From 0425b96e4d7773aa02bb4bb449ae08c0ae5a8611 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 3 May 2026 21:37:49 +0200 Subject: [PATCH 1/2] factor: emit GNU's 'X is not a valid positive integer' wording GNU's factor.c routes both stdin and command-line input through the same print_factors() and reports invalid input as factor: 'X' is not a valid positive integer Match that wording exactly so the new GNU 9.11 'nul4' test passes and the 'cont' test no longer needs the warning/invalid-digit hunk in tests_factor_factor.pl.patch. --- src/uu/factor/locales/en-US.ftl | 2 +- src/uu/factor/locales/fr-FR.ftl | 2 +- src/uu/factor/src/factor.rs | 17 ++++++----------- tests/by-util/test_factor.rs | 19 +++++++++++++++---- util/gnu-patches/tests_factor_factor.pl.patch | 7 +------ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/uu/factor/locales/en-US.ftl b/src/uu/factor/locales/en-US.ftl index 8e4eebeab04..4fed2ad4a1f 100644 --- a/src/uu/factor/locales/en-US.ftl +++ b/src/uu/factor/locales/en-US.ftl @@ -10,4 +10,4 @@ factor-help-help = Print help information. factor-error-factorization-incomplete = Factorization incomplete. Remainders exists. factor-error-write-error = write error factor-error-reading-input = error reading input: { $error } -factor-error-invalid-int = invalid digit found in string +factor-error-invalid-int = is not a valid positive integer diff --git a/src/uu/factor/locales/fr-FR.ftl b/src/uu/factor/locales/fr-FR.ftl index 81d07a9b715..e31e6cd60ee 100644 --- a/src/uu/factor/locales/fr-FR.ftl +++ b/src/uu/factor/locales/fr-FR.ftl @@ -10,4 +10,4 @@ factor-help-help = Afficher les informations d'aide. factor-error-factorization-incomplete = Factorisation incomplète. Des restes existent. factor-error-write-error = erreur d'écriture factor-error-reading-input = erreur de lecture de l'entrée : { $error } -factor-error-invalid-int = chiffre invalide trouvé dans la chaîne +factor-error-invalid-int = n'est pas un entier positif valide diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index 4d3d82c52b9..6f418387366 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -74,36 +74,31 @@ fn write_factors_str( } fn parse_num(slice: &[u8]) -> UResult { - let err_invalid = |s: &str, force_quoting| { - let num = if force_quoting { - s.quote() // Force quoting if there are invalid characters. - } else { - s.maybe_quote() - }; + let err_invalid = |s: &str| { USimpleError::new( 1, - format!("warning: {num}: {}", translate!("factor-error-invalid-int")), + format!("{} {}", s.quote(), translate!("factor-error-invalid-int")), ) }; - let num = str::from_utf8(slice).map_err(|_| err_invalid(&NumError(slice).to_string(), true))?; + let num = str::from_utf8(slice).map_err(|_| err_invalid(&NumError(slice).to_string()))?; match num.parse::() { Ok(x) => return Ok(Number::U64(x)), // If overflown, attempt a greater width Err(e) if matches!(e.kind(), IntErrorKind::PosOverflow) => {} - Err(_) => return Err(err_invalid(num, false)), + Err(_) => return Err(err_invalid(num)), } match num.parse::() { Ok(x) => return Ok(Number::U128(x)), // If overflown, attempt a greater width Err(e) if matches!(e.kind(), IntErrorKind::PosOverflow) => {} - Err(_) => return Err(err_invalid(num, false)), + Err(_) => return Err(err_invalid(num)), } num.parse::() .map(Number::BigUint) - .map_err(|_| err_invalid(num, false)) + .map_err(|_| err_invalid(num)) } /// This is a newtype wrapper over a potentially malformed UTF-8 diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index bee47b5efdc..7ee4529f16d 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -1678,10 +1678,10 @@ fn succeeds_with_numbers_larger_than_u256() { fn handles_non_unicode_data() { let input = b"\0 \xFF\0\xFF\xAA\0\xAA\x44 a\n6 9\x003\xC024\t2\t\t4\x000+4\xFF \xF7\xC1"; let expected_out = "6: 2 3\n9: 3 3\n2: 2\n4: 2 2\n"; - let expected_err = r"factor: warning: '': invalid digit found in string -factor: warning: '\377': invalid digit found in string -factor: warning: 'a': invalid digit found in string -factor: warning: '\367\301': invalid digit found in string + let expected_err = r"factor: '' is not a valid positive integer +factor: '\377' is not a valid positive integer +factor: 'a' is not a valid positive integer +factor: '\367\301' is not a valid positive integer "; new_ucmd!() .pipe_in(input) @@ -1689,3 +1689,14 @@ factor: warning: '\367\301': invalid digit found in string .stdout_is(expected_out) .stderr_is(expected_err); } + +// GNU's `tests/factor/factor.pl` `cont` test passes `factor a 4` and expects +// `factor: 'a' is not a valid positive integer` while still factoring 4. +#[test] +fn invalid_cmdline_arg_continues() { + new_ucmd!() + .args(&["a", "4"]) + .fails_with_code(1) + .stdout_is("4: 2 2\n") + .stderr_is("factor: 'a' is not a valid positive integer\n"); +} diff --git a/util/gnu-patches/tests_factor_factor.pl.patch b/util/gnu-patches/tests_factor_factor.pl.patch index 892d526964e..b105e25b915 100644 --- a/util/gnu-patches/tests_factor_factor.pl.patch +++ b/util/gnu-patches/tests_factor_factor.pl.patch @@ -2,7 +2,7 @@ Index: gnu/tests/factor/factor.pl =================================================================== --- gnu.orig/tests/factor/factor.pl +++ gnu/tests/factor/factor.pl -@@ -61,12 +61,14 @@ my @Tests = +@@ -61,8 +61,10 @@ my @Tests = # Map newer glibc diagnostic to expected. # Also map OpenBSD 5.1's "unknown option" to expected "invalid option". {ERR_SUBST => q!s/'1'/1/;s/unknown/invalid/!}, @@ -15,8 +15,3 @@ Index: gnu/tests/factor/factor.pl {EXIT => 1}], ['cont', 'a 4', {OUT => "4: 2 2\n"}, -- {ERR => "$prog: 'a' is not a valid positive integer\n"}, -+ {ERR => "$prog: warning: a: invalid digit found in string\n"}, - {EXIT => 1}], - ['bug-2012-a', '465658903', {OUT => '15259 30517'}], - ['bug-2012-b', '2242724851', {OUT => '33487 66973'}], From a66d197cbd11f9d998b30c24c9be900fb2978a6e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 3 May 2026 21:44:01 +0200 Subject: [PATCH 2/2] Add 'cmdline' to spell-checker ignore list --- tests/by-util/test_factor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index 7ee4529f16d..8833c9d96d9 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (methods) hexdigest funcs nprimes +// spell-checker:ignore (methods) hexdigest funcs nprimes cmdline #![allow( clippy::similar_names, clippy::cast_possible_truncation,