Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests with fixtures don't handle should_panic expectation messages #15

Open
asomers opened this issue Nov 7, 2018 · 1 comment
Open
Labels

Comments

@asomers
Copy link
Contributor

asomers commented Nov 7, 2018

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! {
@mindsbackyard
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants