diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-10-20 19:18:39 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-11-03 11:30:33 +0100 |
commit | 485ad3815f20184b59a1212d0379e998cbdc37c7 (patch) | |
tree | 42113f02686564871c64736ea9a7d0b37ce5456f /tests | |
parent | 0c685fde738736ec8476c13e8f22ab1a55226206 (diff) |
Add helper function to get stderr of a command
But also get back the Assert object, which can then be used to check
whether the command succeeded or failed.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ui/src/imag.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index 34edbb4c..fb413ab3 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -22,6 +22,7 @@ use std::path::PathBuf; use assert_fs::fixture::TempDir; use assert_cmd::prelude::*; +use assert_cmd::assert::Assert; pub fn make_temphome() -> TempDir { TempDir::new().unwrap().persist_if(std::env::var("IMAG_UI_TEST_PERSIST").is_ok()) @@ -53,6 +54,19 @@ pub fn stdout_of_command(mut command: Command) -> Vec<String> { lines } +/// Run the passed command and get the stderr of it. +/// +/// This function does _not_ ensure that stdin is inherited. +pub fn stderr_of_command(command: &mut Command) -> (Assert, Vec<String>) { + let assert = command.assert(); + let lines = String::from_utf8(assert.get_output().stderr.clone()) + .unwrap() + .lines() + .map(String::from) + .collect(); + (assert, lines) +} + /// Create a PathBuf for a file in a TempDir pub fn file_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf { create_path_for(tempdir.path().to_path_buf(), path_elements) |