Skip to content

Commit 4044358

Browse files
authored
Merge pull request #1307 from EnergySystemsModellingLab/debug-test-output
Generate debug output for all regression tests
2 parents 18ceb6f + b00af32 commit 4044358

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

tests/cli.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,14 @@ fn check_example_extract_command(#[case] patch: bool) {
109109
);
110110
}
111111

112-
// NB: `example run` is covered by regression tests
112+
/// Test the `example run` command with no additional flags
113+
#[test]
114+
fn check_example_run_command() {
115+
let tmp = tempdir().unwrap();
116+
let output_dir = tmp.path().join("out");
117+
let output_dir_str = output_dir.to_string_lossy();
118+
119+
assert_muse2_runs(&["example", "run", "simple", "--output-dir", &output_dir_str]);
120+
}
121+
122+
// NB: `example run` extra flags are covered by regression tests

tests/common.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ macro_rules! define_regression_test_with_extra_args {
2929
($example:ident, $extra_args:expr) => {
3030
#[test]
3131
fn $example() {
32-
run_regression_test(stringify!($example), $extra_args);
32+
run_regression_test(stringify!($example), $extra_args, false);
33+
}
34+
};
35+
($example:ident, $extra_args:expr, $debug_model:expr) => {
36+
#[test]
37+
fn $example() {
38+
run_regression_test(stringify!($example), $extra_args, $debug_model);
3339
}
3440
};
3541
}
@@ -50,7 +56,7 @@ pub(crate) use define_regression_test;
5056
#[allow(unused_macros)]
5157
macro_rules! define_regression_test_with_debug_files {
5258
($example:ident) => {
53-
define_regression_test_with_extra_args!($example, &["--debug-model"]);
59+
define_regression_test_with_extra_args!($example, &[], true);
5460
};
5561
}
5662
#[allow(unused_imports)]

tests/regression.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ define_regression_test_with_patches!(simple_ironing_out);
3737
/// The tolerance when comparing floating-point values in CSV files
3838
const FLOAT_CMP_TOLERANCE: f64 = 1e-10;
3939

40-
/// Run a regression test for the given example with optional extra arguments to `muse2 run`.
41-
fn run_regression_test(example: &str, extra_args: &[&str]) {
40+
/// Run a regression test for the given example with optional extra arguments to `muse2 example run`.
41+
///
42+
/// The `--debug-model` flag is always used so the debug files are available to examine. The debug
43+
/// files are only tested when the `debug_model` parameter is true.
44+
fn run_regression_test(example: &str, extra_args: &[&str], debug_model: bool) {
4245
// Allow user to set output dir for regression tests so they can examine results. This is
4346
// principally intended for use by CI.
4447
let tmp: TempDir;
@@ -51,17 +54,20 @@ fn run_regression_test(example: &str, extra_args: &[&str]) {
5154

5255
// Invoke muse2
5356
let output_dir_str = output_dir.to_string_lossy();
54-
let mut args = vec!["example", "run", example, "--output-dir", &output_dir_str];
57+
let mut args = vec![
58+
"example",
59+
"run",
60+
example,
61+
"--debug-model",
62+
"--output-dir",
63+
&output_dir_str,
64+
];
5565
args.extend(extra_args);
5666
assert_muse2_runs(&args);
5767

5868
// Check that the output files match (approximately)
5969
let test_data_dir = PathBuf::from(format!("tests/data/{example}"));
60-
compare_output_dirs(
61-
&output_dir,
62-
&test_data_dir,
63-
extra_args.contains(&"--debug-model"),
64-
);
70+
compare_output_dirs(&output_dir, &test_data_dir, debug_model);
6571
}
6672

6773
fn compare_output_dirs(cur_output_dir1: &Path, test_data_dir: &Path, debug_model: bool) {

0 commit comments

Comments
 (0)