Skip to content

Commit

Permalink
Improve blessing and add hint about INFERNO_BLESS_TESTS=1
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Jul 18, 2022
1 parent f5c3eb3 commit 012d1a2
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn test_flamegraph_multiple_files(
}
// and then compare
result.set_position(0);
if std::env::var("FLAMEGRAPH_BLESS").is_ok() {
if std::env::var("INFERNO_BLESS_TESTS").is_ok() {
fs::write(expected_result_file, result.get_ref()).unwrap();
} else {
compare_results(result, expected, expected_result_file);
Expand All @@ -76,30 +76,33 @@ where
R: BufRead,
E: BufRead,
{
const BLESS_MSG: &str =
"If you want to bless the output, set `INFERNO_BLESS_TESTS=1` before the `cargo test`";
let mut buf = String::new();
let mut line_num = 1;
for line in result.lines() {
if expected.read_line(&mut buf).unwrap() == 0 {
panic!(
"\noutput has more lines than expected result file: {}",
expected_file
"\noutput has more lines than expected result file: {}\n\n{}",
expected_file, BLESS_MSG
);
}
assert_eq!(
line.unwrap(),
buf.trim_end(),
"\n{}:{}",
"\n{}:{}\n\n{}",
expected_file,
line_num
line_num,
BLESS_MSG
);
buf.clear();
line_num += 1;
}

if expected.read_line(&mut buf).unwrap() > 0 {
panic!(
"\n{} has more lines than output, beginning at line: {}",
expected_file, line_num
"\n{} has more lines than output, beginning at line: {}\n\n{}",
expected_file, line_num, BLESS_MSG
)
}
}
Expand Down

0 comments on commit 012d1a2

Please sign in to comment.