Skip to content

Commit c330c63

Browse files
committed
feat(test2): Support empty parameter list in #[test]
This supports using the `test` attribute on function with no parameters: ``` #[libtest2::test] fn simple_test() { ... } ```
1 parent 63e8214 commit c330c63

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

crates/libtest2/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub mod _private {
6666
pub use crate::_main_parse as main_parse;
6767
pub use crate::_parse_ignore as parse_ignore;
6868
pub use crate::_run_test as run_test;
69+
pub use crate::_test_expr as test_expr;
6970
pub use crate::_test_parse as test_parse;
7071
pub use crate::case::DynCase;
7172
}

crates/libtest2/src/macros.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ macro_rules! _test_parse {
102102
};
103103

104104
// End result
105-
(break: name=$name:ident body=[$($item:tt)*] $(ignore=$ignore:tt)? $(should_panic=$should_panic:tt)?) => {
105+
(break: name=$name:ident body=[($($params:tt)*) $($item:tt)*] $(ignore=$ignore:tt)? $(should_panic=$should_panic:tt)?) => {
106106
#[allow(non_camel_case_types)]
107107
struct $name;
108108

@@ -123,12 +123,12 @@ macro_rules! _test_parse {
123123
}
124124

125125
fn run(&self, context: &$crate::TestContext) -> $crate::RunResult {
126-
fn run $($item)*
126+
fn run($($params)*) $($item)*
127127

128128
$crate::_private::parse_ignore!(context, $($ignore)?);
129129

130130
use $crate::IntoRunResult;
131-
let result = $crate::_private::run_test!(context, $($should_panic)?);
131+
let result = $crate::_private::run_test!($crate::_private::test_expr!(context, [$($params)*]), $($should_panic)?);
132132
IntoRunResult::into_run_result(result)
133133
}
134134
}
@@ -149,14 +149,25 @@ macro_rules! _parse_ignore {
149149

150150
#[macro_export]
151151
#[doc(hidden)]
152-
macro_rules! _run_test {
153-
($context:expr, [$expected:literal]) => {
154-
$crate::panic::assert_panic_contains(|| run($context), $expected)
155-
};
152+
macro_rules! _test_expr {
156153
($context:expr, []) => {
157-
$crate::panic::assert_panic(|| run($context))
154+
run()
158155
};
159-
($context:expr $(,)?) => {{
156+
($context:expr, [$($params:tt)+]) => {
160157
run($context)
158+
};
159+
}
160+
161+
#[macro_export]
162+
#[doc(hidden)]
163+
macro_rules! _run_test {
164+
($test:expr, [$expected:literal]) => {
165+
$crate::panic::assert_panic_contains(|| $test, $expected)
166+
};
167+
($test:expr, []) => {
168+
$crate::panic::assert_panic(|| $test)
169+
};
170+
($test:expr $(,)?) => {{
171+
$test
161172
}};
162173
}

0 commit comments

Comments
 (0)