From f8ee9f018c53c7555c07a035ff2efaad9723adc9 Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 7 Oct 2025 18:26:36 +0800 Subject: [PATCH] Print tip for human error format when check fail --- src/tools/compiletest/src/runtest.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index bd32bec383fa3..e9dea95cafbdc 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -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 ¬_found { print_error(error); let mut suggestions = Vec::new();