@@ -4,10 +4,11 @@ use itertools::Itertools;
44use muse2:: cli:: RunOpts ;
55use muse2:: cli:: example:: handle_example_run_command;
66use muse2:: settings:: Settings ;
7+ use std:: env;
78use std:: fs:: { File , read_dir} ;
89use std:: io:: { BufRead , BufReader } ;
910use std:: path:: { Path , PathBuf } ;
10- use tempfile:: tempdir;
11+ use tempfile:: { TempDir , tempdir} ;
1112
1213const FLOAT_CMP_TOLERANCE : f64 = 1e-10 ;
1314
@@ -27,31 +28,42 @@ pub fn run_regression_test_with_debug_files(example_name: &str) {
2728}
2829
2930fn 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 ,
36- debug_model,
46+ debug_model : true , // NB: Always enable this as it helps to have the files for debugging
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, debug_model ) ;
4352}
4453
45- fn compare_output_dirs ( output_dir1 : & Path , output_dir2 : & Path ) {
46- let file_names1 = get_csv_file_names ( output_dir1) ;
47- let file_names2 = get_csv_file_names ( output_dir2) ;
54+ fn compare_output_dirs ( cur_output_dir1 : & Path , test_data_dir : & Path , debug_model : bool ) {
55+ let mut file_names1 = get_csv_file_names ( cur_output_dir1) ;
56+ if !debug_model {
57+ file_names1. retain ( |name| !name. starts_with ( "debug_" ) ) ;
58+ }
59+ let file_names2 = get_csv_file_names ( test_data_dir) ;
4860
4961 // Check that output files haven't been added/removed
5062 assert ! ( file_names1 == file_names2) ;
5163
5264 let mut errors = Vec :: new ( ) ;
5365 for file_name in file_names1 {
54- compare_lines ( output_dir1 , output_dir2 , & file_name, & mut errors) ;
66+ compare_lines ( cur_output_dir1 , test_data_dir , & file_name, & mut errors) ;
5567 }
5668
5769 assert ! (
0 commit comments