aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cli.rs41
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"));
}