Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/uucore/src/lib/mods/clap_localization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//!

use crate::error::{UResult, USimpleError};
use crate::locale::translate;
use crate::locale::{translate, translate_text};

use clap::error::{ContextKind, ErrorKind};
use clap::{ArgMatches, Command, Error};
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'a> ErrorFormatter<'a> {
let _ = write!(
stderr(),
"{}\n\n",
translate!(
translate_text!(
"clap-error-unexpected-argument",
"arg" => self.color_mgr.colorize(&arg_str, Color::Yellow),
"error_word" => self.color_mgr.colorize(&error_word, Color::Red)
Expand All @@ -164,7 +164,7 @@ impl<'a> ErrorFormatter<'a> {
let _ = write!(
stderr(),
"{}\n\n",
translate!(
translate_text!(
"clap-error-similar-argument",
"tip_word" => self.color_mgr.colorize(&tip_word, Color::Green),
"suggestion" => self.color_mgr.colorize(&suggested_arg.to_string(), Color::Green)
Expand Down Expand Up @@ -204,7 +204,7 @@ impl<'a> ErrorFormatter<'a> {
} else {
// Invalid value provided
let error_word = translate!("common-error");
let error_msg = translate!(
let error_msg = translate_text!(
"clap-error-invalid-value",
"error_word" => self.color_mgr.colorize(&error_word, Color::Red),
"value" => self.color_mgr.colorize(&value, Color::Yellow),
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ fn test_invalid_value_returns_2() {
}
}

#[test]
fn test_invalid_numeric_value_is_verbatim() {
new_ucmd!()
.env("LC_ALL", "C")
.arg("--format=007")
.fails()
.stderr_contains("invalid value '007' for '--format");
}

#[test]
fn test_invalid_value_time_style() {
// This is the only flag which does not raise an error if it is invalid but not actually used:
Expand Down
11 changes: 11 additions & 0 deletions tests/by-util/test_uname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
}

#[test]
fn test_unexpected_numeric_operand_is_verbatim() {
for arg in ["007", "1e3", "1.50"] {
new_ucmd!()
.env("LC_ALL", "C")
.arg(arg)
.fails_with_code(1)
.stderr_contains(format!("unexpected argument '{arg}' found"));
}
}

#[test]
fn test_uname() {
new_ucmd!().succeeds();
Expand Down
Loading