Skip to content

Commit 5a7aabe

Browse files
committed
Don't fail subsequent tests if one panics
1 parent 2a19fc1 commit 5a7aabe

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spirv-builder/src/test/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use lazy_static::lazy_static;
55
use rustc_codegen_spirv::rspirv;
66
use std::error::Error;
77
use std::path::{Path, PathBuf};
8-
use std::sync::Mutex;
8+
use std::sync::{Mutex, MutexGuard};
99

1010
// https://github.com/colin-kiegel/rust-pretty-assertions/issues/24
1111
#[derive(PartialEq, Eq)]
@@ -25,6 +25,14 @@ lazy_static! {
2525
static ref GLOBAL_MUTEX: Mutex<()> = Mutex::new(());
2626
}
2727

28+
fn global_lock() -> MutexGuard<'static, ()> {
29+
match GLOBAL_MUTEX.lock() {
30+
Ok(guard) => guard,
31+
// we don't care about poison - a previous test may have paniced, but that's okay
32+
Err(poisoned) => poisoned.into_inner(),
33+
}
34+
}
35+
2836
static CARGO_TOML: &str = r#"[package]
2937
name = "test-project"
3038
version = "0.1.0"
@@ -80,7 +88,7 @@ fn read_module(path: &Path) -> Result<rspirv::dr::Module, Box<dyn Error>> {
8088
}
8189

8290
fn val(src: &str) {
83-
let _lock = GLOBAL_MUTEX.lock().unwrap();
91+
let _lock = global_lock();
8492
// spirv-val is included in building
8593
build(src);
8694
}
@@ -102,7 +110,7 @@ fn assert_str_eq(expected: &str, result: &str) {
102110
}
103111

104112
fn dis_fn(src: &str, func: &str, expect: &str) {
105-
let _lock = GLOBAL_MUTEX.lock().unwrap();
113+
let _lock = global_lock();
106114
let module = read_module(&build(src)).unwrap();
107115
let id = module
108116
.debugs

0 commit comments

Comments
 (0)