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

#[test_log::test(test_case::test_case)] doesn't work with multiple cases #35

Open
tamird opened this issue Nov 7, 2023 · 3 comments · May be fixed by #46
Open

#[test_log::test(test_case::test_case)] doesn't work with multiple cases #35

tamird opened this issue Nov 7, 2023 · 3 comments · May be fixed by #46

Comments

@tamird
Copy link
Contributor

tamird commented Nov 7, 2023

Spin-off from #30.

It is not possible to write #[test_case(...)] tests with multiple cases. For example

#[test_log::test(test_case::test_case(-2, -4; "one"))]
#[test_log::test(test_case::test_case(-4, -2; "two"))]
fn it_works(x: i8, y: i8) {
  // ...
}

does not work.

I think the approach of wrapping other test macros such as tokio::test and test_case::test_case in the
test_log::test macro ends up being inflexible for such cases and it's probably better to abandon it in favor of
parsing other attributes on the test function and inserting #[test] only if nothing else has already done it. This
would mean that ordering of attributes would start to matter but this is already the case when test_case::test_case is
composed with tokio::test; test_case has to come first or else compilation fails with "functions used as tests can not have any arguments".

@d-e-s-o
Copy link
Owner

d-e-s-o commented Nov 9, 2023

it's probably better to abandon it in favor of parsing other attributes on the test function and inserting #[test] only if nothing else has already done it

I am not sure I completely understand the proposal. How would we be able to detect that fact? Aren't both tokio::test and test_case::test_case just arbitrary strings? Could you sketch the proposal out some more, please?

@tamird
Copy link
Contributor Author

tamird commented Nov 9, 2023

I'm afraid I waited too long to file this proposal and have forgotten some of the details. That said it's empirically true that test_case plays well with tokio::test; we should be able to use the same technique they do.

@jtojnar
Copy link

jtojnar commented Mar 22, 2024

Alternately, maybe it would be possible to offer a separate attribute for those cases when passing it as an attribute is not sufficient.

For example tracing_test uses a separate attribute. Of course, user will then need to be careful to order the attributes correctly.

kezhuw added a commit to kezhuw/test-log that referenced this issue Apr 19, 2024
This way if preceding test macros add `#[::core::prelude::v1::test]` by
appending, then we can avoid duplicated test runs.

See also frondeus/test-case#101, frondeus/test-case#143

Closes d-e-s-o#35.
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 a pull request may close this issue.

3 participants