Don't fail subsequent tests if one panics

This commit is contained in:
khyperia 2020-10-30 15:27:18 +01:00
parent 2a19fc1cb7
commit 5a7aabe836

View File

@ -5,7 +5,7 @@ use lazy_static::lazy_static;
use rustc_codegen_spirv::rspirv; use rustc_codegen_spirv::rspirv;
use std::error::Error; use std::error::Error;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Mutex; use std::sync::{Mutex, MutexGuard};
// https://github.com/colin-kiegel/rust-pretty-assertions/issues/24 // https://github.com/colin-kiegel/rust-pretty-assertions/issues/24
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@ -25,6 +25,14 @@ lazy_static! {
static ref GLOBAL_MUTEX: Mutex<()> = Mutex::new(()); static ref GLOBAL_MUTEX: Mutex<()> = Mutex::new(());
} }
fn global_lock() -> MutexGuard<'static, ()> {
match GLOBAL_MUTEX.lock() {
Ok(guard) => guard,
// we don't care about poison - a previous test may have paniced, but that's okay
Err(poisoned) => poisoned.into_inner(),
}
}
static CARGO_TOML: &str = r#"[package] static CARGO_TOML: &str = r#"[package]
name = "test-project" name = "test-project"
version = "0.1.0" version = "0.1.0"
@ -80,7 +88,7 @@ fn read_module(path: &Path) -> Result<rspirv::dr::Module, Box<dyn Error>> {
} }
fn val(src: &str) { fn val(src: &str) {
let _lock = GLOBAL_MUTEX.lock().unwrap(); let _lock = global_lock();
// spirv-val is included in building // spirv-val is included in building
build(src); build(src);
} }
@ -102,7 +110,7 @@ fn assert_str_eq(expected: &str, result: &str) {
} }
fn dis_fn(src: &str, func: &str, expect: &str) { fn dis_fn(src: &str, func: &str, expect: &str) {
let _lock = GLOBAL_MUTEX.lock().unwrap(); let _lock = global_lock();
let module = read_module(&build(src)).unwrap(); let module = read_module(&build(src)).unwrap();
let id = module let id = module
.debugs .debugs