Skip to content

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

Merged
Y-Nak merged 2 commits intofe-lang:mainfrom
sbillig:test_name_prefix
May 16, 2024
Merged

Prefix generated test names with user-defined test fn name#7
Y-Nak merged 2 commits intofe-lang:mainfrom
sbillig:test_name_prefix

Conversation

@sbillig
Copy link
Copy Markdown
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
Copy Markdown
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
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