Repository navigation
Open
Labels
Description
GNU diff's -B / --ignore-blank-lines drops hunks whose inserted and deleted lines
are all blank. uutils does not know the option and fails with unrecognized option '-B'
and exit 2. The GNU test no-newline-at-eof exposes it in its last step (Bug#18402,
diff -B a b on two one-line files without a final newline must exit 1).
Reproduction
printf 'a\n\nb\n' > b1; printf 'a\nb\n' > b2
printf 'a' > b5; printf 'b' > b6Rust (incorrect)
$ ./target/release/diffutils diff -B b1 b2
unrecognized option '-B'
# Exit code: 2
$ ./target/release/diffutils diff --ignore-blank-lines b1 b2
unrecognized option '--ignore-blank-lines'
# Exit code: 2
$ ./target/release/diffutils diff -B b5 b6
unrecognized option '-B'
# Exit code: 2GNU (correct)
$ LC_ALL=C diff -B b1 b2
# Exit code: 0
$ LC_ALL=C diff --ignore-blank-lines b1 b2
# Exit code: 0
$ LC_ALL=C diff -B b5 b6
1c1
< a
\ No newline at end of file
---
> b
\ No newline at end of file
# Exit code: 1Test
Add to tests/by-util/test_diff.rs:
#[test]
fn ignore_blank_lines() -> Result<(), Box<dyn std::error::Error>> {
let mut a = NamedTempFile::new()?;
a.write_all(b"a\n\nb\n")?;
let mut b = NamedTempFile::new()?;
b.write_all(b"a\nb\n")?;
for option in ["-B", "--ignore-blank-lines"] {
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("diff").arg(option).arg(a.path()).arg(b.path());
cmd.assert()
.code(predicate::eq(0))
.stdout(predicate::str::is_empty());
}
// Bug#18402: non-blank changes without a final newline are still reported.
let mut c = NamedTempFile::new()?;
c.write_all(b"a")?;
let mut d = NamedTempFile::new()?;
d.write_all(b"b")?;
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("diff").arg("-B").arg(c.path()).arg(d.path());
cmd.assert().code(predicate::eq(1)).stdout(predicate::eq(
"1c1\n< a\n\\ No newline at end of file\n---\n> b\n\\ No newline at end of file\n",
));
Ok(())
}Exposed by the GNU diffutils test suite: no-newline-at-eof.
Activity