mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
cksum: Fix file quoting on stderr (#8272)
* cksum: handle escaping in stderr for file errors * uutests: Minor fix and stdX_contains_bytes feature * test(cksum): add test for stderr escaping
This commit is contained in:
parent
c64adee068
commit
56ce0e28ad
5 changed files with 91 additions and 14 deletions
|
@ -71,7 +71,7 @@ macro_rules! new_ucmd {
|
|||
#[macro_export]
|
||||
macro_rules! at_and_ucmd {
|
||||
() => {{
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let ts = ::uutests::util::TestScenario::new(::uutests::util_name!());
|
||||
(ts.fixtures.clone(), ts.ucmd())
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
clippy::missing_errors_doc
|
||||
)]
|
||||
|
||||
use core::str;
|
||||
#[cfg(unix)]
|
||||
use libc::mode_t;
|
||||
#[cfg(unix)]
|
||||
|
@ -758,6 +759,29 @@ impl CmdResult {
|
|||
self
|
||||
}
|
||||
|
||||
/// Verify if stdout contains a byte sequence
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// new_ucmd!()
|
||||
/// .arg("--help")
|
||||
/// .succeeds()
|
||||
/// .stdout_contains_bytes(b"hello \xff");
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn stdout_contains_bytes<T: AsRef<[u8]>>(&self, cmp: T) -> &Self {
|
||||
assert!(
|
||||
self.stdout()
|
||||
.windows(cmp.as_ref().len())
|
||||
.any(|sub| sub == cmp.as_ref()),
|
||||
"'{:?}'\ndoes not contain\n'{:?}'",
|
||||
self.stdout(),
|
||||
cmp.as_ref()
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
/// Verify if stderr contains a specific string
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -780,6 +804,29 @@ impl CmdResult {
|
|||
self
|
||||
}
|
||||
|
||||
/// Verify if stderr contains a byte sequence
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// new_ucmd!()
|
||||
/// .arg("--help")
|
||||
/// .succeeds()
|
||||
/// .stdout_contains_bytes(b"hello \xff");
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn stderr_contains_bytes<T: AsRef<[u8]>>(&self, cmp: T) -> &Self {
|
||||
assert!(
|
||||
self.stderr()
|
||||
.windows(cmp.as_ref().len())
|
||||
.any(|sub| sub == cmp.as_ref()),
|
||||
"'{:?}'\ndoes not contain\n'{:?}'",
|
||||
self.stderr(),
|
||||
cmp.as_ref()
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
/// Verify if stdout does not contain a specific string
|
||||
///
|
||||
/// # Examples
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue