diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-10-12 16:07:17 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-11-02 18:19:30 +0100 |
commit | 49af82cc68580568c0301dc14695988dd39c738e (patch) | |
tree | 71f637a51e6240eb28839759bf6d89a9a84d395f /tests | |
parent | d78ab6795616cb131a3467141d7635f70f4face9 (diff) |
Add imag-init test
* Extract function to call imag-init for a tempdir path
* Simplify setup helper functions
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ui/src/imag.rs | 21 | ||||
-rw-r--r-- | tests/ui/src/imag_init.rs | 31 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index 987eadc5..a10a19ba 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -17,3 +17,24 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +use std::process::Command; + +use assert_fs::fixture::TempDir; +use assert_cmd::prelude::*; + +pub fn make_temphome() -> TempDir { + TempDir::new().unwrap().persist_if(std::env::var("IMAG_UI_TEST_PERSIST").is_ok()) +} + +pub fn binary(tempdir: &TempDir, binary_name: &str) -> Command { + let path = tempdir.path() + .to_str() + .map(String::from) + .unwrap_or_else(|| panic!("Cannot create imag home path string")); + + let mut cmd = Command::cargo_bin(binary_name).unwrap(); + cmd.arg("--rtp"); + cmd.arg(path); + cmd +} + diff --git a/tests/ui/src/imag_init.rs b/tests/ui/src/imag_init.rs index 987eadc5..2c9cda31 100644 --- a/tests/ui/src/imag_init.rs +++ b/tests/ui/src/imag_init.rs @@ -17,3 +17,34 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +use std::process::Command; + +use assert_cmd::prelude::*; +use assert_fs::fixture::TempDir; + +/// Helper to call imag-init +pub fn call(tempdir: &TempDir) { + binary(tempdir).assert().success(); +} + +pub fn binary(tempdir: &TempDir) -> Command { + let path = tempdir.path() + .to_str() + .map(String::from) + .unwrap_or_else(|| panic!("Cannot create imag home path string")); + + let mut cmd = Command::cargo_bin("imag-init").unwrap(); + cmd.arg("--path"); + cmd.arg(path); + cmd +} + + +#[test] +fn test_init_makes_imag_dir() { + crate::setup_logging(); + let imag_home = crate::imag::make_temphome(); + call(&imag_home); + assert!(imag_home.path().exists(), "imag dir does not exist"); +} + |