]> git.lizzy.rs Git - rust.git/commitdiff
Add a dedicated thread for output printing
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 18 Jul 2022 09:02:40 +0000 (09:02 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 21 Jul 2022 07:35:49 +0000 (07:35 +0000)
ui_test/src/lib.rs

index 4318e8a8e034d4bd1920997b3f49bcff048ea576..ee20920e54ffd4323bdc3232e2e49962adcffea9 100644 (file)
@@ -123,11 +123,22 @@ pub fn run_tests(mut config: Config) -> Result<()> {
             drop(submit);
         });
 
             drop(submit);
         });
 
+        // A channel for the messages emitted by the individual test threads.
+        let (finish_file, finished_files) = crossbeam::channel::unbounded();
+
+        s.spawn(|_| {
+            for msg in finished_files {
+                eprintln!("{msg}");
+            }
+        });
+
         let mut threads = vec![];
 
         // Create N worker threads that receive files to test.
         for _ in 0..std::thread::available_parallelism().unwrap().get() {
         let mut threads = vec![];
 
         // Create N worker threads that receive files to test.
         for _ in 0..std::thread::available_parallelism().unwrap().get() {
+            let finish_file = finish_file.clone();
             threads.push(s.spawn(|_| -> Result<()> {
             threads.push(s.spawn(|_| -> Result<()> {
+                let finish_file = finish_file;
                 for path in &receive {
                     if !config.path_filter.is_empty() {
                         let path_display = path.display().to_string();
                 for path in &receive {
                     if !config.path_filter.is_empty() {
                         let path_display = path.display().to_string();
@@ -140,11 +151,12 @@ pub fn run_tests(mut config: Config) -> Result<()> {
                     // Ignore file if only/ignore rules do (not) apply
                     if !test_file_conditions(&comments, &target, &config) {
                         ignored.fetch_add(1, Ordering::Relaxed);
                     // Ignore file if only/ignore rules do (not) apply
                     if !test_file_conditions(&comments, &target, &config) {
                         ignored.fetch_add(1, Ordering::Relaxed);
-                        eprintln!(
+                        let msg = format!(
                             "{} ... {}",
                             path.display(),
                             "ignored (in-test comment)".yellow()
                         );
                             "{} ... {}",
                             path.display(),
                             "ignored (in-test comment)".yellow()
                         );
+                        finish_file.send(msg)?;
                         continue;
                     }
                     // Run the test for all revisions
                         continue;
                     }
                     // Run the test for all revisions
@@ -161,10 +173,10 @@ pub fn run_tests(mut config: Config) -> Result<()> {
                         }
                         write!(msg, "... ").unwrap();
                         if errors.is_empty() {
                         }
                         write!(msg, "... ").unwrap();
                         if errors.is_empty() {
-                            eprintln!("{msg}{}", "ok".green());
+                            write!(msg, "{}", "ok".green()).unwrap();
                             succeeded.fetch_add(1, Ordering::Relaxed);
                         } else {
                             succeeded.fetch_add(1, Ordering::Relaxed);
                         } else {
-                            eprintln!("{msg}{}", "FAILED".red().bold());
+                            write!(msg, "{}", "FAILED".red().bold()).unwrap();
                             failures.lock().unwrap().push((
                                 path.clone(),
                                 m,
                             failures.lock().unwrap().push((
                                 path.clone(),
                                 m,
@@ -173,11 +185,13 @@ pub fn run_tests(mut config: Config) -> Result<()> {
                                 stderr,
                             ));
                         }
                                 stderr,
                             ));
                         }
+                        finish_file.send(msg)?;
                     }
                 }
                 Ok(())
             }));
         }
                     }
                 }
                 Ok(())
             }));
         }
+
         for thread in threads {
             thread.join().unwrap()?;
         }
         for thread in threads {
             thread.join().unwrap()?;
         }