fix(tools): h5rs diff names its options as h5diff does

-c meant "list at most N differences" in h5rs, but in h5diff -c is
--compare (a flag) and the count is -n/--count=N, so a script moved over
from h5diff behaved differently: `h5diff -r -c 2 A B` exits 2 (the 2 is
taken as a file name) while h5rs exited 1.

The count is now -n/--count, -c/--compare is accepted (h5rs always lists
objects that are not comparable), and the --count=N, --delta=D,
--relative=R forms are accepted; exit codes equal h5diff's on 7 cases.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
osobh
2026-09-26 01:18:56 -05:00
co-authored by Claude Opus 5.5
parent b5e43bacd7
commit 386bd1d41e
5 changed files with 70 additions and 9 deletions
@@ -380,6 +380,42 @@ fn diff_exit_codes_match_h5diff() {
assert!(s.contains("2 difference(s) found"), "{s}");
}
/// The option names are h5diff's: -c is --compare (a flag), the count is
/// -n/--count, and the --name=value forms are accepted.
#[test]
fn diff_options_are_named_like_h5diff() {
let Some(f) = generate() else { return };
let (b, changed) = (f.p("base.h5"), f.p("changed.h5"));
let cases: Vec<(Vec<&str>, i32)> = vec![
// "2" is then the first file name, which does not exist.
(vec!["-r", "-c", "2", &b, &changed], 2),
(vec!["-c", &b, &changed], 1),
(vec!["--compare", &b, &b], 0),
(vec!["-r", "-n", "1", &b, &changed], 1),
(vec!["-r", "--count=1", &b, &changed], 1),
(vec!["--delta=0.01", &b, &changed], 0),
(vec!["--relative=1e-9", &b, &changed], 1),
];
let have_h5diff = tool_available("h5diff");
for (args, want) in cases {
if have_h5diff {
assert_eq!(code(&run("h5diff", &args)), want, "h5diff {args:?}");
}
let o = h5rs(&[&["diff"], args.as_slice()].concat());
assert_eq!(code(&o), want, "h5rs diff {args:?}: {}", stdout(&o));
}
for count in [vec!["-n", "1"], vec!["--count=1"]] {
let o = h5rs(&[&["diff", "-r"], count.as_slice(), &[&b, &changed, "/d"]].concat());
let s = stdout(&o);
assert!(
s.contains("[ 0 2 ]") && !s.contains("[ 2 3 ]"),
"{count:?}: {s}"
);
assert!(s.contains("2 difference(s) found"), "{s}");
}
assert_eq!(code(&h5rs(&["diff", "--bogus=1", &b, &b])), 2);
}
/// Tolerances on 64-bit integers one apart, far beyond f64's integer
/// precision: compared exactly, as h5diff does.
#[test]