diff --git a/src/cmp.rs b/src/cmp.rs index 3ff716f..dc212d2 100644 --- a/src/cmp.rs +++ b/src/cmp.rs @@ -703,9 +703,8 @@ fn report_difference( at_line ); if params.print_bytes { - let char_width = if to_byte >= 0x7F { 2 } else { 1 }; print!( - " is {:>3o} {:char_width$} {:>3o} {:char_width$}", + " is {:>3o} {} {:>3o} {}", from_byte, format_visible_byte(from_byte), to_byte, diff --git a/tests/by-util/test_cmp.rs b/tests/by-util/test_cmp.rs index 0053a46..a36d16a 100644 --- a/tests/by-util/test_cmp.rs +++ b/tests/by-util/test_cmp.rs @@ -452,6 +452,34 @@ fn cmp_skip() -> Result<(), Box> { Ok(()) } +#[test] +fn cmp_print_bytes_high_byte() -> Result<(), Box> { + let tmp_dir = tempdir()?; + + let a_path = tmp_dir.path().join("a"); + let mut a = File::create(&a_path).unwrap(); + a.write_all(b"a").unwrap(); + + let b_path = tmp_dir.path().join("b"); + let mut b = File::create(&b_path).unwrap(); + b.write_all(&[0xC3]).unwrap(); + + // GNU cmp does not pad the printed bytes, whatever the second byte is. + let mut cmd = cargo_bin_cmd!("diffutils"); + cmd.arg("cmp"); + cmd.arg("-b"); + cmd.arg(&a_path).arg(&b_path); + cmd.assert() + .code(predicate::eq(1)) + .failure() + .stderr(predicate::str::is_empty()) + .stdout(predicate::str::ends_with( + " differ: byte 1, line 1 is 141 a 303 M-C\n", + )); + + Ok(()) +} + #[test] fn cmp_binary() -> Result<(), Box> { let tmp_dir = tempdir()?;