From 98195f6bbbfca58a2c0720c35c44d24ed9a4f421 Mon Sep 17 00:00:00 2001 From: Logic769 Date: Fri, 30 Oct 2026 03:53:16 +0800 Subject: [PATCH 1/3] sort: use the shared incompatible-options error for -o with --debug --- src/uu/sort/src/sort.rs | 7 +++++++ tests/by-util/test_sort.rs | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index eb3a0959321..343665f1060 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -2145,6 +2145,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } settings.debug = matches.get_flag(options::DEBUG); + if let Some(path) = matches.get_one::(options::RANDOM_SOURCE) { settings.random_source = Some(PathBuf::from(path)); } @@ -2343,6 +2344,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(incompatible_options_error(opts)); } + // `-o` writes to a file, which is incompatible with the diagnostic output of + // `--debug`. + if matches.contains_id(options::OUTPUT) && matches.get_flag(options::DEBUG) { + return Err(incompatible_options_error("o --debug")); + } + settings.ignore_leading_blanks = matches.get_flag(options::IGNORE_LEADING_BLANKS); settings.reverse = matches.get_flag(options::REVERSE); diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 5b6b7d6c2e7..13d824444c3 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -4243,3 +4243,13 @@ fn test_numeric_looking_file_names_are_kept_verbatim( at.touch("empty"); ucmd.args(args).fails_with_code(2).stderr_is(expected); } + +#[test] +fn test_debug_incompatible_with_output() { + let (at, mut ucmd) = at_and_ucmd!(); + ucmd.args(&["-o", "out", "--debug"]) + .pipe_in("b\na\n") + .fails_with_code(2) + .stderr_only("sort: options '-o --debug' are incompatible\n"); + assert!(!at.file_exists("out")); +} From 9023b24dd175a5dc6b000338c60d87b3c0d70f66 Mon Sep 17 00:00:00 2001 From: Logic769 Date: Mon, 2 Nov 2026 14:18:50 +0800 Subject: [PATCH 2/3] sort: drop the redundant comment on the -o/--debug check --- src/uu/sort/src/sort.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 343665f1060..19febdf9293 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -2344,8 +2344,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(incompatible_options_error(opts)); } - // `-o` writes to a file, which is incompatible with the diagnostic output of - // `--debug`. if matches.contains_id(options::OUTPUT) && matches.get_flag(options::DEBUG) { return Err(incompatible_options_error("o --debug")); } From d9dddef189a2cc11ec51735c5979ba68b87426d8 Mon Sep 17 00:00:00 2001 From: Logic769 Date: Tue, 3 Nov 2026 08:15:07 +0800 Subject: [PATCH 3/3] sort: use settings.debug in the -o/--debug conflict check --- src/uu/sort/src/sort.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 19febdf9293..16549fbbab8 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -2145,7 +2145,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } settings.debug = matches.get_flag(options::DEBUG); - if let Some(path) = matches.get_one::(options::RANDOM_SOURCE) { settings.random_source = Some(PathBuf::from(path)); } @@ -2344,7 +2343,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(incompatible_options_error(opts)); } - if matches.contains_id(options::OUTPUT) && matches.get_flag(options::DEBUG) { + if matches.contains_id(options::OUTPUT) && settings.debug { return Err(incompatible_options_error("o --debug")); }