Skip to content

Commit 4baa65d

Browse files
committed
Allow user to set output dir for regression tests via env var
1 parent 179db46 commit 4baa65d

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

tests/regression.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use itertools::Itertools;
44
use muse2::cli::RunOpts;
55
use muse2::cli::example::handle_example_run_command;
66
use muse2::settings::Settings;
7+
use std::env;
78
use std::fs::{File, read_dir};
89
use std::io::{BufRead, BufReader};
910
use std::path::{Path, PathBuf};
10-
use tempfile::tempdir;
11+
use tempfile::{TempDir, tempdir};
1112

1213
const FLOAT_CMP_TOLERANCE: f64 = 1e-10;
1314

@@ -27,19 +28,27 @@ pub fn run_regression_test_with_debug_files(example_name: &str) {
2728
}
2829

2930
fn run_regression_test_debug_opt(example_name: &str, debug_model: bool) {
30-
unsafe { std::env::set_var("MUSE2_LOG_LEVEL", "off") };
31+
unsafe { env::set_var("MUSE2_LOG_LEVEL", "off") };
32+
33+
// Allow user to set output dir for regression tests so they can examine results. This is
34+
// principally intended for use by CI.
35+
let tmp: TempDir;
36+
let output_dir = if let Ok(dir) = env::var("MUSE2_TEST_OUTPUT_DIR") {
37+
[&dir, example_name].iter().collect()
38+
} else {
39+
tmp = tempdir().unwrap();
40+
tmp.path().to_path_buf()
41+
};
3142

32-
let tempdir = tempdir().unwrap();
3343
let opts = RunOpts {
34-
output_dir: Some(tempdir.path().to_path_buf()),
44+
output_dir: Some(output_dir.clone()),
3545
overwrite: false,
3646
debug_model,
3747
};
38-
let output_dir = tempdir.path();
3948
handle_example_run_command(example_name, &opts, Some(Settings::default())).unwrap();
4049

4150
let test_data_dir = PathBuf::from(format!("tests/data/{example_name}"));
42-
compare_output_dirs(output_dir, &test_data_dir);
51+
compare_output_dirs(&output_dir, &test_data_dir);
4352
}
4453

4554
fn compare_output_dirs(output_dir1: &Path, output_dir2: &Path) {

0 commit comments

Comments
 (0)