Skip to content

Commit

Permalink
Merge pull request #41 from alexcrichton/on-thread-on-wasm
Browse files Browse the repository at this point in the history
Default to single-threaded tests for WebAssembly
  • Loading branch information
LukasKalbertodt authored May 10, 2024
2 parents 30dba02 + 5de2e1e commit cc56e00
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ pub fn run(args: &Arguments, mut tests: Vec<Trial>) -> Conclusion {

// Execute all tests.
let test_mode = !args.bench;
if args.test_threads == Some(1) {
if platform_defaults_to_one_thread() || args.test_threads == Some(1) {
// Run test sequentially in main thread
for test in tests {
// Print `test foo ...`, run the test, then print the outcome in
Expand Down Expand Up @@ -537,6 +537,13 @@ pub fn run(args: &Arguments, mut tests: Vec<Trial>) -> Conclusion {
conclusion
}

/// Returns whether the current host platform should use a single thread by
/// default rather than a thread pool by default. Some platforms, such as
/// WebAssembly, don't have native support for threading at this time.
fn platform_defaults_to_one_thread() -> bool {
cfg!(target_family = "wasm")
}

/// Runs the given runner, catching any panics and treating them as a failed test.
fn run_single(runner: Box<dyn FnOnce(bool) -> Outcome + Send>, test_mode: bool) -> Outcome {
use std::panic::{catch_unwind, AssertUnwindSafe};
Expand Down

0 comments on commit cc56e00

Please sign in to comment.