Repository: denoland/deno
Pull request: fix(test): ignore write errors in reporter

Fixes #20377.

Changed files:
filename: cli/tools/test/mod.rs
patch: @@ -347,28 +347,28 @@ impl TestFailure {
       }
       TestFailure::Leaked(details, trailer_notes) => {
         let mut f = String::new();
-        write!(f, "Leaks detected:").unwrap();
+        write!(f, "Leaks detected:").ok();
         for detail in details {
-          write!(f, "\n  - {}", detail).unwrap();
+          write!(f, "\n  - {}", detail).ok();
         }
         for trailer in trailer_notes {
-          write!(f, "\n{}", trailer).unwrap();
+          write!(f, "\n{}", trailer).ok();
         }
         Cow::Owned(f)
       }
       TestFailure::OverlapsWithSanitizers(long_names) => {
         let mut f = String::new();
-        write!(f, "Started test step while another test step with sanitizers was running:").unwrap();
+        write!(f, "Started test step while another test step with sanitizers was running:").ok();
         for long_name in long_names {
-          write!(f, "\n  * {}", long_name).unwrap();
+          write!(f, "\n  * {}", long_name).ok();
         }
         Cow::Owned(f)
       }
       TestFailure::HasSanitizersAndOverlaps(long_names) => {
         let mut f = String::new();
-        write!(f, "Started test step with sanitizers while another test step was running:").unwrap();
+        write!(f, "Started test step with sanitizers while another test step was running:").ok();
         for long_name in long_names {
-          write!(f, "\n  * {}", long_name).unwrap();
+          write!(f, "\n  * {}", long_name).ok();
         }
         Cow::Owned(f)
       }

filename: cli/tools/test/reporters/common.rs
patch: @@ -93,11 +93,11 @@ pub(super) fn report_sigint(
     "\n{} The following tests were pending:\n",
     colors::intense_blue("SIGINT")
   )
-  .unwrap();
+  .ok();
   for entry in formatted_pending {
-    writeln!(writer, "{}", entry).unwrap();
+    writeln!(writer, "{}", entry).ok();
   }
-  writeln!(writer).unwrap();
+  writeln!(writer).ok();
 }
 
 pub(super) fn report_summary(
@@ -131,20 +131,20 @@ pub(super) fn report_summary(
     }
 
     // note: the trailing whitespace is intentional to get a red background
-    writeln!(writer, "\n{}\n", colors::white_bold_on_red(" ERRORS ")).unwrap();
+    writeln!(writer, "\n{}\n", colors::white_bold_on_red(" ERRORS ")).ok();
     for (origin, (failures, uncaught_error)) in failures_by_origin {
       for (description, failure) in failures {
         if !failure.hide_in_summary() {
           let failure_title = format_test_for_summary(cwd, description);
-          writeln!(writer, "{}", &failure_title).unwrap();
+          writeln!(writer, "{}", &failure_title).ok();
           writeln!(
             writer,
             "{}: {}",
             colors::red_bold("error"),
             failure.format(options)
           )
-          .unwrap();
-          writeln!(writer).unwrap();
+          .ok();
+          writeln!(writer).ok();
           failure_titles.push(failure_title);
         }
       }
@@ -153,24 +153,24 @@ pub(super) fn report_summary(
           "{} (uncaught error)",
           to_relative_path_or_remote_url(cwd, &origin)
         );
-        writeln!(writer, "{}", &failure_title).unwrap();
+        writeln!(writer, "{}", &failure_title).ok();
         writeln!(
           writer,
           "{}: {}",
           colors::red_bold("error"),
           format_test_error(js_error, options)
         )
-        .unwrap();
-        writeln!(writer, "This error was not caught from a test and caused the test runner to fail on the referenced module.").unwrap();
-        writeln!(writer, "It most likely originated from a dangling promise, event/timeout handler or top-level code.").unwrap();
-        writeln!(writer).unwrap();
+        .ok();
+        writeln!(writer, "This error was not caught from a test and caused the test runner to fail on the referenced module.").ok();
+        writeln!(writer, "It most likely originated from a dangling promise, event/timeout handler or top-level code.").ok();
+        writeln!(writer).ok();
         failure_titles.push(failure_title);
       }
     }
     // note: the trailing whitespace is intentional to get a red background
-    writeln!(writer, "{}\n", colors::white_bold_on_red(" FAILURES ")).unwrap();
+    writeln!(writer, "{}\n", colors::white_bold_on_red(" FAILURES ")).ok();
     for failure_title in failure_titles {
-      writeln!(writer, "{failure_title}").unwrap();
+      writeln!(writer, "{failure_title}").ok();
     }
   }
 
@@ -200,7 +200,7 @@ pub(super) fn report_summary(
     summary.failed,
     get_steps_text(summary.failed_steps),
   )
-  .unwrap();
+  .ok();
 
   let ignored_steps = get_steps_text(summary.ignored_steps);
   if summary.ignored > 0 || !ignored_steps.is_empty() {
@@ -209,15 +209,15 @@ pub(super) fn report_summary(
       " | {} ignored{}",
       summary.ignored, ignored_steps
     )
-    .unwrap()
+    .ok();
   }
 
   if summary.measured > 0 {
-    write!(summary_result, " | {} measured", summary.measured,).unwrap();
+    write!(summary_result, " | {} measured", summary.measured,).ok();
   }
 
   if summary.filtered_out > 0 {
-    write!(summary_result, " | {} filtered out", summary.filtered_out).unwrap()
+    write!(summary_result, " | {} filtered out", summary.filtered_out).ok();
   };
 
   writeln!(
@@ -227,5 +227,5 @@ pub(super) fn report_summary(
     summary_result,
     colors::gray(format!("({})", display::human_elapsed(elapsed.as_millis()))),
   )
-  .unwrap();
+  .ok();
 }

filename: cli/tools/test/reporters/dot.rs
patch: @@ -97,7 +97,7 @@ impl TestReporter for DotTestReporter {
 
   fn report_wait(&mut self, _description: &TestDescription) {
     // flush for faster feedback when line buffered
-    std::io::stdout().flush().unwrap();
+    std::io::stdout().flush().ok();
   }
 
   fn report_slow(&mut self, _description: &TestDescription, _elapsed: u64) {}
@@ -149,7 +149,7 @@ impl TestReporter for DotTestReporter {
 
   fn report_step_wait(&mut self, _description: &TestStepDescription) {
     // flush for faster feedback when line buffered
-    std::io::stdout().flush().unwrap();
+    std::io::stdout().flush().ok();
   }
 
   fn report_step_result(

filename: cli/tools/test/reporters/pretty.rs
patch: @@ -57,7 +57,7 @@ impl PrettyTestReporter {
 
   fn force_report_wait(&mut self, description: &TestDescription) {
     if !self.in_new_line {
-      writeln!(&mut self.writer).unwrap();
+      writeln!(&mut self.writer).ok();
     }
     if self.parallel {
       write!(
@@ -68,30 +68,30 @@ impl PrettyTestReporter {
           to_relative_path_or_remote_url(&self.cwd, &description.origin)
         ))
       )
-      .unwrap();
+      .ok();
     }
-    write!(&mut self.writer, "{} ...", description.name).unwrap();
+    write!(&mut self.writer, "{} ...", description.name).ok();
     self.in_new_line = false;
     // flush for faster feedback when line buffered
-    std::io::stdout().flush().unwrap();
+    std::io::stdout().flush().ok();
     self.scope_test_id = Some(description.id);
   }
 
   fn force_report_step_wait(&mut self, description: &TestStepDescription) {
     self.write_output_end();
     if !self.in_new_line {
-      writeln!(&mut self.writer).unwrap();
+      writeln!(&mut self.writer).ok();
     }
     write!(
       &mut self.writer,
       "{}{} ...",
       "  ".repeat(description.level),
       description.name
     )
-    .unwrap();
+    .ok();
     self.in_new_line = false;
     // flush for faster feedback when line buffered
-    std::io::stdout().flush().unwrap();
+    std::io::stdout().flush().ok();
     self.scope_test_id = Some(description.id);
   }
 
@@ -124,10 +124,10 @@ impl PrettyTestReporter {
       TestStepResult::Ignored => colors::yellow("ignored").to_string(),
       TestStepResult::Failed(failure) => failure.format_label(),
     };
-    write!(&mut self.writer, " {}", status).unwrap();
+    write!(&mut self.writer, " {}", status).ok();
     if let TestStepResult::Failed(failure) = result {
       if let Some(inline_summary) = failure.format_inline_summary() {
-        write!(&mut self.writer, " ({})", inline_summary).unwrap()
+        write!(&mut self.writer, " ({})", inline_summary).ok();
       }
     }
     if !matches!(result, TestStepResult::Failed(TestFailure::Incomplete)) {
@@ -136,9 +136,9 @@ impl PrettyTestReporter {
         " {}",
         colors::gray(format!("({})", display::human_elapsed(elapsed.into())))
       )
-      .unwrap();
+      .ok();
     }
-    writeln!(&mut self.writer).unwrap();
+    writeln!(&mut self.writer).ok();
     self.in_new_line = true;
     if self.parallel {
       self.scope_test_id = None;
@@ -159,7 +159,7 @@ impl PrettyTestReporter {
         "{}",
         colors::gray(format!("----- {}output end -----", self.phase))
       )
-      .unwrap();
+      .ok();
       self.in_new_line = true;
       self.did_have_user_output = false;
     }
@@ -189,7 +189,7 @@ impl TestReporter for PrettyTestReporter {
         to_relative_path_or_remote_url(&self.cwd, &plan.origin)
       ))
     )
-    .unwrap();
+    .ok();
     self.in_new_line = true;
   }
 
@@ -210,7 +210,7 @@ impl TestReporter for PrettyTestReporter {
         colors::gray(format!("({})", display::human_elapsed(elapsed.into()))),
       ))
     )
-    .unwrap();
+    .ok();
   }
   fn report_output(&mut self, output: &[u8]) {
     if !self.echo_output {
@@ -220,7 +220,7 @@ impl TestReporter for PrettyTestReporter {
     if !self.did_have_user_output {
       self.did_have_user_output = true;
       if !self.in_new_line {
-        writeln!(&mut self.writer).unwrap();
+        writeln!(&mut self.writer).ok();
       }
       self.phase = if !self.started_tests {
         "pre-test "
@@ -234,13 +234,13 @@ impl TestReporter for PrettyTestReporter {
         "{}",
         colors::gray(format!("------- {}output -------", self.phase))
       )
-      .unwrap();
+      .ok();
       self.in_new_line = true;
     }
 
     // output everything to stdout in order to prevent
     // stdout and stderr racing
-    std::io::stdout().write_all(output).unwrap();
+    std::io::stdout().write_all(output).ok();
   }
 
   fn report_result(
@@ -283,18 +283,18 @@ impl TestReporter for PrettyTestReporter {
       TestResult::Failed(failure) => failure.format_label(),
       TestResult::Cancelled => colors::gray("cancelled").to_string(),
     };
-    write!(&mut self.writer, " {}", status).unwrap();
+    write!(&mut self.writer, " {}", status).ok();
     if let TestResult::Failed(failure) = result {
       if let Some(inline_summary) = failure.format_inline_summary() {
-        write!(&mut self.writer, " ({})", inline_summary).unwrap();
+        write!(&mut self.writer, " ({})", inline_summary).ok();
       }
     }
     writeln!(
       &mut self.writer,
       " {}",
       colors::gray(format!("({})", display::human_elapsed(elapsed.into())))
     )
-    .unwrap();
+    .ok();
     self.in_new_line = true;
     self.scope_test_id = None;
   }
@@ -307,15 +307,15 @@ impl TestReporter for PrettyTestReporter {
       .push((origin.to_string(), error));
 
     if !self.in_new_line {
-      writeln!(&mut self.writer).unwrap();
+      writeln!(&mut self.writer).ok();
     }
     writeln!(
       &mut self.writer,
       "Uncaught error from {} {}",
       to_relative_path_or_remote_url(&self.cwd, origin),
       colors::red("FAILED")
     )
-    .unwrap();
+    .ok();
     self.in_new_line = true;
     self.did_have_user_output = false;
   }
@@ -368,7 +368,7 @@ impl TestReporter for PrettyTestReporter {
         )),
         common::format_test_step_ancestry(desc, tests, test_steps)
       )
-      .unwrap();
+      .ok();
       self.in_new_line = false;
       self.scope_test_id = Some(desc.id);
       self.force_report_step_result(desc, result, elapsed);
@@ -406,7 +406,7 @@ impl TestReporter for PrettyTestReporter {
       &self.failure_format_options,
     );
     if !self.repl {
-      writeln!(&mut self.writer).unwrap();
+      writeln!(&mut self.writer).ok();
     }
     self.in_new_line = true;
   }
@@ -438,7 +438,7 @@ impl TestReporter for PrettyTestReporter {
     _tests: &IndexMap<usize, TestDescription>,
     _test_steps: &IndexMap<usize, TestStepDescription>,
   ) -> anyhow::Result<()> {
-    self.writer.flush().unwrap();
+    self.writer.flush().ok();
     Ok(())
   }
 }

filename: cli/tools/test/reporters/tap.rs
patch: @@ -144,7 +144,7 @@ impl TestReporter for TapTestReporter {
 
   fn report_wait(&mut self, _description: &TestDescription) {
     // flush for faster feedback when line buffered
-    std::io::stdout().flush().unwrap();
+    std::io::stdout().flush().ok();
   }
 
   fn report_slow(&mut self, _description: &TestDescription, _elapsed: u64) {}
@@ -195,7 +195,7 @@ impl TestReporter for TapTestReporter {
 
   fn report_step_wait(&mut self, _description: &TestStepDescription) {
     // flush for faster feedback when line buffered
-    std::io::stdout().flush().unwrap();
+    std::io::stdout().flush().ok();
   }
 
   fn report_step_result(