Skip to content

Commit 39a8227

Browse files
committed
test(test2): Add test module for attribute macros
This module aims to specifically test that the macros accept various edge cases that a user might expect us to support. This includes: - No parameters - Return result (with and without context as a parameter) - Include context as a parameter, but ignore it - Include context as a parameter and pattern match on it
1 parent c330c63 commit 39a8227

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
fn test_cmd() -> snapbox::cmd::Command {
2+
static BIN: once_cell_polyfill::sync::OnceLock<(std::path::PathBuf, std::path::PathBuf)> =
3+
once_cell_polyfill::sync::OnceLock::new();
4+
5+
let (bin, current_dir) = BIN.get_or_init(|| {
6+
let package_root = crate::util::new_test(
7+
r#"
8+
#[libtest2::main]
9+
fn main() {}
10+
11+
#[libtest2::test]
12+
fn takes_context(_context: &libtest2::TestContext) {}
13+
14+
#[libtest2::test]
15+
fn no_parameters() {}
16+
17+
#[libtest2::test]
18+
fn takes_context_return_result(_context: &libtest2::TestContext) -> libtest2::RunResult {
19+
Ok(())
20+
}
21+
22+
#[libtest2::test]
23+
fn no_parameters_return_result() -> libtest2::RunResult {
24+
Ok(())
25+
}
26+
27+
#[libtest2::test]
28+
fn ignored_context(_: &libtest2::TestContext) {}
29+
30+
#[libtest2::test]
31+
fn context_as_pattern(libtest2::TestContext { .. }: &libtest2::TestContext) {}
32+
"#,
33+
false,
34+
);
35+
let bin = crate::util::compile_test(&package_root);
36+
(bin, package_root)
37+
});
38+
snapbox::cmd::Command::new(bin).current_dir(current_dir)
39+
}
40+
41+
#[test]
42+
fn all_pass() {
43+
test_cmd().assert().code(0);
44+
}

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)