Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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