Rollup merge of #106769 - lenko-d:libtest-print_why_a_test_was_ignored_if_its_the_only_test_specified, r=Mark-Simulacrum

libtest: Print why a test was ignored if it's the only test specified.

Fixes [#106659](https://github.com/rust-lang/rust/issues/106659)
Needed by [106763](https://github.com/rust-lang/rust/pull/106763)
This commit is contained in:
Matthias Krüger 2023-01-29 20:03:36 +01:00 committed by GitHub
commit 192eecd53a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -53,6 +53,7 @@ pub struct ConsoleTestState {
pub metrics: MetricMap, pub metrics: MetricMap,
pub failures: Vec<(TestDesc, Vec<u8>)>, pub failures: Vec<(TestDesc, Vec<u8>)>,
pub not_failures: Vec<(TestDesc, Vec<u8>)>, pub not_failures: Vec<(TestDesc, Vec<u8>)>,
pub ignores: Vec<(TestDesc, Vec<u8>)>,
pub time_failures: Vec<(TestDesc, Vec<u8>)>, pub time_failures: Vec<(TestDesc, Vec<u8>)>,
pub options: Options, pub options: Options,
} }
@ -76,6 +77,7 @@ impl ConsoleTestState {
metrics: MetricMap::new(), metrics: MetricMap::new(),
failures: Vec::new(), failures: Vec::new(),
not_failures: Vec::new(), not_failures: Vec::new(),
ignores: Vec::new(),
time_failures: Vec::new(), time_failures: Vec::new(),
options: opts.options, options: opts.options,
}) })
@ -194,7 +196,10 @@ fn handle_test_result(st: &mut ConsoleTestState, completed_test: CompletedTest)
st.passed += 1; st.passed += 1;
st.not_failures.push((test, stdout)); st.not_failures.push((test, stdout));
} }
TestResult::TrIgnored => st.ignored += 1, TestResult::TrIgnored => {
st.ignored += 1;
st.ignores.push((test, stdout));
}
TestResult::TrBench(bs) => { TestResult::TrBench(bs) => {
st.metrics.insert_metric( st.metrics.insert_metric(
test.name.as_slice(), test.name.as_slice(),

View File

@ -254,6 +254,15 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
self.write_plain("\n\n")?; self.write_plain("\n\n")?;
// Custom handling of cases where there is only 1 test to execute and that test was ignored.
// We want to show more detailed information(why was the test ignored) for investigation purposes.
if self.total_test_count == 1 && state.ignores.len() == 1 {
let test_desc = &state.ignores[0].0;
if let Some(im) = test_desc.ignore_message {
self.write_plain(format!("test: {}, ignore_message: {}\n\n", test_desc.name, im))?;
}
}
Ok(success) Ok(success)
} }
} }

View File

@ -790,6 +790,7 @@ fn should_sort_failures_before_printing_them() {
failures: vec![(test_b, Vec::new()), (test_a, Vec::new())], failures: vec![(test_b, Vec::new()), (test_a, Vec::new())],
options: Options::new(), options: Options::new(),
not_failures: Vec::new(), not_failures: Vec::new(),
ignores: Vec::new(),
time_failures: Vec::new(), time_failures: Vec::new(),
}; };