From c6e207e15b0dcc381c72ed5d94972b3d4f2b1b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 15 Jan 2020 23:00:48 -0700 Subject: Implement success2() as a method --- tests/cli.rs | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'tests/cli.rs') 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")); } -- cgit v1.2.3