1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tests/common: implement CmdResult::usage_error

This commit is contained in:
Thomas Queiroz 2021-11-09 14:43:55 -03:00
parent 0bbc805e43
commit f43dfa9a61
No known key found for this signature in database
GPG key ID: 229D2DDF7ECA5F8F

View file

@ -365,6 +365,23 @@ impl CmdResult {
self self
} }
/// asserts that
/// 1. the command resulted in stderr stream output that equals the
/// the following format when both are trimmed of trailing whitespace
/// `"{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
/// `msg` should be the same as the one provided to UUsageError::new or show_error!
///
/// 2. the command resulted in empty (zero-length) stdout stream output
pub fn usage_error<T: AsRef<str>>(&self, msg: T) -> &CmdResult {
self.stderr_only(format!(
"{0}: {2}\nTry '{1} {0} --help' for more information.",
self.util_name.as_ref().unwrap(), // This shouldn't be called using a normal command
self.bin_path,
msg.as_ref()
))
}
pub fn stdout_contains<T: AsRef<str>>(&self, cmp: T) -> &CmdResult { pub fn stdout_contains<T: AsRef<str>>(&self, cmp: T) -> &CmdResult {
assert!( assert!(
self.stdout_str().contains(cmp.as_ref()), self.stdout_str().contains(cmp.as_ref()),