Rollup merge of #147429 - chenyukang:yukang-fix-test-tip, r=fmease

Print tip for human error format in runtest

When working on https://github.com/rust-lang/rust/pull/147354, spent some time to figure out that there is `//~ ERROR` left on test file, this PR will give a better error message for this scenario.
This commit is contained in:
Matthias Krüger 2025-10-07 17:42:13 +02:00 committed by GitHub
commit 2d353c35e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -878,6 +878,21 @@ impl<'test> TestCx<'test> {
prefix = self.error_prefix(),
n = not_found.len(),
);
// FIXME: Ideally, we should check this at the place where we actually parse error annotations.
// it's better to use (negated) heuristic inside normalize_output if possible
if let Some(human_format) = self.props.compile_flags.iter().find(|flag| {
// `human`, `human-unicode`, `short` will not generate JSON output
flag.contains("error-format")
&& (flag.contains("short") || flag.contains("human"))
}) {
let msg = format!(
"tests with compile flag `{}` should not have error annotations such as `//~ ERROR`",
human_format
).color(Color::Red);
writeln!(self.stdout, "{}", msg);
}
for error in &not_found {
print_error(error);
let mut suggestions = Vec::new();