diff options
author | Ondřej Čertík <ondrej@certik.us> | 2020-01-15 23:50:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-15 23:50:37 -0700 |
commit | 2d50ae9f8346d3d2f1516d8cbaf7c367aff1d2f8 (patch) | |
tree | e71b092a30313bc1124ec151e7dada38049c86bd | |
parent | c08b52b764ea3cc5e4c6853529aedaccff62e8e7 (diff) | |
parent | a9b2a4aaf145a55c54642d4592d92c739e3a4b0f (diff) | |
download | fpm-2d50ae9f8346d3d2f1516d8cbaf7c367aff1d2f8.tar.gz fpm-2d50ae9f8346d3d2f1516d8cbaf7c367aff1d2f8.zip |
Merge pull request #18 from certik/success
Better reporting on terminated processes
-rw-r--r-- | tests/cli.rs | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index 09e42e9..2d32e4d 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,24 +1,66 @@ use std::process::Command; // Run programs use assert_cmd::prelude::*; // Add methods on commands use predicates::prelude::*; // Used for writing assertions +use assert_cmd::assert::Assert; +#[cfg(unix)] +use std::os::unix::process::ExitStatusExt; +use std::process::ExitStatus; + +pub trait Success2 { + // Our own function with better reporting of errors + fn success2(self) -> Self; +} + +#[cfg(unix)] +fn get_signal(status: ExitStatus) -> Option<i32> { + status.signal() +} + +#[cfg(not(unix))] +fn get_signal(_status: ExitStatus) -> Option<i32> { + None +} + +impl Success2 for Assert { + fn success2(self) -> Self { + if !self.get_output().status.success() { + let output = self.get_output(); + let code = output.status.code(); + println!("status: {}", output.status); + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + if cfg!(unix) { + if code.is_none() { + let signal = get_signal(output.status).unwrap(); + panic!("INTERRUPTED with signal: {}", signal); + } + } + let actual_code = code.unwrap(); + println!("code: {}", actual_code); + panic!("Non zero exit code"); + } + self + } +} #[test] fn test_help() { let mut cmd = Command::cargo_bin("fpm").unwrap(); cmd.arg("--help"); cmd.assert() - .success() + .success2() .stdout( predicate::str::contains("--help Prints help information")); } + #[test] fn test_1() { let mut build = Command::cargo_bin("fpm").unwrap(); build.arg("build") .current_dir("tests/1"); build.assert() - .success() + .success2() .stdout(predicate::str::contains("Built target p1") .and(predicate::str::contains("TEST1 OK").not())); @@ -26,7 +68,7 @@ fn test_1() { run.arg("run") .current_dir("tests/1"); run.assert() - .success() + .success2() .stdout(predicate::str::contains("TEST1 OK")); } @@ -36,7 +78,7 @@ fn test_2() { build.arg("build") .current_dir("tests/2"); build.assert() - .success() + .success2() .stdout(predicate::str::contains("Built target p1") .and(predicate::str::contains("TEST2 OK").not())); @@ -44,6 +86,6 @@ fn test_2() { run.arg("run") .current_dir("tests/2"); run.assert() - .success() + .success2() .stdout(predicate::str::contains("TEST2 OK")); } |