From 5a7aabe836b8f07cb6c0fa767d0a484bb1f970e2 Mon Sep 17 00:00:00 2001 From: khyperia Date: Fri, 30 Oct 2020 15:27:18 +0100 Subject: [PATCH] Don't fail subsequent tests if one panics --- spirv-builder/src/test/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spirv-builder/src/test/mod.rs b/spirv-builder/src/test/mod.rs index 2554cccf9c..8c04d6ea0e 100644 --- a/spirv-builder/src/test/mod.rs +++ b/spirv-builder/src/test/mod.rs @@ -5,7 +5,7 @@ use lazy_static::lazy_static; use rustc_codegen_spirv::rspirv; use std::error::Error; use std::path::{Path, PathBuf}; -use std::sync::Mutex; +use std::sync::{Mutex, MutexGuard}; // https://github.com/colin-kiegel/rust-pretty-assertions/issues/24 #[derive(PartialEq, Eq)] @@ -25,6 +25,14 @@ lazy_static! { 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] name = "test-project" version = "0.1.0" @@ -80,7 +88,7 @@ fn read_module(path: &Path) -> Result> { } fn val(src: &str) { - let _lock = GLOBAL_MUTEX.lock().unwrap(); + let _lock = global_lock(); // spirv-val is included in building build(src); } @@ -102,7 +110,7 @@ fn assert_str_eq(expected: &str, result: &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 id = module .debugs