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

Add the ability to have comments in matrix tests #132

Merged
merged 1 commit into from
Oct 22, 2023

Conversation

ollien
Copy link
Contributor

@ollien ollien commented Oct 2, 2023

On a project of mine, I found a case where it was useful to have more than one test_matrix invocation on a test. However, there was no way from the test output to differentiate them, so I thought I'd add comment support to identify the individual matrices :)

Example:

  #[test_matrix(
      2,
      [1, 3, 5]
      ; "multiplied by two"
  )]
  #[test_matrix(
      [4, 6, 8],
      [1, 3, 5]
      ; "multiplied by an even"
  )]
  fn multiplication_tests(x: i32, y: i32) {
      assert_eq!(0, (x * y) % 2)
  }
[~/Documents/code/test-case-example] nick@cubert$ cargo t
   Compiling tmp v0.1.0 (/home/nick/Documents/code/test-case-example)
    Finished test [unoptimized + debuginfo] target(s) in 0.24s
     Running unittests src/lib.rs (target/debug/deps/tmp-eca7087e9424c00f)

running 12 tests
test tests::multiplication_tests::multiplied_by_an_even_4_1_expects ... ok
test tests::multiplication_tests::multiplied_by_an_even_4_3_expects ... ok
test tests::multiplication_tests::multiplied_by_an_even_6_5_expects ... ok
test tests::multiplication_tests::multiplied_by_an_even_6_1_expects ... ok
test tests::multiplication_tests::multiplied_by_an_even_4_5_expects ... ok
test tests::multiplication_tests::multiplied_by_an_even_8_1_expects ... ok
test tests::multiplication_tests::multiplied_by_an_even_6_3_expects ... ok
test tests::multiplication_tests::multiplied_by_an_even_8_3_expects ... ok
test tests::multiplication_tests::multiplied_by_an_even_8_5_expects ... ok
test tests::multiplication_tests::multiplied_by_two_2_1_expects ... ok
test tests::multiplication_tests::multiplied_by_two_2_3_expects ... ok
test tests::multiplication_tests::multiplied_by_two_2_5_expects ... ok

test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests tmp

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

@@ -29,34 +34,53 @@ where
I: IntoIterator<Item = Expr>,
{
Copy link
Contributor Author

@ollien ollien Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to remove this trait implementation, but it's part of the public interface and I didn't think it was worth forcing a major bump of the crate version. Nothing else in the crate uses it

@ollien
Copy link
Contributor Author

ollien commented Oct 18, 2023

Looks like the new panic formatting in 1.73 blew up some of the testcases. I'll get this fixed tonight

@luke-biel
Copy link
Collaborator

It seems that the tests failed on different target than the one you tried. There's a ./scripts/test_all.sh script that you can use to have complete test suite ran.

@ollien
Copy link
Contributor Author

ollien commented Oct 21, 2023

Ah yep, looks like nightly needed to be updated (I ran it on stable). Should be fixed now :)

@luke-biel luke-biel merged commit 2fc16bf into frondeus:master Oct 22, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants