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
Modify the test description structure to store the reason for ignoring,
#[derive(Clone, Debug)]
pub struct TestDesc {
pub name: TestName,
pub ignore: bool,
pub should_panic: options::ShouldPanic,
pub allow_fail: bool,
pub compile_fail: bool,
pub no_run: bool,
pub test_type: TestType,
}
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
Update the reason when parsing the header of test, and parsing the meta value in parse_cfg_name_directive
ignore = match config.parse_cfg_name_directive(ln, "ignore") {
ParsedNameDirective::Match => true,
ParsedNameDirective::NoMatch => ignore,
};
ParsedNameDirective::Match(Some(meta_value)) => Some(Some(meta_value)),
ParsedNameDirective::Match(None) => Some(None),
Print the ignoring message
self.write_log(|| {
format!(
"{} {}",
match *result {
TestResult::TrOk => "ok".to_owned(),
TestResult::TrFailed => "failed".to_owned(),
TestResult::TrFailedMsg(ref msg) => format!("failed: {}", msg),
TestResult::TrIgnored => "ignored".to_owned(),
TestResult::TrAllowedFail => "failed (allowed)".to_owned(),
TestResult::TrBench(ref bs) => fmt_bench_samples(bs),
TestResult::TrTimedFail => "failed (time limit exceeded)".to_owned(),
},
test.name,
)
})?;
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
rust-lang:master
← yanganto:ignore-test-message
opened 09:00AM - 07 Jan 22 UTC
This RFC proposes to add ignore message into the summary as a result of `cargo t… est`.
```
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
```
[Rendered](https://github.com/yanganto/rfcs/blob/ignore-test-message/text/0000-ignore-test-message.md)
[Previous discussion on IRLO](https://internals.rust-lang.org/t/pre-rfc-provide-ignore-message-when-the-test-ignored/15904)
system
Closed
April 10, 2022, 1:49am
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.