diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index eb3a0959321..16549fbbab8 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -2343,6 +2343,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(incompatible_options_error(opts)); } + if matches.contains_id(options::OUTPUT) && settings.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")); +}