Skip to content

Commit b8a8783

Browse files
committed
Add a context message to tests to know if initial formatting or idempotence failed
1 parent 5c91d28 commit b8a8783

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

tests/integration_tests.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ fn make_whitespace_visible(s: &str) -> String {
1313
.replace('\n', "↲\n")
1414
}
1515

16-
fn assert_formatted_eq(result: &str, expected: &str, file_path: &Path) {
16+
fn assert_formatted_eq(
17+
result: &str,
18+
expected: &str,
19+
file_path: &Path,
20+
error_context_message: &str,
21+
) {
1722
if result != expected {
18-
eprintln!(
19-
"\nFormatted output doesn't match expected for {}",
20-
file_path.display()
21-
);
22-
eprintln!("Diff between expected(-) and formatted output(+):");
23+
eprintln!("\n{} - {}", error_context_message, file_path.display());
24+
eprintln!("Diff between expected(-) and actual output(+):");
2325
let diff = TextDiff::from_lines(expected, result);
2426
for change in diff.iter_all_changes() {
2527
let text = make_whitespace_visible(&change.to_string());
@@ -34,7 +36,7 @@ fn assert_formatted_eq(result: &str, expected: &str, file_path: &Path) {
3436
eprintln!("{:?}", expected);
3537
eprintln!("\nGOT (raw):");
3638
eprintln!("{:?}", result);
37-
panic!("Assertion failed");
39+
panic!("Assertion failed: {}", error_context_message);
3840
}
3941
}
4042

@@ -73,12 +75,21 @@ fn test_file_with_config(file_path: &Path, config: &FormatterConfig, check_idemp
7375
let result = format_gdscript_with_config(&input_content, config)
7476
.expect(&format!("Failed to format {}", input_path.display()));
7577

76-
assert_formatted_eq(&result, &expected_content, &input_path);
78+
assert_formatted_eq(
79+
&result,
80+
&expected_content,
81+
&input_path,
82+
"First formatting output doesn't match expected",
83+
);
7784

7885
if check_idempotence {
7986
let second_result = format_gdscript_with_config(&result, config)
8087
.expect(&format!("Failed to format {}", input_path.display()));
81-
eprintln!("Checking idempotence: ");
82-
assert_formatted_eq(&second_result, &result, &input_path);
88+
assert_formatted_eq(
89+
&second_result,
90+
&result,
91+
&input_path,
92+
"Idempotence check failed, formatting a second time gave different results",
93+
);
8394
}
8495
}

0 commit comments

Comments
 (0)