diff options
author | Ondřej Čertík <ondrej@certik.us> | 2020-01-15 23:00:48 -0700 |
---|---|---|
committer | Ondřej Čertík <ondrej@certik.us> | 2020-01-15 23:06:09 -0700 |
commit | c6e207e15b0dcc381c72ed5d94972b3d4f2b1b18 (patch) | |
tree | f8f84847f3d9f6f977b6b7eed7a4685b356b38a1 | |
parent | 710a9fa4da4f208462d51b594e27c588e4b39f61 (diff) | |
download | fpm-c6e207e15b0dcc381c72ed5d94972b3d4f2b1b18.tar.gz fpm-c6e207e15b0dcc381c72ed5d94972b3d4f2b1b18.zip |
Implement success2() as a method
-rw-r--r-- | tests/cli.rs | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index d980853..fb73e8a 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -4,25 +4,32 @@ use predicates::prelude::*; // Used for writing assertions use assert_cmd::assert::Assert; use std::os::unix::process::ExitStatusExt; -// Our own function, so that we can better debug the failure -fn success(self0: Assert) -> Assert { - if !self0.get_output().status.success() { - let code = self0.get_output().status.code(); - if code.is_none() { - let signal = self0.get_output().status.signal().unwrap(); - panic!("INTERRUPTED with signal: {}", signal); +pub trait Success2 { + // Our own function with better reporting of errors + fn success2(self) -> Self; +} + +impl Success2 for Assert { + fn success2(self) -> Self { + if !self.get_output().status.success() { + let code = self.get_output().status.code(); + if code.is_none() { + let signal = self.get_output().status.signal().unwrap(); + panic!("INTERRUPTED with signal: {}", signal); + } + let actual_code = code.unwrap(); + panic!("Non zero exit code: {}", actual_code); } - let actual_code = code.unwrap(); - panic!("Non zero exit code: {}", actual_code); + self } - self0 } #[test] fn test_help() { let mut cmd = Command::cargo_bin("fpm").unwrap(); cmd.arg("--help"); - success(cmd.assert()) + cmd.assert() + .success2() .stdout( predicate::str::contains("--help Prints help information")); } @@ -33,14 +40,16 @@ fn test_1() { let mut build = Command::cargo_bin("fpm").unwrap(); build.arg("build") .current_dir("tests/1"); - success(build.assert()) + build.assert() + .success2() .stdout(predicate::str::contains("Built target p1") .and(predicate::str::contains("TEST1 OK").not())); let mut run = Command::cargo_bin("fpm").unwrap(); run.arg("run") .current_dir("tests/1"); - success(run.assert()) + run.assert() + .success2() .stdout(predicate::str::contains("TEST1 OK")); } @@ -49,13 +58,15 @@ fn test_2() { let mut build = Command::cargo_bin("fpm").unwrap(); build.arg("build") .current_dir("tests/2"); - success(build.assert()) + build.assert() + .success2() .stdout(predicate::str::contains("Built target p1") .and(predicate::str::contains("TEST2 OK").not())); let mut run = Command::cargo_bin("fpm").unwrap(); run.arg("run") .current_dir("tests/2"); - success(run.assert()) + run.assert() + .success2() .stdout(predicate::str::contains("TEST2 OK")); } |