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

Allow customizing the "length" of the test case names from the path #212

Open
stonecharioteer opened this issue Sep 4, 2023 · 1 comment

Comments

@stonecharioteer
Copy link

Following up from #205:

Great! Thanks for your work. Is it possible, btw, to customize the test case names? Right now, the way we've set things up gives us really similar test case names, since we have multiple nested data directories. I'd like to say "hey, generate the test case names only from the last 3 segments of the path" or something.

When you have tests that access multiple nested directories in a folder, irrespective of whether they're in a subfolder or in another folder outside of the crate, as described in #205, if you have nested folders for the globbed files, you will soon see patterns where you get test cases with the exact same name, because the "unique" part of the test case is truncated off in the file name.

This could perhaps be resolved with an optional parameter for segment: u8, which takes the last few directory levels to generate this, and the onus of readability is left to the user. Of course, the depth will have to be in reverse, if you have a file /home/user/data/more-data/nice-little-folder/case_0/subcase_10/file.yml, and you give a segment=3, the code should use case_0/subcase_10/file.yml. I'm open to alternate solutions on this, as long as it is possible to ascertain which test case failed.

@ivan23kor
Copy link

+1, I want to see some customization for the test names defined under the #[files] macro.

Keeping the last components: u8 path components would suffice but I can imagine a use case, where it is desirable to include components starting at a given path, so maybe that's a more general solution.

For example, if I have the following directory structure:

../../../test-cases/
├── advanced
│   ├── A
│   │   └── case2.txt
│   ├── B
│   │   └── case3.txt
│   └── case4.txt
└── case1.txt

I would like test names to include only the differing components of the path. Either the default should trim common path prefix or the user would have to specify such behaviour like this:

#[rstest]
#[trim_path_prefixes(["../../../test-cases"])]
fn tests(#[files("glob")] path: std::path::PathBuf) {
  ...
}

So, the test cases would be named

tests::path_1_advanced_A_case2_txt
tests::path_2_advanced_B_case3_txt
tests::path_3_advanced_case4_txt
tests::path_4_case1_txt

instead of

tests::path_1__UP__UP__UP_test_cases_advanced_A_case2_txt
tests::path_2__UP__UP__UP_test_cases_advanced_B_case3_txt
tests::path_3__UP__UP__UP_test_cases_advanced_case4_txt
tests::path_4__UP__UP__UP_test_cases_case1_txt

trim_path_prefixes([...]) would accept an array of prefixes to trim: each prefix from this array would be compared against each test case path and trim the prefix on match. Trim at most one prefix from a path and don't change the test case path if none of the prefixes match.

Optionally, trim file extensions.

@la10736 what do you think about such proposal? I am willing to do the implementation but I need a second brain to bounce ideas off.

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