Skip to content

fix: return correct exit status for side-by-side diff - #403

Open
dex0o0 wants to merge 12 commits into
uutils:mainfrom
dex0o0:fix-side-by-side-exit-status
Open

dex0o0 wants to merge 12 commits into
uutils:mainfrom
dex0o0:fix-side-by-side-exit-status

Conversation

@dex0o0

@dex0o0 dex0o0 commented Nov 17, 2026

Copy link
Copy Markdown

Summary

  • Fix the exit status returned by side-by-side diff when comparing identical or different files.
  • Preserve the existing public side_diff::diff API.
  • Add a regression test ensuring identical files return exit code 0.
  • Restore the side-by-side diff disclaimer and address dead-code warnings.

Testing

  • cargo test
  • cargo clippy -- -D warnings

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.
Comment thread src/main.rs Outdated
mod macros;
mod normal_diff;
mod params;
#[allow(dead_code)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/side_diff.rs Outdated
params: &Params,
) -> Vec<u8> {
// ^ The left file ^ The right file
diff_with_status(from_file, to_file, output, params);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need diff_with_status? diff could return bool directly

Comment thread src/diff.rs Outdated
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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost the same code 4 times
could you keep the match returning result and compute different once after it?

Comment thread src/side_diff.rs Outdated
*/
for result in diff::slice(&left_lines, &right_lines) {
let results = diff::slice(&left_lines, &right_lines);
let different = results

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be set in the loop below instead of walking the results twice, no?

Comment thread src/side_diff.rs
) -> 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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a test for -q -y with different files, and for the header with -r -y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants