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

Prefix generated test names with user-defined test fn name #7

Merged
merged 2 commits into from
May 16, 2024

Conversation

sbillig
Copy link
Contributor

@sbillig sbillig commented May 16, 2024

I ran into a minor problem with code like this:

#[dir_test(
    dir: "$CARGO_MANIFEST_DIR/test_files/syntax/func",
    glob: "*.sntn"
)]
fn test_func(fixture: Fixture<&str>) {
    test_rule(Rule::functions, fixture)
}

#[dir_test(
    dir: "$CARGO_MANIFEST_DIR/test_files/syntax/module",
    glob: "*.sntn"
)]
fn test_module(fixture: Fixture<&str>) {
    test_rule(Rule::module, fixture)
}

where both of the directories contain a file called "simple.sntn", and thus two test functions called "simple" are generated. I could have manually specified a suffix to the dir_test attribute, but I think it's better for this situation to work by default. I solved this by prefixing the generated test names with the name of the function that the dir_test attribute is attached to; in this case the generated tests are test_func__simple and test_module__simple.

This change is also makes the cargo test output more clear when there are many test functions specified, and files with generic name. Eg

test test_item_list__use ... ok
test test_pat__record ... ok
test test_struct__empty ... ok
test test_stmt__assign ... ok
test test_struct__attr ... ok
test test_stmt__while ... ok
test test_stmt__for ... ok
test test_pat__path_tuple ... ok

Copy link
Collaborator

@Y-Nak Y-Nak left a comment

Choose a reason for hiding this comment

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

LGTM!
I'll bump up the version to 0.3.

@Y-Nak Y-Nak merged commit d54fdf0 into fe-lang:main May 16, 2024
5 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