mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
tests/util
: Don't trim output in CmdResult::stdout_matches
and stdout_does_not_match
(#4304)
* tests/util: Fix documentation of UCommand::stderr_only and usage_error * tests/util: Remove trimming from CmdResult::stdout_matches and stdout_does_not_match. Fix tests. The tests are fixed to match the trailing newline instead of ignoring it.
This commit is contained in:
parent
ff5000d4d0
commit
f610f33aa7
6 changed files with 15 additions and 15 deletions
|
@ -68,10 +68,10 @@ fn test_date_utc() {
|
||||||
fn test_date_format_y() {
|
fn test_date_format_y() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
||||||
let mut re = Regex::new(r"^\d{4}$").unwrap();
|
let mut re = Regex::new(r"^\d{4}\n$").unwrap();
|
||||||
scene.ucmd().arg("+%Y").succeeds().stdout_matches(&re);
|
scene.ucmd().arg("+%Y").succeeds().stdout_matches(&re);
|
||||||
|
|
||||||
re = Regex::new(r"^\d{2}$").unwrap();
|
re = Regex::new(r"^\d{2}\n$").unwrap();
|
||||||
scene.ucmd().arg("+%y").succeeds().stdout_matches(&re);
|
scene.ucmd().arg("+%y").succeeds().stdout_matches(&re);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ fn test_date_format_m() {
|
||||||
let mut re = Regex::new(r"\S+").unwrap();
|
let mut re = Regex::new(r"\S+").unwrap();
|
||||||
scene.ucmd().arg("+%b").succeeds().stdout_matches(&re);
|
scene.ucmd().arg("+%b").succeeds().stdout_matches(&re);
|
||||||
|
|
||||||
re = Regex::new(r"^\d{2}$").unwrap();
|
re = Regex::new(r"^\d{2}\n$").unwrap();
|
||||||
scene.ucmd().arg("+%m").succeeds().stdout_matches(&re);
|
scene.ucmd().arg("+%m").succeeds().stdout_matches(&re);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ fn test_date_format_day() {
|
||||||
re = Regex::new(r"\S+").unwrap();
|
re = Regex::new(r"\S+").unwrap();
|
||||||
scene.ucmd().arg("+%A").succeeds().stdout_matches(&re);
|
scene.ucmd().arg("+%A").succeeds().stdout_matches(&re);
|
||||||
|
|
||||||
re = Regex::new(r"^\d{1}$").unwrap();
|
re = Regex::new(r"^\d{1}\n$").unwrap();
|
||||||
scene.ucmd().arg("+%u").succeeds().stdout_matches(&re);
|
scene.ucmd().arg("+%u").succeeds().stdout_matches(&re);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ fn test_date_issue_3780() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_date_nano_seconds() {
|
fn test_date_nano_seconds() {
|
||||||
// %N nanoseconds (000000000..999999999)
|
// %N nanoseconds (000000000..999999999)
|
||||||
let re = Regex::new(r"^\d{1,9}$").unwrap();
|
let re = Regex::new(r"^\d{1,9}\n$").unwrap();
|
||||||
new_ucmd!().arg("+%N").succeeds().stdout_matches(&re);
|
new_ucmd!().arg("+%N").succeeds().stdout_matches(&re);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,5 +49,5 @@ fn test_long_output() {
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg("-l")
|
.arg("-l")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_matches(&Regex::new("[rwx-]{10}.*some-file1$").unwrap());
|
.stdout_matches(&Regex::new("[rwx-]{10}.*some-file1\n$").unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -950,7 +950,7 @@ fn test_ls_commas_trailing() {
|
||||||
.arg("./test-commas-trailing-1")
|
.arg("./test-commas-trailing-1")
|
||||||
.arg("./test-commas-trailing-2")
|
.arg("./test-commas-trailing-2")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_matches(&Regex::new(r"\S$").unwrap()); // matches if there is no whitespace at the end of stdout.
|
.stdout_matches(&Regex::new(r"\S\n$").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -300,7 +300,7 @@ fn test_relative_base_not_prefix_of_relative_to() {
|
||||||
.succeeds();
|
.succeeds();
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
result.stdout_matches(&Regex::new(r"^.*:\\usr\n.*:\\usr\\local$").unwrap());
|
result.stdout_matches(&Regex::new(r"^.*:\\usr\n.*:\\usr\\local\n$").unwrap());
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
result.stdout_is("/usr\n/usr/local\n");
|
result.stdout_is("/usr\n/usr/local\n");
|
||||||
|
@ -344,7 +344,7 @@ fn test_relative() {
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
result.stdout_is("/tmp\n.\n");
|
result.stdout_is("/tmp\n.\n");
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
result.stdout_matches(&Regex::new(r"^.*:\\tmp\n\.$").unwrap());
|
result.stdout_matches(&Regex::new(r"^.*:\\tmp\n\.\n$").unwrap());
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-sm", "--relative-base=/", "--relative-to=/", "/", "/usr"])
|
.args(&["-sm", "--relative-base=/", "--relative-to=/", "/", "/usr"])
|
||||||
|
@ -357,7 +357,7 @@ fn test_relative() {
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
result.stdout_is("/tmp\n.\n");
|
result.stdout_is("/tmp\n.\n");
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
result.stdout_matches(&Regex::new(r"^.*:\\tmp\n\.$").unwrap());
|
result.stdout_matches(&Regex::new(r"^.*:\\tmp\n\.\n$").unwrap());
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-sm", "--relative-base=/", "/", "/usr"])
|
.args(&["-sm", "--relative-base=/", "/", "/usr"])
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn test_default_output() {
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_matches(&Regex::new("[rwx-]{10}.*some-file1$").unwrap());
|
.stdout_matches(&Regex::new("[rwx-]{10}.*some-file1\n$").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -598,7 +598,7 @@ impl CmdResult {
|
||||||
|
|
||||||
/// asserts that
|
/// asserts that
|
||||||
/// 1. the command resulted in stderr stream output that equals the
|
/// 1. the command resulted in stderr stream output that equals the
|
||||||
/// passed in value, when both are trimmed of trailing whitespace
|
/// passed in value
|
||||||
/// 2. the command resulted in empty (zero-length) stdout stream output
|
/// 2. the command resulted in empty (zero-length) stdout stream output
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn stderr_only<T: AsRef<str>>(&self, msg: T) -> &Self {
|
pub fn stderr_only<T: AsRef<str>>(&self, msg: T) -> &Self {
|
||||||
|
@ -623,7 +623,7 @@ impl CmdResult {
|
||||||
|
|
||||||
/// asserts that
|
/// asserts that
|
||||||
/// 1. the command resulted in stderr stream output that equals the
|
/// 1. the command resulted in stderr stream output that equals the
|
||||||
/// the following format when both are trimmed of trailing whitespace
|
/// the following format
|
||||||
/// `"{util_name}: {msg}\nTry '{bin_path} {util_name} --help' for more information."`
|
/// `"{util_name}: {msg}\nTry '{bin_path} {util_name} --help' for more information."`
|
||||||
/// This the expected format when a `UUsageError` is returned or when `show_error!` is called
|
/// This the expected format when a `UUsageError` is returned or when `show_error!` is called
|
||||||
/// `msg` should be the same as the one provided to `UUsageError::new` or `show_error!`
|
/// `msg` should be the same as the one provided to `UUsageError::new` or `show_error!`
|
||||||
|
@ -681,7 +681,7 @@ impl CmdResult {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn stdout_matches(&self, regex: ®ex::Regex) -> &Self {
|
pub fn stdout_matches(&self, regex: ®ex::Regex) -> &Self {
|
||||||
assert!(
|
assert!(
|
||||||
regex.is_match(self.stdout_str().trim()),
|
regex.is_match(self.stdout_str()),
|
||||||
"Stdout does not match regex:\n{}",
|
"Stdout does not match regex:\n{}",
|
||||||
self.stdout_str()
|
self.stdout_str()
|
||||||
);
|
);
|
||||||
|
@ -691,7 +691,7 @@ impl CmdResult {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn stdout_does_not_match(&self, regex: ®ex::Regex) -> &Self {
|
pub fn stdout_does_not_match(&self, regex: ®ex::Regex) -> &Self {
|
||||||
assert!(
|
assert!(
|
||||||
!regex.is_match(self.stdout_str().trim()),
|
!regex.is_match(self.stdout_str()),
|
||||||
"Stdout matches regex:\n{}",
|
"Stdout matches regex:\n{}",
|
||||||
self.stdout_str()
|
self.stdout_str()
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue