Stabilize joinir tests and env guards

This commit is contained in:
2025-12-27 17:41:30 +09:00
parent 88ead0df9f
commit 0d6229d5a2
28 changed files with 444 additions and 127 deletions

View File

@ -599,6 +599,7 @@ mod tests {
use super::*;
use std::fs;
use std::path::PathBuf;
use std::sync::{Mutex, OnceLock};
fn temp_path(name: &str) -> PathBuf {
let mut p = std::env::temp_dir();
@ -606,12 +607,18 @@ mod tests {
p
}
fn env_guard() -> &'static Mutex<()> {
static GUARD: OnceLock<Mutex<()>> = OnceLock::new();
GUARD.get_or_init(|| Mutex::new(()))
}
fn dummy_module() -> MirModule {
MirModule::new("test-module".to_string())
}
#[test]
fn writes_file_when_dump_path_is_set() {
let _lock = env_guard().lock().unwrap();
let path = temp_path("mir_dump_path");
let _ = fs::remove_file(&path);
std::env::set_var("RUST_MIR_DUMP_PATH", path.to_string_lossy().to_string());
@ -634,6 +641,7 @@ mod tests {
#[test]
fn does_not_write_when_dump_path_is_unset() {
let _lock = env_guard().lock().unwrap();
std::env::remove_var("RUST_MIR_DUMP_PATH");
let path = temp_path("mir_dump_path_unset");
let _ = fs::remove_file(&path);