Forráskód Böngészése

chore(test): minor loom fixups

Signed-off-by: Eliza Weisman <[email protected]>
Eliza Weisman 3 éve
szülő
commit
7a2beae342
2 módosított fájl, 15 hozzáadás és 3 törlés
  1. 3 0
      bin/loom
  2. 12 3
      src/loom.rs

+ 3 - 0
bin/loom

@@ -7,4 +7,7 @@ LOOM_LOG="${LOOM_LOG:-info}" \
 LOOM_MAX_PREEMPTIONS="${LOOM_MAX_PREEMPTIONS:-2}" \
 cargo test \
     --profile loom \
+    # All loom tests are lib tests; don't run integration or doctests
+    # (they can be run with the normal `cargo test` command).
+    --lib \
     "$@"

+ 12 - 3
src/loom.rs

@@ -39,12 +39,12 @@ mod inner {
         use std::{
             env, io,
             sync::{
-                atomic::{AtomicUsize, Ordering},
+                atomic::{AtomicBool, AtomicUsize, Ordering},
                 Once,
             },
         };
         use tracing_subscriber::{filter::Targets, fmt, prelude::*};
-
+        static IS_NOCAPTURE: AtomicBool = AtomicBool::new(false);
         static SETUP_TRACE: Once = Once::new();
 
         SETUP_TRACE.call_once(|| {
@@ -83,6 +83,10 @@ mod inner {
                 .with(filter)
                 .init();
 
+            if std::env::args().any(|arg| arg == "--nocapture") {
+                IS_NOCAPTURE.store(true, Ordering::Relaxed);
+            }
+
             let default_hook = std::panic::take_hook();
             std::panic::set_hook(Box::new(move |panic| {
                 // try to print the trace buffer.
@@ -122,7 +126,12 @@ mod inner {
             // next iteration...
             TRACE_BUF.with(|buf| buf.borrow_mut().clear());
         });
-        print!("({} iterations) ", iteration.load(Ordering::Relaxed));
+
+        // Only print iterations on test completion in nocapture mode; otherwise
+        // they'll just get all mangled.
+        if IS_NOCAPTURE.load(Ordering::Relaxed) {
+            print!("({} iterations) ", iteration.load(Ordering::Relaxed));
+        }
     }
 
     #[track_caller]