Skip to content

Commit beadf39

Browse files
committed
tests: require passing checks to not have a output.ruffle.txt/png file
1 parent 08ca133 commit beadf39

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

tests/framework/src/runner/image_test.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,20 @@ pub fn capture_and_compare_image(
4444
}
4545
};
4646

47+
let ruffle_expected_path = base_path.join(format!("{name}.ruffle.png"))?;
48+
4749
let diff = test(&image_comparison, name, &actual_image, expected_image)?;
4850
let (failure, failure_name) = match (diff, image_comparison.known_failure) {
49-
(None, false) => return Ok(()),
51+
(None, false) => {
52+
return if ruffle_expected_path.exists()? {
53+
Err(anyhow!(
54+
"Unexpected `{}` file for passing check, please remove it!",
55+
ruffle_expected_path.as_str(),
56+
))
57+
} else {
58+
Ok(())
59+
};
60+
}
5061
(None, true) => {
5162
return Err(anyhow!(
5263
"Image '{name}': Check was known to be failing, but now passes successfully. \
@@ -56,13 +67,12 @@ pub fn capture_and_compare_image(
5667
(Some(diff), false) => (diff, Cow::Borrowed(name)),
5768
(Some(_), true) => {
5869
let ruffle_name = format!("{name}.ruffle");
59-
let path = base_path.join(format!("{ruffle_name}.png"))?;
60-
let image = if path.exists()? {
61-
image::load_from_memory(&read_bytes(&path)?)
70+
let image = if ruffle_expected_path.exists()? {
71+
image::load_from_memory(&read_bytes(&ruffle_expected_path)?)
6272
.context("Failed to open Ruffle-expected image")?
6373
.into_rgba8()
6474
} else {
65-
write_image(&path, &actual_image)?;
75+
write_image(&ruffle_expected_path, &actual_image)?;
6676
return Err(anyhow!(
6777
"Image '{ruffle_name}': No image to compare to! Saved actual image as Ruffle-expected."
6878
));

tests/framework/src/runner/trace.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub fn compare_trace_output(
1313
) -> anyhow::Result<()> {
1414
let expected_trace = expected_path.read_to_string()?.replace("\r\n", "\n");
1515

16+
let ruffle_expected_path = path_with_suffix(expected_path, "ruffle")?;
17+
1618
// Null bytes are invisible, and interfere with constructing
1719
// the expected output.txt file. Any tests dealing with null
1820
// bytes should explicitly test for them in ActionScript.
@@ -21,7 +23,16 @@ pub fn compare_trace_output(
2123
let result = test("flash_expected", approx, &expected_trace, &actual_trace);
2224

2325
match known_failure {
24-
KnownFailure::None | KnownFailure::Panic { .. } => result,
26+
KnownFailure::None | KnownFailure::Panic { .. } => {
27+
if result.is_ok() && ruffle_expected_path.exists()? {
28+
Err(anyhow!(
29+
"Unexpected `{}` file for passing check, please remove it!",
30+
ruffle_expected_path.as_str(),
31+
))
32+
} else {
33+
result
34+
}
35+
}
2536
KnownFailure::TraceOutput {
2637
ruffle_check: false,
2738
} => {
@@ -35,20 +46,20 @@ pub fn compare_trace_output(
3546
}
3647
}
3748
KnownFailure::TraceOutput { ruffle_check: true } => {
38-
let path = path_with_suffix(expected_path, "ruffle")?;
39-
4049
if result.is_ok() {
4150
return Err(anyhow!(
4251
"Trace output check was known to be failing, but now passes successfully. \
4352
Please update the test, and remove `known_failure = true` and `{}`!",
44-
path.as_str(),
53+
ruffle_expected_path.as_str(),
4554
));
4655
}
4756

48-
let expected_trace = if path.exists()? {
49-
path.read_to_string()?.replace("\r\n", "\n")
57+
let expected_trace = if ruffle_expected_path.exists()? {
58+
ruffle_expected_path.read_to_string()?.replace("\r\n", "\n")
5059
} else {
51-
path.create_file()?.write_all(actual_trace.as_bytes())?;
60+
ruffle_expected_path
61+
.create_file()?
62+
.write_all(actual_trace.as_bytes())?;
5263
return Err(anyhow!(
5364
"No trace to compare to! Saved actual trace as Ruffle-expected."
5465
));

0 commit comments

Comments
 (0)