Skip to content

Commit

Permalink
use an enum instead of bool
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 11, 2018
1 parent 741ba1f commit c28c287
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ mod formatters;

use formatters::{JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter};

/// Whether to execute tests concurrently or not
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Concurrent { Yes, No }

// The name of a test. By convention this follows the rules for rust
// paths; i.e. it should be a series of identifiers separated by double
// colons. This way if some test runner wants to arrange the tests
Expand Down Expand Up @@ -1150,7 +1154,7 @@ where
while !remaining.is_empty() {
let test = remaining.pop().unwrap();
callback(TeWait(test.desc.clone()))?;
run_test(opts, !opts.run_tests, test, tx.clone(), /*concurrency*/false);
run_test(opts, !opts.run_tests, test, tx.clone(), Concurrent::No);
let (test, result, stdout) = rx.recv().unwrap();
callback(TeResult(test, result, stdout))?;
}
Expand All @@ -1161,7 +1165,7 @@ where
let timeout = Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S);
running_tests.insert(test.desc.clone(), timeout);
callback(TeWait(test.desc.clone()))?; //here no pad
run_test(opts, !opts.run_tests, test, tx.clone(), /*concurrency*/true);
run_test(opts, !opts.run_tests, test, tx.clone(), Concurrent::Yes);
pending += 1;
}

Expand Down Expand Up @@ -1193,7 +1197,7 @@ where
// All benchmarks run at the end, in serial.
for b in filtered_benchs {
callback(TeWait(b.desc.clone()))?;
run_test(opts, false, b, tx.clone(), /*concurrency*/true);
run_test(opts, false, b, tx.clone(), Concurrent::No);
let (test, result, stdout) = rx.recv().unwrap();
callback(TeResult(test, result, stdout))?;
}
Expand Down Expand Up @@ -1395,7 +1399,7 @@ pub fn run_test(
force_ignore: bool,
test: TestDescAndFn,
monitor_ch: Sender<MonitorMsg>,
concurrency: bool,
concurrency: Concurrent,
) {
let TestDescAndFn { desc, testfn } = test;

Expand All @@ -1412,7 +1416,7 @@ pub fn run_test(
monitor_ch: Sender<MonitorMsg>,
nocapture: bool,
testfn: Box<dyn FnBox() + Send>,
concurrency: bool,
concurrency: Concurrent,
) {
// Buffer for capturing standard I/O
let data = Arc::new(Mutex::new(Vec::new()));
Expand Down Expand Up @@ -1447,7 +1451,7 @@ pub fn run_test(
// the test synchronously, regardless of the concurrency
// level.
let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_arch = "wasm32");
if concurrency && supports_threads {
if concurrency == Concurrent::Yes && supports_threads {
let cfg = thread::Builder::new().name(name.as_slice().to_owned());
cfg.spawn(runtest).unwrap();
} else {
Expand Down Expand Up @@ -1758,6 +1762,7 @@ mod tests {
use std::sync::mpsc::channel;
use bench;
use Bencher;
use Concurrent;


fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
Expand Down Expand Up @@ -1798,7 +1803,7 @@ mod tests {
testfn: DynTestFn(Box::new(f)),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx, /*concurrency*/false);
run_test(&TestOpts::new(), false, desc, tx, Concurrent::No);
let (_, res, _) = rx.recv().unwrap();
assert!(res != TrOk);
}
Expand All @@ -1816,7 +1821,7 @@ mod tests {
testfn: DynTestFn(Box::new(f)),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx, /*concurrency*/false);
run_test(&TestOpts::new(), false, desc, tx, Concurrent::No);
let (_, res, _) = rx.recv().unwrap();
assert!(res == TrIgnored);
}
Expand All @@ -1836,7 +1841,7 @@ mod tests {
testfn: DynTestFn(Box::new(f)),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx, /*concurrency*/false);
run_test(&TestOpts::new(), false, desc, tx, Concurrent::No);
let (_, res, _) = rx.recv().unwrap();
assert!(res == TrOk);
}
Expand All @@ -1856,7 +1861,7 @@ mod tests {
testfn: DynTestFn(Box::new(f)),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx, /*concurrency*/false);
run_test(&TestOpts::new(), false, desc, tx, Concurrent::No);
let (_, res, _) = rx.recv().unwrap();
assert!(res == TrOk);
}
Expand All @@ -1878,7 +1883,7 @@ mod tests {
testfn: DynTestFn(Box::new(f)),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx, /*concurrency*/false);
run_test(&TestOpts::new(), false, desc, tx, Concurrent::No);
let (_, res, _) = rx.recv().unwrap();
assert!(res == TrFailedMsg(format!("{} '{}'", failed_msg, expected)));
}
Expand All @@ -1896,7 +1901,7 @@ mod tests {
testfn: DynTestFn(Box::new(f)),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx, /*concurrency*/false);
run_test(&TestOpts::new(), false, desc, tx, Concurrent::No);
let (_, res, _) = rx.recv().unwrap();
assert!(res == TrFailed);
}
Expand Down

0 comments on commit c28c287

Please sign in to comment.