From 7b53dd48556cf792359c030fcdb01693e1db45b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 15 Jan 2020 22:44:55 -0700 Subject: Add our own implementation of success() --- tests/cli.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index 09e42e9..ebdcd24 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,32 +1,42 @@ 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; + +// Our own function, so that we can better debug the failure +fn success(self0: Assert) -> Assert { + if !self0.get_output().status.success() { + let actual_code = self0.get_output().status.code().unwrap_or_else(|| { + panic!("INTERRUPTED") + }); + panic!("Non zero exit code: {}", actual_code); + } + self0 +} #[test] fn test_help() { let mut cmd = Command::cargo_bin("fpm").unwrap(); cmd.arg("--help"); - cmd.assert() - .success() + success(cmd.assert()) .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() + success(build.assert()) .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"); - run.assert() - .success() + success(run.assert()) .stdout(predicate::str::contains("TEST1 OK")); } @@ -35,15 +45,13 @@ fn test_2() { let mut build = Command::cargo_bin("fpm").unwrap(); build.arg("build") .current_dir("tests/2"); - build.assert() - .success() + success(build.assert()) .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"); - run.assert() - .success() + success(run.assert()) .stdout(predicate::str::contains("TEST2 OK")); } -- cgit v1.2.3 From 710a9fa4da4f208462d51b594e27c588e4b39f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 15 Jan 2020 22:55:04 -0700 Subject: Extract the signal and report it --- tests/cli.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index ebdcd24..d980853 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -2,13 +2,17 @@ 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; +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 actual_code = self0.get_output().status.code().unwrap_or_else(|| { - panic!("INTERRUPTED") - }); + let code = self0.get_output().status.code(); + if code.is_none() { + let signal = self0.get_output().status.signal().unwrap(); + panic!("INTERRUPTED with signal: {}", signal); + } + let actual_code = code.unwrap(); panic!("Non zero exit code: {}", actual_code); } self0 -- cgit v1.2.3 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') 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 From 1f7bf6c0335a6979e11a62fc07cd8cb7c1c04464 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:07:59 -0700 Subject: Only import std::os::unix on Unix --- tests/cli.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index fb73e8a..40fabbd 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -2,6 +2,7 @@ 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; pub trait Success2 { @@ -13,9 +14,11 @@ 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); + if cfg!(unix) { + 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); -- cgit v1.2.3 From fe55ad285512afb2ce59d5b3bcb0aa56effc798a 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:19:20 -0700 Subject: Let it compile on Windows --- tests/cli.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index 40fabbd..33e63cd 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -4,19 +4,30 @@ 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 { + status.signal() +} + +#[cfg(not(unix))] +fn get_signal(status: ExitStatus) -> Option { + None +} + impl Success2 for Assert { fn success2(self) -> Self { if !self.get_output().status.success() { let code = self.get_output().status.code(); if cfg!(unix) { if code.is_none() { - let signal = self.get_output().status.signal().unwrap(); + let signal = get_signal(self.get_output().status).unwrap(); panic!("INTERRUPTED with signal: {}", signal); } } -- cgit v1.2.3 From 322ef7812ff80510f7219e7ca5703cc5f38decd3 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:24:15 -0700 Subject: Fix a warning on Windows --- tests/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index 33e63cd..34f0ae7 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -17,7 +17,7 @@ fn get_signal(status: ExitStatus) -> Option { } #[cfg(not(unix))] -fn get_signal(status: ExitStatus) -> Option { +fn get_signal(_status: ExitStatus) -> Option { None } -- cgit v1.2.3 From a9b2a4aaf145a55c54642d4592d92c739e3a4b0f 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:34:30 -0700 Subject: Print stderr and stdout --- tests/cli.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index 34f0ae7..2d32e4d 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -24,15 +24,20 @@ fn get_signal(_status: ExitStatus) -> Option { impl Success2 for Assert { fn success2(self) -> Self { if !self.get_output().status.success() { - let code = self.get_output().status.code(); + 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(self.get_output().status).unwrap(); + let signal = get_signal(output.status).unwrap(); panic!("INTERRUPTED with signal: {}", signal); } } let actual_code = code.unwrap(); - panic!("Non zero exit code: {}", actual_code); + println!("code: {}", actual_code); + panic!("Non zero exit code"); } self } -- cgit v1.2.3