Hi,
Right now the Span of a test case Ident is derived from the macro's call site. This means the observable source location for every test is grouped on the first invocation of test_case, which leads to side effects in tools that utilize those locations (e.g. the rust-analyzer Visual Studio Code extension and some new additions to listing tests in a binary.) I was able to throw together a change which uses Ident::set_span to match the emitted test function to its source attribute, but I'm not very savvy on proc macros/hygiene and wasn't sure if doing so is bad practice. If there aren't any issues with it, I could open a PR to introduce the change. I've included below examples of rust-analyzer's test decorations on the readme's sample code and cargo test -- --list -Zunstable-options --format=json run on nightly both before and after applying the change to demonstrate.
Before

$ cargo test -- --list -Zunstable-options --format=json
...
{ "type": "test", "event": "discovered", "name": "tests::multiplication_tests::when_both_operands_are_negative", "ignore": false, "ignore_message": "", "source_path": "tests/example.rs", "start_line": 15, "start_col": 5, "end_line": 15, "end_col": 61 }
{ "type": "test", "event": "discovered", "name": "tests::multiplication_tests::when_both_operands_are_positive", "ignore": false, "ignore_message": "", "source_path": "tests/example.rs", "start_line": 15, "start_col": 5, "end_line": 15, "end_col": 61 }
{ "type": "test", "event": "discovered", "name": "tests::multiplication_tests::when_operands_are_swapped", "ignore": false, "ignore_message": "", "source_path": "tests/example.rs", "start_line": 15, "start_col": 5, "end_line": 15, "end_col": 61 }
After

$ cargo test -- --list -Zunstable-options --format=json
...
{ "type": "test", "event": "discovered", "name": "tests::multiplication_tests::when_both_operands_are_negative", "ignore": false, "ignore_message": "", "source_path": "tests/example.rs", "start_line": 15, "start_col": 5, "end_line": 15, "end_col": 61 }
{ "type": "test", "event": "discovered", "name": "tests::multiplication_tests::when_both_operands_are_positive", "ignore": false, "ignore_message": "", "source_path": "tests/example.rs", "start_line": 16, "start_col": 5, "end_line": 16, "end_col": 61 }
{ "type": "test", "event": "discovered", "name": "tests::multiplication_tests::when_operands_are_swapped", "ignore": false, "ignore_message": "", "source_path": "tests/example.rs", "start_line": 17, "start_col": 5, "end_line": 17, "end_col": 55 }
Hi,
Right now the
Spanof a test caseIdentis derived from the macro's call site. This means the observable source location for every test is grouped on the first invocation oftest_case, which leads to side effects in tools that utilize those locations (e.g. the rust-analyzer Visual Studio Code extension and some new additions to listing tests in a binary.) I was able to throw together a change which usesIdent::set_spanto match the emitted test function to its source attribute, but I'm not very savvy on proc macros/hygiene and wasn't sure if doing so is bad practice. If there aren't any issues with it, I could open a PR to introduce the change. I've included below examples of rust-analyzer's test decorations on the readme's sample code andcargo test -- --list -Zunstable-options --format=jsonrun on nightly both before and after applying the change to demonstrate.Before
After