Skip to content

Commit b6e63d8

Browse files
committed
fix(test2): Capture names as full paths
Regarding the bug shown visible in the test in the previous commit, where two passing tests both named `foo` would give output that only 1 test passed: The test macros should now always give unique names to all tests, so this is no longer visible when using the macros. However, unique test names is noo guaranteed when using the imperative API, so the bug could still happen (just not when using the macros).
1 parent 55dd64a commit b6e63d8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

crates/libtest2/src/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ macro_rules! _test_parse {
110110
fn name(&self) -> &str {
111111
$crate::_private::push!(crate::TESTS, _: $crate::_private::DynCase = $crate::_private::DynCase(&$name));
112112

113-
stringify!($name)
113+
const FULL_PATH: &str = concat!(std::module_path!(), "::", stringify!($name));
114+
let i = FULL_PATH.find("::").expect("we have inserted this in the line above so it must be there");
115+
&FULL_PATH[(i+2)..]
114116
}
115117
fn kind(&self) -> $crate::_private::TestKind {
116118
Default::default()

crates/libtest2/tests/testsuite/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ fn check() {
3030
let data = str![[r#"
3131
3232
running 2 tests
33-
test foo ... ok
34-
test foo ... ok
33+
test foo ... ok
34+
test some_module::foo ... ok
3535
36-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 filtered out; finished in [..]s
36+
test result: ok. 2 passed; 0 failed; 0 ignored; 0 filtered out; finished in [..]s
3737
3838
3939
"#]];

0 commit comments

Comments
 (0)