about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2025-08-02 13:07:01 +1000
committerZalathar <Zalathar@users.noreply.github.com>2025-08-03 13:47:40 +1000
commit1063b0f09010ffae99b6a3b55bec5539876ce57e (patch)
tree5994ed95bd8d285861253dfc971fcc633a1f8138 /src
parentd1d44d44f15f32ea4c53abc2dbb35bd8304e582e (diff)
Change `TestCx::error` to `error_prefix`, which returns a string
This reduces the amount of "hidden" printing in error-reporting code, which
will be helpful when overhauling compiletest's error handling and output
capture.
Diffstat (limited to 'src')
-rw-r--r--src/tools/compiletest/src/runtest.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index b1f8e461aef..35670ba89e9 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -603,7 +603,10 @@ impl<'test> TestCx<'test> {
             );
         } else {
             for pattern in missing_patterns {
-                self.error(&format!("error pattern '{}' not found!", pattern));
+                println!(
+                    "\n{prefix}: error pattern '{pattern}' not found!",
+                    prefix = self.error_prefix()
+                );
             }
             self.fatal_proc_rec("multiple error patterns not found", proc_res);
         }
@@ -821,10 +824,11 @@ impl<'test> TestCx<'test> {
             // - only known line - meh, but suggested
             // - others are not worth suggesting
             if !unexpected.is_empty() {
-                self.error(&format!(
-                    "{} diagnostics reported in JSON output but not expected in test file",
-                    unexpected.len(),
-                ));
+                println!(
+                    "\n{prefix}: {n} diagnostics reported in JSON output but not expected in test file",
+                    prefix = self.error_prefix(),
+                    n = unexpected.len(),
+                );
                 for error in &unexpected {
                     print_error(error);
                     let mut suggestions = Vec::new();
@@ -854,10 +858,11 @@ impl<'test> TestCx<'test> {
                 }
             }
             if !not_found.is_empty() {
-                self.error(&format!(
-                    "{} diagnostics expected in test file but not reported in JSON output",
-                    not_found.len()
-                ));
+                println!(
+                    "\n{prefix}: {n} diagnostics expected in test file but not reported in JSON output",
+                    prefix = self.error_prefix(),
+                    n = not_found.len(),
+                );
                 for error in &not_found {
                     print_error(error);
                     let mut suggestions = Vec::new();
@@ -1992,16 +1997,19 @@ impl<'test> TestCx<'test> {
         output_base_name(self.config, self.testpaths, self.safe_revision())
     }
 
-    fn error(&self, err: &str) {
+    /// Prefix to print before error messages. Normally just `error`, but also
+    /// includes the revision name for tests that use revisions.
+    #[must_use]
+    fn error_prefix(&self) -> String {
         match self.revision {
-            Some(rev) => println!("\nerror in revision `{}`: {}", rev, err),
-            None => println!("\nerror: {}", err),
+            Some(rev) => format!("error in revision `{rev}`"),
+            None => format!("error"),
         }
     }
 
     #[track_caller]
     fn fatal(&self, err: &str) -> ! {
-        self.error(err);
+        println!("\n{prefix}: {err}", prefix = self.error_prefix());
         error!("fatal error, panic: {:?}", err);
         panic!("fatal error");
     }
@@ -2019,7 +2027,7 @@ impl<'test> TestCx<'test> {
         proc_res: &ProcRes,
         callback_before_unwind: impl FnOnce(),
     ) -> ! {
-        self.error(err);
+        println!("\n{prefix}: {err}", prefix = self.error_prefix());
 
         // Some callers want to print additional notes after the main error message.
         if let Some(note) = extra_note {