Pre-RFC: Provide ignore message when the test ignored

There may be meta value as a reason for ignoring attributes on a test case. the-ignore-attribute

#[test]
#[ignore = "not yet implemented"]
fn test_ignored() {
    // …
}

It is good to show the reason if exist on the result of cargo test.

running 2 tests
test tests::test_ignored ... ignored, *not yet implemented*
test tests::test_works ... ok

test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s

Possible solution

  1. Modify the test description structure to store the reason for ignoring,

pub ignore: Option<Option<String>>

Following value for the different use case

  • Some(None) - ignored without specific reason
  • Some(Some(reason)) - ignored with specific reason
  • None - not ignored
  1. Update the reason when parsing the header of test, and parsing the meta value in parse_cfg_name_directive
ParsedNameDirective::Match(Some(meta_value)) => Some(Some(meta_value)),
ParsedNameDirective::Match(None) => Some(None),
  1. Print the ignoring message
TestResult::TrIgnored => test.ignore.take().map(| reason | format!("ignored, {}", reason)).or("ignoted".to_string()),

Known issues

The internal ignore flag is used in serval places, for example, the test case with different target will make the ignore flag true as the original design, it may be Some(None) for that scenario. Only the reason that user-specified will store as Some(Some("reason".to_string()).

Related issues

By the way, the crate will utilize this feature to help users easily to know why the test case ignored

This is the first post for me here, if there is something I need to change, please kindly tell me thanks.

12 Likes

This thread is likely of interest since it is adjacent. It is about runtime detection of such things rather than build-time detection (which I presume this is doing).

Yes, the runtime solution is better, and there is some voice to make it in the test framework. https://github.com/rust-lang/rust/issues/68007

The build-time solution may be easier and solve the problem quickly. I think it is nice in CI flow to see the reason for ignoring a test case no matter the solution is build-time or runtime.

How can I make this happen? If someone knows the working flow, please kindly help me. Many thanks.

As prior art, it might be worth mentioning the analogous feature on JUnit.

1 Like

JUnit added into prior art section

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.