Skip to content

Commit

Permalink
tests: Print comparison when approximation assertion fails
Browse files Browse the repository at this point in the history
This makes it easier to compare values and see which one failed.
  • Loading branch information
kjarosh authored and Dinnerbone committed Oct 21, 2024
1 parent 64a5c01 commit c34d8e5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/framework/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::image_trigger::ImageTrigger;
use crate::options::{ImageComparison, TestOptions};
use crate::test::Test;
use crate::util::{read_bytes, write_image};
use anyhow::{anyhow, Result};
use anyhow::{anyhow, Error, Result};
use image::ImageFormat;
use pretty_assertions::Comparison;
use ruffle_core::backend::navigator::NullExecutor;
Expand Down Expand Up @@ -403,6 +403,14 @@ impl TestRunner {
let expected_output = self.output_path.read_to_string()?.replace("\r\n", "\n");

if let Some(approximations) = &self.options.approximations {
let add_comparison_to_err = |err: Error| -> Error {
let left_pretty = PrettyString(actual_output);
let right_pretty = PrettyString(&expected_output);
let comparison = Comparison::new(&left_pretty, &right_pretty);

anyhow!("{}\n\n{}\n", err, comparison)
};

if actual_output.lines().count() != expected_output.lines().count() {
return Err(anyhow!(
"# of lines of output didn't match (expected {} from Flash, got {} from Ruffle",
Expand All @@ -420,7 +428,9 @@ impl TestRunner {
continue;
}

approximations.compare(actual, expected)?;
approximations
.compare(actual, expected)
.map_err(add_comparison_to_err)?;
} else {
let mut found = false;

Expand Down Expand Up @@ -455,7 +465,9 @@ impl TestRunner {
.as_str()
.parse::<f64>()
.expect("Failed to parse 'expected' capture group as float");
approximations.compare(actual_num, expected_num)?;
approximations
.compare(actual_num, expected_num)
.map_err(add_comparison_to_err)?;
}
let modified_actual = pattern.replace_all(actual, "");
let modified_expected = pattern.replace_all(expected, "");
Expand Down

0 comments on commit c34d8e5

Please sign in to comment.