Skip to content

Commit 55dd64a

Browse files
committed
test(test2): Add test checking module structure
Note that the list of passing tests is 1, even though 2 tests have passed. Probably because they both share the exact same test name: `foo`.
1 parent 63e8214 commit 55dd64a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use snapbox::str;
2+
3+
fn test_cmd() -> snapbox::cmd::Command {
4+
static BIN: once_cell_polyfill::sync::OnceLock<(std::path::PathBuf, std::path::PathBuf)> =
5+
once_cell_polyfill::sync::OnceLock::new();
6+
let (bin, current_dir) = BIN.get_or_init(|| {
7+
let package_root = crate::util::new_test(
8+
r#"
9+
#[libtest2::main]
10+
fn main() {}
11+
12+
#[libtest2::test]
13+
fn foo(_context: &libtest2::TestContext) {}
14+
15+
mod some_module {
16+
#[libtest2::test]
17+
fn foo(_context: &libtest2::TestContext) {}
18+
}
19+
"#,
20+
false,
21+
);
22+
let bin = crate::util::compile_test(&package_root);
23+
(bin, package_root)
24+
});
25+
snapbox::cmd::Command::new(bin).current_dir(current_dir)
26+
}
27+
28+
#[test]
29+
fn check() {
30+
let data = str![[r#"
31+
32+
running 2 tests
33+
test foo ... ok
34+
test foo ... ok
35+
36+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 filtered out; finished in [..]s
37+
38+
39+
"#]];
40+
41+
test_cmd()
42+
.args(["--test-threads", "1"])
43+
.assert()
44+
.success()
45+
.stdout_eq(data);
46+
}

crates/libtest2/tests/testsuite/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod all_passing;
22
mod argfile;
3+
mod macros;
34
mod mixed_bag;
45
mod panic;
56
mod should_panic;

0 commit comments

Comments
 (0)