]> git.lizzy.rs Git - rust.git/blobdiff - src/libtest/formatters/pretty.rs
Rollup merge of #68342 - lcnr:type_name_docs, r=Dylan-DPC
[rust.git] / src / libtest / formatters / pretty.rs
index 2935b4c99cec42c68f76e5c1c0acc1cd6a1f3d58..4a93e084df178d8182ec03bf4c111d7e47e3654b 100644 (file)
@@ -1,9 +1,18 @@
-use super::*;
+use std::{io, io::prelude::Write};
+
+use super::OutputFormatter;
+use crate::{
+    bench::fmt_bench_samples,
+    console::{ConsoleTestState, OutputLocation},
+    test_result::TestResult,
+    time,
+    types::TestDesc,
+};
 
 pub(crate) struct PrettyFormatter<T> {
     out: OutputLocation<T>,
     use_color: bool,
-    time_options: Option<TestTimeOptions>,
+    time_options: Option<time::TestTimeOptions>,
 
     /// Number of columns to fill when aligning names
     max_name_len: usize,
@@ -17,15 +26,9 @@ pub fn new(
         use_color: bool,
         max_name_len: usize,
         is_multithreaded: bool,
-        time_options: Option<TestTimeOptions>,
+        time_options: Option<time::TestTimeOptions>,
     ) -> Self {
-        PrettyFormatter {
-            out,
-            use_color,
-            max_name_len,
-            is_multithreaded,
-            time_options
-        }
+        PrettyFormatter { out, use_color, max_name_len, is_multithreaded, time_options }
     }
 
     #[cfg(test)]
@@ -67,7 +70,7 @@ pub fn write_short_result(
 
     pub fn write_pretty(&mut self, word: &str, color: term::color::Color) -> io::Result<()> {
         match self.out {
-            Pretty(ref mut term) => {
+            OutputLocation::Pretty(ref mut term) => {
                 if self.use_color {
                     term.fg(color)?;
                 }
@@ -77,7 +80,7 @@ pub fn write_pretty(&mut self, word: &str, color: term::color::Color) -> io::Res
                 }
                 term.flush()
             }
-            Raw(ref mut stdout) => {
+            OutputLocation::Raw(ref mut stdout) => {
                 stdout.write_all(word.as_bytes())?;
                 stdout.flush()
             }
@@ -93,7 +96,7 @@ pub fn write_plain<S: AsRef<str>>(&mut self, s: S) -> io::Result<()> {
     fn write_time(
         &mut self,
         desc: &TestDesc,
-        exec_time: Option<&TestExecTime>
+        exec_time: Option<&time::TestExecTime>,
     ) -> io::Result<()> {
         if let (Some(opts), Some(time)) = (self.time_options, exec_time) {
             let time_str = format!(" <{}>", time);
@@ -112,7 +115,7 @@ fn write_time(
 
             match color {
                 Some(color) => self.write_pretty(&time_str, color)?,
-                None => self.write_plain(&time_str)?
+                None => self.write_plain(&time_str)?,
             }
         }
 
@@ -122,7 +125,7 @@ fn write_time(
     fn write_results(
         &mut self,
         inputs: &Vec<(TestDesc, Vec<u8>)>,
-        results_type: &str
+        results_type: &str,
     ) -> io::Result<()> {
         let results_out_str = format!("\n{}:\n", results_type);
 
@@ -194,7 +197,7 @@ fn write_result(
         &mut self,
         desc: &TestDesc,
         result: &TestResult,
-        exec_time: Option<&TestExecTime>,
+        exec_time: Option<&time::TestExecTime>,
         _: &[u8],
         _: &ConsoleTestState,
     ) -> io::Result<()> {
@@ -203,15 +206,15 @@ fn write_result(
         }
 
         match *result {
-            TrOk => self.write_ok()?,
-            TrFailed | TrFailedMsg(_) => self.write_failed()?,
-            TrIgnored => self.write_ignored()?,
-            TrAllowedFail => self.write_allowed_fail()?,
-            TrBench(ref bs) => {
+            TestResult::TrOk => self.write_ok()?,
+            TestResult::TrFailed | TestResult::TrFailedMsg(_) => self.write_failed()?,
+            TestResult::TrIgnored => self.write_ignored()?,
+            TestResult::TrAllowedFail => self.write_allowed_fail()?,
+            TestResult::TrBench(ref bs) => {
                 self.write_bench()?;
                 self.write_plain(&format!(": {}", fmt_bench_samples(bs)))?;
             }
-            TrTimedFail => self.write_time_failed()?,
+            TestResult::TrTimedFail => self.write_time_failed()?,
         }
 
         self.write_time(desc, exec_time)?;
@@ -225,7 +228,8 @@ fn write_timeout(&mut self, desc: &TestDesc) -> io::Result<()> {
 
         self.write_plain(&format!(
             "test {} has been running for over {} seconds\n",
-            desc.name, TEST_WARN_TIMEOUT_S
+            desc.name,
+            time::TEST_WARN_TIMEOUT_S
         ))
     }