Skip to content

Commit 04fa4eb

Browse files
authored
Merge pull request #894 from EnergySystemsModellingLab/ci-test-tweaks
Tweaks to regression tests to make CI debugging easier
2 parents 179db46 + 4a9a9e3 commit 04fa4eb

2 files changed

Lines changed: 37 additions & 12 deletions

File tree

.github/workflows/cargo-test.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v5
2323
- uses: actions-rust-lang/setup-rust-toolchain@v1
24-
- run: cargo test --verbose
24+
- name: Run cargo test
25+
shell: bash
26+
env:
27+
MUSE2_TEST_OUTPUT_DIR: test_results
28+
run: |
29+
mkdir $MUSE2_TEST_OUTPUT_DIR
30+
cargo test --verbose --no-fail-fast
31+
32+
# Upload regression test results for analysis
33+
- uses: actions/upload-artifact@v4
34+
if: "!cancelled()"
35+
with:
36+
name: muse2_test_results_${{ matrix.os }}
37+
path: test_results
2538

2639
- if: ${{ matrix.coverage }}
2740
uses: ./.github/actions/codecov

tests/regression.rs

Lines changed: 23 additions & 11 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,31 +28,42 @@ 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,
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

Comments
 (0)