Skip to content

Commit 33becac

Browse files
committed
feat: Add #[ignore] macro
1 parent be5d3fc commit 33becac

File tree

3 files changed

+206
-78
lines changed

3 files changed

+206
-78
lines changed

crates/libtest2/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub mod _private {
4444
pub use libtest2_harness::TestKind;
4545

4646
pub use crate::_main_parse as main_parse;
47+
pub use crate::_parse_ignore as parse_ignore;
4748
pub use crate::_test_parse as test_parse;
4849
pub use crate::case::DynCase;
4950
}

crates/libtest2/src/macros.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@ macro_rules! _main_parse {
1212
};
1313
}
1414

15+
#[macro_export]
16+
macro_rules! _parse_ignore {
17+
(ignore) => {
18+
::std::option::Option::<&'static str>::None
19+
};
20+
(ignore = $reason:expr) => {
21+
::std::option::Option::<&'static str>::Some($reason)
22+
};
23+
($($attr:tt)*) => {
24+
compile_error!(concat!("unknown attribute '", stringify!($($attr)*), "'"));
25+
};
26+
}
27+
1528
#[macro_export]
1629
#[allow(clippy::crate_in_macro_def)] // accessing item defined by `_main_parse`
1730
macro_rules! _test_parse {
18-
(#[test] fn $name:ident $($item:tt)*) => {
31+
(#[test] $(#[$($attr:tt)*])* fn $name:ident $($item:tt)*) => {
1932
#[allow(non_camel_case_types)]
2033
struct $name;
2134

@@ -38,6 +51,13 @@ macro_rules! _test_parse {
3851
fn run(&self, context: &$crate::TestContext) -> $crate::RunResult {
3952
fn run $($item)*
4053

54+
$(
55+
match $crate::_private::parse_ignore!($($attr)*) {
56+
::std::option::Option::None => context.ignore()?,
57+
::std::option::Option::Some(reason) => context.ignore_for(reason)?,
58+
}
59+
)*
60+
4161
run(context)
4262
}
4363
}

0 commit comments

Comments
 (0)