From e75d4f8a100af4cf2a8c09ed29c56f345ce454a7 Mon Sep 17 00:00:00 2001 From: Logic769 Date: Fri, 30 Oct 2026 03:36:25 +0800 Subject: [PATCH 1/3] nl: accept negative values for -v and -i --- src/uu/nl/src/nl.rs | 2 ++ tests/by-util/test_nl.rs | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 3f58e77cdff..ec69895fc23 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -353,6 +353,7 @@ pub fn uu_app() -> Command { .long(options::LINE_INCREMENT) .help(translate!("nl-help-line-increment")) .value_name("NUMBER") + .allow_negative_numbers(true) .value_parser(clap::value_parser!(i64)), ) .arg( @@ -392,6 +393,7 @@ pub fn uu_app() -> Command { .long(options::STARTING_LINE_NUMBER) .help(translate!("nl-help-starting-line-number")) .value_name("NUMBER") + .allow_negative_numbers(true) .value_parser(clap::value_parser!(i64)), ) .arg( diff --git a/tests/by-util/test_nl.rs b/tests/by-util/test_nl.rs index d63a1790c0a..cee8cdb27a1 100644 --- a/tests/by-util/test_nl.rs +++ b/tests/by-util/test_nl.rs @@ -1039,3 +1039,12 @@ fn test_other_numeric_options_still_reject_values_above_the_limit() { .stderr_contains("invalid value '18446744073709551616'"); } } + +#[test] +fn test_negative_starting_line_and_increment() { + new_ucmd!() + .args(&["-v", "-1"]) + .pipe_in("a\nb\n") + .succeeds() + .stdout_is(" -1\ta\n 0\tb\n"); +} From 906c09873abedba8a090cf773163a3cd357ddd5c Mon Sep 17 00:00:00 2001 From: Logic769 Date: Fri, 30 Oct 2026 21:10:30 +0800 Subject: [PATCH 2/3] nl: cover a negative increment given as a separate argument --- tests/by-util/test_nl.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/by-util/test_nl.rs b/tests/by-util/test_nl.rs index cee8cdb27a1..17557c4bf38 100644 --- a/tests/by-util/test_nl.rs +++ b/tests/by-util/test_nl.rs @@ -1048,3 +1048,14 @@ fn test_negative_starting_line_and_increment() { .succeeds() .stdout_is(" -1\ta\n 0\tb\n"); } + +#[test] +fn test_negative_line_increment_as_a_separate_argument() { + for arg in ["-i", "--line-increment"] { + new_ucmd!() + .args(&[arg, "-1"]) + .pipe_in("a\nb\nc\n") + .succeeds() + .stdout_is(" 1\ta\n 0\tb\n -1\tc\n"); + } +} From 4c480a981434e93aa8d53a4e60ac045fbd7994e0 Mon Sep 17 00:00:00 2001 From: Logic769 Date: Mon, 2 Nov 2026 13:29:20 +0800 Subject: [PATCH 3/3] test(nl): cover negative starting line as a separate argument --- tests/by-util/test_nl.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/by-util/test_nl.rs b/tests/by-util/test_nl.rs index 17557c4bf38..fd27723ba00 100644 --- a/tests/by-util/test_nl.rs +++ b/tests/by-util/test_nl.rs @@ -1041,12 +1041,14 @@ fn test_other_numeric_options_still_reject_values_above_the_limit() { } #[test] -fn test_negative_starting_line_and_increment() { - new_ucmd!() - .args(&["-v", "-1"]) - .pipe_in("a\nb\n") - .succeeds() - .stdout_is(" -1\ta\n 0\tb\n"); +fn test_negative_starting_line_as_a_separate_argument() { + for arg in ["-v", "--starting-line-number"] { + new_ucmd!() + .args(&[arg, "-1"]) + .pipe_in("a\nb\n") + .succeeds() + .stdout_is(" -1\ta\n 0\tb\n"); + } } #[test]