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 support for #[test_case] crate #684

Open
NicolasWent opened this issue Nov 15, 2024 · 0 comments
Open

Add support for #[test_case] crate #684

NicolasWent opened this issue Nov 15, 2024 · 0 comments

Comments

@NicolasWent
Copy link

NicolasWent commented Nov 15, 2024

Hello,

When I use test_case crate with insta, I get wrong test name results and the tests are not passing when I don't modify the code and re-run them

Minimal reproducing example:

Cargo.toml:

[package]
name = "insta-suggestion"
version = "0.1.0"
edition = "2021"

[dependencies]
test-case = "3.3"
insta = { version = "1.41", features = ["yaml"] }

lib.rs:

use insta::assert_yaml_snapshot;
use test_case::test_case;

pub fn to_upper_case(text: &str) -> String {
    text.to_uppercase()
}

#[test_case("Hello World" ; "test_hello_world")]
#[test_case("Insta is fun" ; "test_insta_is_fun")]
fn test_function(text: &str) {
    let res = to_upper_case(text);
    assert_yaml_snapshot!(res);
}

What happens

Running cargo test will create two files:
insta_suggestion__function-2.snap.new
and
insta_suggestion__function.snap.new

If I re-run cargo test, it will fail everytime

Expected output

The two files created should have the right name with "test_hello_world" and "test_insta_is_fun" instead of "test_function"

Aditionaly, if we re-run cargo test without changing anything, the tests shouldn't fail

Why this would be a good features

Pros

insta seems to be a crate designed to write tests faster, test_case also. It would be amazing to combine both and be able to write lots of tests very fast

Cons

Some features, specially with the @"" keyword or the vscode extension will be hard to work with

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

1 participant