galvanic-test
galvanic-test copied to clipboard
Tests with fixtures don't handle `should_panic` expectation messages
Tests without fixtures work as expected with #[should_panic]
. However, tests with fixtures don't. Using an expected
message as in #[should_panic(expected = "whatever")
doesn't work. The test will always fail, even if the panic message was correct. This diff demonstrates the problem
diff --git a/tests/test_suite.rs b/tests/test_suite.rs
index d0ca37e..5d54bd3 100644
--- a/tests/test_suite.rs
+++ b/tests/test_suite.rs
@@ -30,6 +30,11 @@ test_suite! {
test simple_test() {
assert!(true);
}
+
+ #[should_panic(expected = "xxx")]
+ test panic_test() {
+ panic!("xxx");
+ }
}
test_suite! {
@@ -44,6 +49,11 @@ test_suite! {
test inject_fixture(test_fixture) {
assert_eq!(test_fixture.val, 42);
}
+
+ #[should_panic(expected = "xxx")]
+ test panic_test(test_fixture) {
+ panic!("xxx");
+ }
}
test_suite! {
I had a look at this one and it seems to be tricky to solve. The problem occurs because if a test with a fixture fails, the library prints additional information on the fixtures' parametrisation. This seems to interfere with the expected message.
I have no quick fix for this at the moment, but I added a note to the documentation.
I'll try to address this issue in the next version, though I'm not sure if it's possible without sacrificing clearer error messages. As a workaround I'll try to add a matcher to the next version of the galvanic-assert
library.