From 59f6d5e1385887995f0f2541e9c751be36834aed Mon Sep 17 00:00:00 2001 From: David Rusu Date: Wed, 29 Dec 2021 23:15:04 -0500 Subject: [PATCH] only build debug representations of arguments even on failing tests --- src/tester.rs | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/tester.rs b/src/tester.rs index e2eaa20..66fcc4c 100644 --- a/src/tester.rs +++ b/src/tester.rs @@ -189,7 +189,7 @@ pub fn quickcheck(f: A) { #[derive(Clone, Debug)] pub struct TestResult { status: Status, - arguments: Vec, + arguments: Option>, err: Option, } @@ -224,7 +224,7 @@ impl TestResult { /// When a test is discarded, `quickcheck` will replace it with a /// fresh one (up to a certain limit). pub fn discard() -> TestResult { - TestResult { status: Discard, arguments: vec![], err: None } + TestResult { status: Discard, arguments: None, err: None } } /// Converts a `bool` to a `TestResult`. A `true` value indicates that @@ -233,7 +233,7 @@ impl TestResult { pub fn from_bool(b: bool) -> TestResult { TestResult { status: if b { Pass } else { Fail }, - arguments: vec![], + arguments: None, err: None, } } @@ -266,16 +266,15 @@ impl TestResult { } fn failed_msg(&self) -> String { + let arguments_msg = match self.arguments { + None => format!("No Arguments Provided"), + Some(ref args) => format!("Arguments: ({})", args.join(", ")), + }; match self.err { - None => format!( - "[quickcheck] TEST FAILED. Arguments: ({})", - self.arguments.join(", ") - ), + None => format!("[quickcheck] TEST FAILED. {}", arguments_msg), Some(ref err) => format!( - "[quickcheck] TEST FAILED (runtime error). \ - Arguments: ({})\nError: {}", - self.arguments.join(", "), - err + "[quickcheck] TEST FAILED (runtime error). {}\nError: {}", + arguments_msg, err ), } } @@ -350,7 +349,7 @@ impl r, Fail => { @@ -429,7 +423,7 @@ mod test { .quicktest(thetest as fn(vals: Vec) -> bool) .unwrap_err(); let expected_argument = format!("{:?}", [true, true]); - assert_eq!(failing_case.arguments, vec![expected_argument]); + assert_eq!(failing_case.arguments, Some(vec![expected_argument])); } #[test]