Merge pull request #2520 from rtfeldman/2495-check-format-tests

Add tests for `roc format --check {{file}}`
This commit is contained in:
Folkert de Vries 2022-02-19 01:37:12 +01:00 committed by GitHub
commit da568965f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -69,6 +69,17 @@ mod cli_run {
assert_multiline_str_eq!(err, expected.into());
}
fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) {
let flags = &["--check"];
let out = run_roc(&[&["format", &file.to_str().unwrap()], &flags[..]].concat());
if expects_success_exit_code {
assert!(out.status.success());
} else {
assert!(!out.status.success());
}
}
fn check_output_with_stdin(
file: &Path,
stdin: &[&str],
@ -863,6 +874,16 @@ mod cli_run {
),
);
}
#[test]
fn format_check_good() {
check_format_check_as_expected(&fixture_file("format", "Formatted.roc"), true);
}
#[test]
fn format_check_reformatting_needed() {
check_format_check_as_expected(&fixture_file("format", "NotFormatted.roc"), false);
}
}
#[allow(dead_code)]

View File

@ -0,0 +1,6 @@
app "formatted"
packages { pf: "platform" } imports []
provides [ main ] to pf
main : Str
main = Dep1.value1 {}

View File

@ -0,0 +1,6 @@
app "formatted"
packages { pf: "platform" }
provides [ main ] to pf
main : Str
main = Dep1.value1 {}