Repository navigation
Conversation
Fix the exit status of side-by-side diff when files differ. Previously, side-by-side diff always returned an empty result, causing to incorrectly treat different files as identical. Introduce to track whether the input files differ while preserving the existing public API. Add regression tests to verify that: - Different files return exit code 1. - Identical files return exit code 0.
Allow dead_code on the side_diff module in the binary to silence the unused diff warning. Keep the library's public API free of unnecessary lint allowances.
| mod macros; | ||
| mod normal_diff; | ||
| mod params; | ||
| #[allow(dead_code)] |
There was a problem hiding this comment.
please don't add #[allow(dead_code)]
make side_diff::diff return the bool and drop the wrapper, a Vec that is always empty isn't an API worth keeping
| params: &Params, | ||
| ) -> Vec<u8> { | ||
| // ^ The left file ^ The right file | ||
| diff_with_status(from_file, to_file, output, params); |
There was a problem hiding this comment.
do we need diff_with_status? diff could return bool directly
| let (result, different): (Vec<u8>, bool) = match params.format { | ||
| Format::Normal => { | ||
| let result = normal_diff::diff(&from_content, &to_content, params); | ||
| let different = !result.is_empty(); |
There was a problem hiding this comment.
almost the same code 4 times
could you keep the match returning result and compute different once after it?
| */ | ||
| for result in diff::slice(&left_lines, &right_lines) { | ||
| let results = diff::slice(&left_lines, &right_lines); | ||
| let different = results |
There was a problem hiding this comment.
could be set in the loop below instead of walking the results twice, no?
| ) -> bool { | ||
| // ^ The left file ^ The right file | ||
| let mut left_lines: Vec<&[u8]> = from_file.split_inclusive(|&c| c == b'\n').collect(); | ||
| let mut right_lines: Vec<&[u8]> = to_file.split_inclusive(|&c| c == b'\n').collect(); |
There was a problem hiding this comment.
please keep the blank lines, unrelated change
|
|
||
| // Regression test: identical files must return exit code 0 in side-by-side mode. | ||
| #[test] | ||
| fn sdiff_identical_files_exit_success() { |
There was a problem hiding this comment.
please also add a test for -q -y with different files, and for the header with -r -y
Summary
side_diff::diffAPI.Testing
cargo testcargo clippy -- -D warnings