Skip to content

Commit

Permalink
Use prettier string comparison in tests (#2435)
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak authored Oct 30, 2024
1 parent b063940 commit a71f2a5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use {super::*, pretty_assertions::assert_eq};
use {
super::*,
pretty_assertions::{assert_eq, StrComparison},
};

macro_rules! test {
{
Expand Down Expand Up @@ -205,6 +208,14 @@ impl Test {
equal
}

fn compare_string(name: &str, have: &str, want: &str) -> bool {
let equal = have == want;
if !equal {
eprintln!("Bad {name}: {}", StrComparison::new(&have, &want));
}
equal
}

if let Some(justfile) = &self.justfile {
let justfile = unindent(justfile);
fs::write(self.justfile_path(), justfile).unwrap();
Expand Down Expand Up @@ -266,8 +277,8 @@ impl Test {
}

if !compare("status", output.status.code(), Some(self.status))
| (self.stdout_regex.is_none() && !compare("stdout", output_stdout, &stdout))
| (self.stderr_regex.is_none() && !compare("stderr", output_stderr, &stderr))
| (self.stdout_regex.is_none() && !compare_string("stdout", output_stdout, &stdout))
| (self.stderr_regex.is_none() && !compare_string("stderr", output_stderr, &stderr))
{
panic!("Output mismatch.");
}
Expand Down

0 comments on commit a71f2a5

Please sign in to comment.