Skip to content

Commit e74dc0f

Browse files
committed
feat: Add #[ignore] macro
1 parent 7c8630a commit e74dc0f

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
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
}

crates/libtest2/tests/testsuite/mixed_bag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ fn fly(context: &libtest2::TestContext) -> libtest2::RunResult {
5050
}
5151
5252
#[libtest2::test]
53+
#[ignore = "fails"]
5354
fn bear(context: &libtest2::TestContext) -> libtest2::RunResult {
54-
context.ignore_for("fails")?;
5555
Err(libtest2::RunError::fail("no honey"))
5656
}
5757
5858
#[libtest2::test]
59+
#[ignore]
5960
fn sheep(context: &libtest2::TestContext) -> libtest2::RunResult {
60-
context.ignore()?;
6161
Err(libtest2::RunError::fail("got lost blindly following the flock"))
6262
}
6363
6464
#[libtest2::test]
65+
#[ignore = "slow"]
6566
fn horse(context: &libtest2::TestContext) -> libtest2::RunResult {
66-
context.ignore_for("slow")?;
6767
Ok(())
6868
}
6969
"#,

0 commit comments

Comments
 (0)