Skip to content

Commit

Permalink
Rollup merge of rust-lang#106769 - lenko-d:libtest-print_why_a_test_w…
Browse files Browse the repository at this point in the history
…as_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 [rust-lang#106659](rust-lang#106659)
Needed by [106763](rust-lang#106763)
  • Loading branch information
matthiaskrgr authored Jan 29, 2023
2 parents 94809b3 + 7713337 commit 192eecd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion library/test/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct ConsoleTestState {
pub metrics: MetricMap,
pub 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 options: Options,
}
Expand All @@ -76,6 +77,7 @@ impl ConsoleTestState {
metrics: MetricMap::new(),
failures: Vec::new(),
not_failures: Vec::new(),
ignores: Vec::new(),
time_failures: Vec::new(),
options: opts.options,
})
Expand Down Expand Up @@ -194,7 +196,10 @@ fn handle_test_result(st: &mut ConsoleTestState, completed_test: CompletedTest)
st.passed += 1;
st.not_failures.push((test, stdout));
}
TestResult::TrIgnored => st.ignored += 1,
TestResult::TrIgnored => {
st.ignored += 1;
st.ignores.push((test, stdout));
}
TestResult::TrBench(bs) => {
st.metrics.insert_metric(
test.name.as_slice(),
Expand Down
9 changes: 9 additions & 0 deletions library/test/src/formatters/terse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {

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)
}
}
1 change: 1 addition & 0 deletions library/test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ fn should_sort_failures_before_printing_them() {
failures: vec![(test_b, Vec::new()), (test_a, Vec::new())],
options: Options::new(),
not_failures: Vec::new(),
ignores: Vec::new(),
time_failures: Vec::new(),
};

Expand Down

0 comments on commit 192eecd

Please sign in to comment.