Skip to content

Commit 614d93d

Browse files
committed
Report number of non-matching diffs
In addition to the first non-matching diff, the test now also reports the fixture it came from and the number of total as well as non-matching diffs. This makes the slider test more suitable as a benchmark for comparing different slider heuristics.
1 parent f471ac5 commit 614d93d

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

gix-diff/tests/diff/blob/slider.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use gix_diff::blob::intern::TokenSource;
22
use gix_diff::blob::unified_diff::ContextSize;
33
use gix_diff::blob::{Algorithm, UnifiedDiff};
44
use gix_testtools::bstr::{BString, ByteVec};
5+
use pretty_assertions::StrComparison;
56

67
#[test]
78
fn baseline() -> gix_testtools::Result {
@@ -10,15 +11,15 @@ fn baseline() -> gix_testtools::Result {
1011

1112
let dir = std::fs::read_dir(&worktree_path)?;
1213

13-
let mut count = 0;
14+
let mut diffs = Vec::new();
15+
1416
for entry in dir {
1517
let entry = entry?;
1618
let file_name = entry.file_name().into_string().expect("to be string");
1719

1820
if !file_name.ends_with(".baseline") {
1921
continue;
2022
}
21-
count += 1;
2223

2324
let parts: Vec<_> = file_name.split('.').collect();
2425
let [name, algorithm, ..] = parts[..] else {
@@ -53,7 +54,7 @@ fn baseline() -> gix_testtools::Result {
5354
),
5455
)?;
5556

56-
let baseline_path = worktree_path.join(file_name);
57+
let baseline_path = worktree_path.join(&file_name);
5758
let baseline = std::fs::read(baseline_path)?;
5859
let baseline = baseline::Baseline::new(&baseline);
5960

@@ -80,13 +81,39 @@ fn baseline() -> gix_testtools::Result {
8081
})
8182
.to_string();
8283

83-
pretty_assertions::assert_eq!(actual, baseline);
84+
let actual_matches_baseline = actual == baseline;
85+
diffs.push((actual, baseline, actual_matches_baseline, file_name));
8486
}
8587

86-
if count == 0 {
88+
if diffs.is_empty() {
8789
eprintln!("Slider baseline isn't setup - look at ./gix-diff/tests/README.md for instructions");
8890
}
8991

92+
let total_diffs = diffs.len();
93+
let matching_diffs = diffs
94+
.iter()
95+
.filter(|(_, _, actual_matches_baseline, _)| *actual_matches_baseline)
96+
.count();
97+
98+
assert!(
99+
matching_diffs == total_diffs,
100+
"assertion failed: total diffs {} == matching diffs {}\n\n{}",
101+
total_diffs,
102+
matching_diffs,
103+
{
104+
let first_non_matching_diff = diffs
105+
.iter()
106+
.find(|(_, _, actual_matches_baseline, _)| !actual_matches_baseline)
107+
.expect("at least one non-matching diff to be there");
108+
109+
format!(
110+
"affected baseline: `{}`\n\n{}",
111+
first_non_matching_diff.3,
112+
StrComparison::new(&first_non_matching_diff.0, &first_non_matching_diff.1)
113+
)
114+
}
115+
);
116+
90117
Ok(())
91118
}
92119

0 commit comments

Comments
 (0)