diff --git a/crates/libtest2/src/macros.rs b/crates/libtest2/src/macros.rs index 54eef9a..9441dbb 100644 --- a/crates/libtest2/src/macros.rs +++ b/crates/libtest2/src/macros.rs @@ -110,7 +110,9 @@ macro_rules! _test_parse { fn name(&self) -> &str { $crate::_private::push!(crate::TESTS, _: $crate::_private::DynCase = $crate::_private::DynCase(&$name)); - stringify!($name) + const FULL_PATH: &str = concat!(std::module_path!(), "::", stringify!($name)); + let i = FULL_PATH.find("::").expect("we have inserted this in the line above so it must be there"); + &FULL_PATH[(i+2)..] } fn kind(&self) -> $crate::_private::TestKind { Default::default() diff --git a/crates/libtest2/tests/testsuite/macros.rs b/crates/libtest2/tests/testsuite/macros.rs new file mode 100644 index 0000000..37b439c --- /dev/null +++ b/crates/libtest2/tests/testsuite/macros.rs @@ -0,0 +1,46 @@ +use snapbox::str; + +fn test_cmd() -> snapbox::cmd::Command { + static BIN: once_cell_polyfill::sync::OnceLock<(std::path::PathBuf, std::path::PathBuf)> = + once_cell_polyfill::sync::OnceLock::new(); + let (bin, current_dir) = BIN.get_or_init(|| { + let package_root = crate::util::new_test( + r#" +#[libtest2::main] +fn main() {} + +#[libtest2::test] +fn foo(_context: &libtest2::TestContext) {} + +mod some_module { + #[libtest2::test] + fn foo(_context: &libtest2::TestContext) {} +} +"#, + false, + ); + let bin = crate::util::compile_test(&package_root); + (bin, package_root) + }); + snapbox::cmd::Command::new(bin).current_dir(current_dir) +} + +#[test] +fn check() { + let data = str![[r#" + +running 2 tests +test foo ... ok +test some_module::foo ... ok + +test result: ok. 2 passed; 0 failed; 0 ignored; 0 filtered out; finished in [..]s + + +"#]]; + + test_cmd() + .args(["--test-threads", "1"]) + .assert() + .success() + .stdout_eq(data); +} diff --git a/crates/libtest2/tests/testsuite/main.rs b/crates/libtest2/tests/testsuite/main.rs index 2d83e9d..3d176ee 100644 --- a/crates/libtest2/tests/testsuite/main.rs +++ b/crates/libtest2/tests/testsuite/main.rs @@ -1,5 +1,6 @@ mod all_passing; mod argfile; +mod macros; mod mixed_bag; mod panic; mod should_panic;