Update libtest for single-threaded emscripten support
This commit is contained in:
parent
b8b50f0eda
commit
f41b363ea3
@ -1182,26 +1182,63 @@ fn flush(&mut self) -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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());
|
||||
// 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 = 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user