Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/libtest2/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
46 changes: 46 additions & 0 deletions crates/libtest2/tests/testsuite/macros.rs
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions crates/libtest2/tests/testsuite/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod all_passing;
mod argfile;
mod macros;
mod mixed_bag;
mod panic;
mod should_panic;
Expand Down