diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/update_logic.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/update_logic.rs b/tests/update_logic.rs new file mode 100644 index 0000000..2b74606 --- /dev/null +++ b/tests/update_logic.rs @@ -0,0 +1,48 @@ +use std::fs; +use std::path::Path; +use std::process::{Command, Output}; + +use eyre::{Result, WrapErr}; + +type R = Result<()>; + +fn make(dir: impl AsRef<Path>) -> Result<Output> { + Command::new(env!("CARGO_BIN_EXE_makers")) + .current_dir(dir) + .output() + .wrap_err("") +} + +#[test] +fn basic_test() -> R { + let dir = tempfile::tempdir()?; + let file = " +based-on-what: based-on-this +\techo hi + "; + fs::write(dir.path().join("Makefile"), file)?; + let result = make(&dir)?; + assert!(!result.status.success()); + assert!(String::from_utf8(result.stderr)?.contains("based-on-this")); + + fs::write(dir.path().join("based-on-this"), "")?; + let result = make(&dir)?; + assert!(result.status.success()); + assert!(String::from_utf8(result.stdout)?.contains("echo hi")); + + let result = make(&dir)?; + assert!(result.status.success()); + assert!(String::from_utf8(result.stdout)?.contains("echo hi")); + + fs::write(dir.path().join("based-on-what"), "")?; + let result = make(&dir)?; + assert!(result.status.success()); + assert!(!String::from_utf8(result.stdout)?.contains("echo hi")); + + fs::write(dir.path().join("based-on-this"), "")?; + let result = make(&dir)?; + assert!(result.status.success()); + assert!(String::from_utf8(result.stdout)?.contains("echo hi")); + + Ok(()) +} |