Skip to content

Commit 192eecd

Browse files
authored
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](#106659) Needed by [106763](#106763)
2 parents 94809b3 + 7713337 commit 192eecd

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

library/test/src/console.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct ConsoleTestState {
5353
pub metrics: MetricMap,
5454
pub failures: Vec<(TestDesc, Vec<u8>)>,
5555
pub not_failures: Vec<(TestDesc, Vec<u8>)>,
56+
pub ignores: Vec<(TestDesc, Vec<u8>)>,
5657
pub time_failures: Vec<(TestDesc, Vec<u8>)>,
5758
pub options: Options,
5859
}
@@ -76,6 +77,7 @@ impl ConsoleTestState {
7677
metrics: MetricMap::new(),
7778
failures: Vec::new(),
7879
not_failures: Vec::new(),
80+
ignores: Vec::new(),
7981
time_failures: Vec::new(),
8082
options: opts.options,
8183
})
@@ -194,7 +196,10 @@ fn handle_test_result(st: &mut ConsoleTestState, completed_test: CompletedTest)
194196
st.passed += 1;
195197
st.not_failures.push((test, stdout));
196198
}
197-
TestResult::TrIgnored => st.ignored += 1,
199+
TestResult::TrIgnored => {
200+
st.ignored += 1;
201+
st.ignores.push((test, stdout));
202+
}
198203
TestResult::TrBench(bs) => {
199204
st.metrics.insert_metric(
200205
test.name.as_slice(),

library/test/src/formatters/terse.rs

+9
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
254254

255255
self.write_plain("\n\n")?;
256256

257+
// Custom handling of cases where there is only 1 test to execute and that test was ignored.
258+
// We want to show more detailed information(why was the test ignored) for investigation purposes.
259+
if self.total_test_count == 1 && state.ignores.len() == 1 {
260+
let test_desc = &state.ignores[0].0;
261+
if let Some(im) = test_desc.ignore_message {
262+
self.write_plain(format!("test: {}, ignore_message: {}\n\n", test_desc.name, im))?;
263+
}
264+
}
265+
257266
Ok(success)
258267
}
259268
}

library/test/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ fn should_sort_failures_before_printing_them() {
790790
failures: vec![(test_b, Vec::new()), (test_a, Vec::new())],
791791
options: Options::new(),
792792
not_failures: Vec::new(),
793+
ignores: Vec::new(),
793794
time_failures: Vec::new(),
794795
};
795796

0 commit comments

Comments
 (0)