diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-10-13 13:07:07 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-11-02 18:19:30 +0100 |
commit | fd2afad72a045e2fb1bfbd44062a5c30ee0631be (patch) | |
tree | 274bec7d5e8fb6cf8b41d3d62b5cca19ebc837ce /tests | |
parent | 4cbcdc118c36aaa32c358740627439a45d2ea200 (diff) |
Move path calculation to helper function
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ui/src/imag.rs | 23 | ||||
-rw-r--r-- | tests/ui/src/imag_create.rs | 9 |
2 files changed, 24 insertions, 8 deletions
diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index a10a19ba..094a0dfe 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -18,6 +18,7 @@ // use std::process::Command; +use std::path::PathBuf; use assert_fs::fixture::TempDir; use assert_cmd::prelude::*; @@ -38,3 +39,25 @@ pub fn binary(tempdir: &TempDir, binary_name: &str) -> Command { cmd } +/// Run the passed command and get the stdout of it. +/// +/// This function does _not_ ensure that stdin is inherited. +pub fn stdout_of_command(command: Command) -> Vec<String> { + let assert = command.assert(); + let lines = String::from_utf8(assert.get_output().stdout.clone()) + .unwrap() + .lines() + .map(String::from) + .collect(); + assert.success(); + lines +} + +/// Create a PathBuf for a file in a TempDir +pub fn file_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf { + let mut path = tempdir.path().to_path_buf(); + path_elements.iter().for_each(|el| path.push(el)); + debug!("Calculated path = {:?}", path); + path +} + diff --git a/tests/ui/src/imag_create.rs b/tests/ui/src/imag_create.rs index 4e6719f3..a857ed28 100644 --- a/tests/ui/src/imag_create.rs +++ b/tests/ui/src/imag_create.rs @@ -50,14 +50,7 @@ fn test_creating_works() { call(&imag_home, &["test"]); - let entry_path = { - let mut path = imag_home.path().to_path_buf(); - path.push("store"); - path.push("test"); - path - }; - - debug!("Calculated path = {:?}", entry_path); + let entry_path = crate::imag::file_path(&imag_home, &["store", "test"]); assert!(entry_path.exists(), "Entry was not created: {:?}", entry_path); assert!(entry_path.is_file() , "Entry is not a file: {:?}", entry_path); |