mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 01:38:04 +00:00
tests: add CmdResult::stdout_is_fixture_bytes()
Add helper method `CmdResult::stdout_is_fixture_bytes()`, which is like `stdout_is_fixture()` but compares stdout to the raw bytes of a given file instead of decoding the contents of the file to a UTF-8 string.
This commit is contained in:
parent
67cee26abe
commit
e598bf0835
1 changed files with 22 additions and 0 deletions
|
@ -265,6 +265,28 @@ impl CmdResult {
|
|||
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
|
||||
self.stdout_is(String::from_utf8(contents).unwrap())
|
||||
}
|
||||
|
||||
/// Assert that the bytes of stdout exactly match those of the given file.
|
||||
///
|
||||
/// Contrast this with [`CmdResult::stdout_is_fixture`], which
|
||||
/// decodes the contents of the file as a UTF-8 [`String`] before
|
||||
/// comparison with stdout.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Use this method in a unit test like this:
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// #[test]
|
||||
/// fn test_something() {
|
||||
/// new_ucmd!().succeeds().stdout_is_fixture_bytes("expected.bin");
|
||||
/// }
|
||||
/// ```
|
||||
pub fn stdout_is_fixture_bytes<T: AsRef<OsStr>>(&self, file_rel_path: T) -> &Self {
|
||||
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
|
||||
self.stdout_is_bytes(contents)
|
||||
}
|
||||
|
||||
/// like stdout_is_fixture(...), but replaces the data in fixture file based on values provided in template_vars
|
||||
/// command output
|
||||
pub fn stdout_is_templated_fixture<T: AsRef<OsStr>>(
|
||||
|
|
Loading…
Reference in a new issue