diff options
| author | Brian Anderson <banderson@mozilla.com> | 2016-09-06 20:16:56 +0000 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2016-09-30 14:02:46 -0700 |
| commit | f41b363ea315509040a20e59acae97955dc8e601 (patch) | |
| tree | d9a6305d212ad8d15a3f1a881f9dddf4fe2318a4 /src/libtest | |
| parent | b8b50f0eda08e19e7c96377681f82ac17c76775d (diff) | |
| download | rust-f41b363ea315509040a20e59acae97955dc8e601.tar.gz rust-f41b363ea315509040a20e59acae97955dc8e601.zip | |
Update libtest for single-threaded emscripten support
Diffstat (limited to 'src/libtest')
| -rw-r--r-- | src/libtest/lib.rs | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 12dd8e615e8..49a7f6589d2 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1182,26 +1182,63 @@ pub fn run_test(opts: &TestOpts, } } - thread::spawn(move || { - let data = Arc::new(Mutex::new(Vec::new())); - let data2 = data.clone(); - let cfg = thread::Builder::new().name(match desc.name { - DynTestName(ref name) => name.clone(), - StaticTestName(name) => name.to_owned(), + // If the platform is single-threaded we're just going to run + // the test synchronously, regardless of the concurrency + // level. + let supports_threads = !cfg!(target_os = "emscripten"); + + // Buffer for capturing standard I/O + let data = Arc::new(Mutex::new(Vec::new())); + let data2 = data.clone(); + + if supports_threads { + thread::spawn(move || { + let cfg = thread::Builder::new().name(match desc.name { + DynTestName(ref name) => name.clone(), + StaticTestName(name) => name.to_owned(), + }); + + let result_guard = cfg.spawn(move || { + if !nocapture { + io::set_print(box Sink(data2.clone())); + io::set_panic(box Sink(data2)); + } + testfn() + }) + .unwrap(); + let test_result = calc_result(&desc, result_guard.join()); + let stdout = data.lock().unwrap().to_vec(); + monitor_ch.send((desc.clone(), test_result, stdout)).unwrap(); }); + } else { + let oldio = if !nocapture { + Some(( + io::set_print(box Sink(data2.clone())), + io::set_panic(box Sink(data2)) + )) + } else { + None + }; + + use std::panic::{catch_unwind, AssertUnwindSafe}; - let result_guard = cfg.spawn(move || { - if !nocapture { - io::set_print(box Sink(data2.clone())); - io::set_panic(box Sink(data2)); - } - testfn() - }) - .unwrap(); - let test_result = calc_result(&desc, result_guard.join()); + let result = catch_unwind(AssertUnwindSafe(|| { + testfn() + })); + + if let Some((printio, panicio)) = oldio { + if let Some(printio) = printio { + io::set_print(printio); + } + if let Some(panicio) = panicio { + io::set_panic(panicio); + } + }; + + let test_result = calc_result(&desc, result); let stdout = data.lock().unwrap().to_vec(); monitor_ch.send((desc.clone(), test_result, stdout)).unwrap(); - }); + } } match testfn { |
