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

Feature: Optional label in the #[case...] #253

Open
rjzak opened this issue May 12, 2024 · 1 comment
Open

Feature: Optional label in the #[case...] #253

rjzak opened this issue May 12, 2024 · 1 comment

Comments

@rjzak
Copy link

rjzak commented May 12, 2024

Currently, this:

#[rstest]
#[case(include_bytes!("path/to/file.bin"))]
#[case(include_bytes!("path/to/other.bin"))]
fn the_test(#[case] input: &[u8]) {
    do_something(input);
}

Yields:

test module::tests::the_test::case_1 ... ok
test module::tests::the_test::case_2 ... ok

It would be nice to have:

#[rstest]
#[case_label("file.bin qwerty", include_bytes!("path/to/file.bin"))]
#[case_label("other.bin bazfoo", include_bytes!("path/to/other.bin"))]
fn the_test(#[case] input: &[u8]) {
    do_something(input);
}

Which would yield:

test module::tests::the_test::file.bin qwerty ... ok
test module::tests::the_test::other.bin bazfoo ... ok

So if there's an error with a specific case, it's easier to see which one failed.

@la10736
Copy link
Owner

la10736 commented May 13, 2024

First of all you can have something that is quite the same with the following code

#[rstest]
#[case::file_bin__qwerty(include_bytes!("path/to/file.bin"))]
#[case::other_bin__bazfoo(include_bytes!("path/to/other.bin"))]
fn the_test(#[case] input: &[u8]) {
    do_something(input);
}

Sadly you cannot label your tests with an unconstrained string like in kotlin because the rust framework show just the test function path and tests name should be valid identities.

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

No branches or pull requests

2 participants