Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@ fn check_example_extract_command(#[case] patch: bool) {
);
}

// NB: `example run` is covered by regression tests
/// Test the `example run` command with no additional flags
#[test]
fn check_example_run_command() {
assert_muse2_runs(&[
"example",
"run",
"simple",
"--output-dir",
&tempdir().unwrap().path().to_path_buf().to_string_lossy(),
Comment on lines +99 to +104
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do this for clarity, regardless of the point about relying on brittle lifetime rules ☝️

]);
}

// NB: `example run` extra flags are covered by regression tests
10 changes: 8 additions & 2 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ macro_rules! define_regression_test_with_extra_args {
($example:ident, $extra_args:expr) => {
#[test]
fn $example() {
run_regression_test(stringify!($example), $extra_args);
run_regression_test(stringify!($example), $extra_args, false);
}
};
($example:ident, $extra_args:expr, $debug_model:literal) => {
#[test]
fn $example() {
run_regression_test(stringify!($example), $extra_args, $debug_model);
}
};
Comment on lines +35 to 40
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

}
Expand All @@ -50,7 +56,7 @@ pub(crate) use define_regression_test;
#[allow(unused_macros)]
macro_rules! define_regression_test_with_debug_files {
($example:ident) => {
define_regression_test_with_extra_args!($example, &["--debug-model"]);
define_regression_test_with_extra_args!($example, &[], true);
};
}
#[allow(unused_imports)]
Expand Down
20 changes: 13 additions & 7 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ define_regression_test_with_patches!(simple_ironing_out);
const FLOAT_CMP_TOLERANCE: f64 = 1e-10;

/// Run a regression test for the given example with optional extra arguments to `muse2 run`.
fn run_regression_test(example: &str, extra_args: &[&str]) {
///
/// The `debug-model` flag is always used so the debug files are available to examine. The debug
/// files are only tested when the `debug_model` flag is true.
fn run_regression_test(example: &str, extra_args: &[&str], debug_model: bool) {
Comment on lines 40 to +44
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also true. Worth fixing up

// Allow user to set output dir for regression tests so they can examine results. This is
// principally intended for use by CI.
let tmp: TempDir;
Expand All @@ -51,17 +54,20 @@ fn run_regression_test(example: &str, extra_args: &[&str]) {

// Invoke muse2
let output_dir_str = output_dir.to_string_lossy();
let mut args = vec!["example", "run", example, "--output-dir", &output_dir_str];
let mut args = vec![
"example",
"run",
example,
"--debug-model",
"--output-dir",
&output_dir_str,
];
args.extend(extra_args);
assert_muse2_runs(&args);

// Check that the output files match (approximately)
let test_data_dir = PathBuf::from(format!("tests/data/{example}"));
compare_output_dirs(
&output_dir,
&test_data_dir,
extra_args.contains(&"--debug-model"),
);
compare_output_dirs(&output_dir, &test_data_dir, debug_model);
}

fn compare_output_dirs(cur_output_dir1: &Path, test_data_dir: &Path, debug_model: bool) {
Expand Down
Loading