diff --git a/Cargo.lock b/Cargo.lock index 88512ab31f..b076a6161b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3375,6 +3375,7 @@ dependencies = [ "roc_parse", "roc_region", "roc_test_utils", + "walkdir", ] [[package]] diff --git a/compiler/fmt/Cargo.toml b/compiler/fmt/Cargo.toml index ea17bf7579..815891ba59 100644 --- a/compiler/fmt/Cargo.toml +++ b/compiler/fmt/Cargo.toml @@ -16,3 +16,4 @@ bumpalo = { version = "3.8.0", features = ["collections"] } pretty_assertions = "1.0.0" indoc = "1.0.3" roc_test_utils = { path = "../../test_utils" } +walkdir = "2.3.2" diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index c55bcc5d79..6b1ebd5086 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -63,7 +63,6 @@ mod test_fmt { } Err(error) => panic!("Unexpected parse failure when parsing this for defs formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n", src, error) } - assert_multiline_str_eq!(expected, buf.as_str()) } Err(error) => panic!("Unexpected parse failure when parsing this for module header formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n", src, error) @@ -71,8 +70,6 @@ mod test_fmt { } fn module_formats_to(input: &str, expected: &str) { - let input = input.trim_end(); - // First check that input formats to the expected version expect_format_module_helper(input, expected); @@ -2941,6 +2938,35 @@ mod test_fmt { )); } + #[test] + /// Test that everything under examples/ is formatted correctly + fn test_fmt_examples() { + let mut count = 0; + let mut root = std::env::current_dir() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .to_owned(); + root.push("examples"); + for entry in walkdir::WalkDir::new(&root) { + let entry = entry.unwrap(); + let path = entry.path(); + if path.extension() == Some(&std::ffi::OsStr::new("roc")) { + count += 1; + let src = std::fs::read_to_string(path).unwrap(); + println!("{}", path.display()); + module_formats_same(&src); + } + } + assert!( + count > 0, + "Expecting to find at least 1 .roc file to format under {}", + root.display() + ); + } + // this is a parse error atm // #[test] // fn multiline_apply() {