diff --git a/Cargo.lock b/Cargo.lock index 21952797..3b3ce3f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,6 +97,21 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" +[[package]] +name = "assert_cmd" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c5bcfa8749ac45dd12cb11055aeeb6b27a3895560d60d71e3c23bf979e60514" +dependencies = [ + "anstyle", + "bstr", + "libc", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "autocfg" version = "1.5.0" @@ -144,6 +159,17 @@ version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +[[package]] +name = "bstr" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + [[package]] name = "built" version = "0.8.0" @@ -353,6 +379,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + [[package]] name = "dirs" version = "6.0.0" @@ -961,6 +993,7 @@ name = "muse2" version = "2.0.0" dependencies = [ "anyhow", + "assert_cmd", "built", "chrono", "clap", @@ -1162,6 +1195,33 @@ dependencies = [ "zerovec", ] +[[package]] +name = "predicates" +version = "3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d19ee57562043d37e82899fade9a22ebab7be9cef5026b07fda9cdd4293573" +dependencies = [ + "anstyle", + "difflib", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727e462b119fe9c93fd0eb1429a5f7647394014cf3c04ab2c0350eeb09095ffa" + +[[package]] +name = "predicates-tree" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72dd2d6d381dfb73a193c7fca536518d7caee39fc8503f74e7dc0be0531b425c" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "prettyplease" version = "0.2.37" @@ -1495,6 +1555,12 @@ dependencies = [ "windows-sys 0.61.0", ] +[[package]] +name = "termtree" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" + [[package]] name = "thiserror" version = "2.0.16" @@ -1650,6 +1716,15 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 71b054de..45bc85b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ edit = "0.1.5" erased-serde = "0.4.9" [dev-dependencies] +assert_cmd = "2.1.2" map-macro = "0.3.0" rstest = {version = "0.26.1", default-features = false, features = ["crate-name"]} yaml-rust2 = {version = "0.11.0", default-features = false} diff --git a/docs/developer_guide/architecture_quickstart.md b/docs/developer_guide/architecture_quickstart.md index ce8ff49a..8f188987 100644 --- a/docs/developer_guide/architecture_quickstart.md +++ b/docs/developer_guide/architecture_quickstart.md @@ -144,12 +144,11 @@ bundled with the MUSE2 executable ([see user guide for more detail][user-guide-e As these are intended as both a kind of documentation and templates, they should ideally be kept as simple as possible. -If you add a new example model, please also add a regression test ([see here for an -example][regression-test-example]). +If you add a new example model, please also add a regression test to [`tests/regression.rs`]. [`examples`]: https://github.com/EnergySystemsModellingLab/MUSE2/blob/main/examples/ [user-guide-example-models]: https://energysystemsmodellinglab.github.io/MUSE2/user_guide.html#example-models -[regression-test-example]: https://github.com/EnergySystemsModellingLab/MUSE2/blob/main/tests/regression_muse1_default.rs +[`tests/regression.rs`]: https://github.com/EnergySystemsModellingLab/MUSE2/blob/main/tests/regression.rs ## Unit types diff --git a/src/cli.rs b/src/cli.rs index d550305f..a5e30b74 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -37,8 +37,8 @@ pub struct RunOpts { #[arg(long)] pub overwrite: bool, /// Whether to write additional information to CSV files - #[arg(long, value_name = "BOOL", num_args = 0..=1, default_missing_value = "true")] - pub debug_model: Option, + #[arg(long)] + pub debug_model: bool, } /// Options for the `graph` command @@ -94,12 +94,10 @@ impl Commands { /// Execute the supplied CLI command fn execute(self) -> Result<()> { match self { - Self::Run { model_dir, opts } => handle_run_command(&model_dir, &opts, None), + Self::Run { model_dir, opts } => handle_run_command(&model_dir, &opts), Self::Example { subcommand } => subcommand.execute(), - Self::Validate { model_dir } => handle_validate_command(&model_dir, None), - Self::SaveGraphs { model_dir, opts } => { - handle_save_graphs_command(&model_dir, &opts, None) - } + Self::Validate { model_dir } => handle_validate_command(&model_dir), + Self::SaveGraphs { model_dir, opts } => handle_save_graphs_command(&model_dir, &opts), Self::Settings { subcommand } => subcommand.execute(), } } @@ -126,21 +124,12 @@ pub fn run_cli() -> Result<()> { } /// Handle the `run` command. -pub fn handle_run_command( - model_path: &Path, - opts: &RunOpts, - settings: Option, -) -> Result<()> { - // Load program settings, if not provided - let mut settings = if let Some(settings) = settings { - settings - } else { - Settings::load().context("Failed to load settings.")? - }; +pub fn handle_run_command(model_path: &Path, opts: &RunOpts) -> Result<()> { + let mut settings = Settings::load_or_default().context("Failed to load settings.")?; // These settings can be overridden by command-line arguments - if let Some(opt) = opts.debug_model { - settings.debug_model = opt; + if opts.debug_model { + settings.debug_model = true; } if opts.overwrite { settings.overwrite = true; @@ -186,13 +175,8 @@ pub fn handle_run_command( } /// Handle the `validate` command. -pub fn handle_validate_command(model_path: &Path, settings: Option) -> Result<()> { - // Load program settings, if not provided - let settings = if let Some(settings) = settings { - settings - } else { - Settings::load().context("Failed to load settings.")? - }; +pub fn handle_validate_command(model_path: &Path) -> Result<()> { + let settings = Settings::load_or_default().context("Failed to load settings.")?; // Initialise program logger (we won't save log files when running the validate command) log::init(&settings.log_level, None).context("Failed to initialise logging.")?; @@ -205,17 +189,8 @@ pub fn handle_validate_command(model_path: &Path, settings: Option) -> } /// Handle the `save-graphs` command. -pub fn handle_save_graphs_command( - model_path: &Path, - opts: &GraphOpts, - settings: Option, -) -> Result<()> { - // Load program settings, if not provided - let mut settings = if let Some(settings) = settings { - settings - } else { - Settings::load().context("Failed to load settings.")? - }; +pub fn handle_save_graphs_command(model_path: &Path, opts: &GraphOpts) -> Result<()> { + let mut settings = Settings::load_or_default().context("Failed to load settings.")?; if opts.overwrite { settings.overwrite = true; diff --git a/src/cli/example.rs b/src/cli/example.rs index 62cb8a6e..a55d89ac 100644 --- a/src/cli/example.rs +++ b/src/cli/example.rs @@ -3,7 +3,6 @@ use super::{RunOpts, handle_run_command}; use crate::example::patches::{get_patch_names, get_patches}; use crate::example::{Example, get_example_names}; use crate::patch::ModelPatch; -use crate::settings::Settings; use anyhow::{Context, Result}; use clap::Subcommand; use std::fs; @@ -59,7 +58,7 @@ impl ExampleSubcommands { new_path, } => handle_example_extract_command(&name, new_path.as_deref(), patch)?, Self::Run { name, patch, opts } => { - handle_example_run_command(&name, patch, &opts, None)?; + handle_example_run_command(&name, patch, &opts)?; } } @@ -127,37 +126,9 @@ fn extract_example(name: &str, patch: bool, dest: &Path) -> Result<()> { } /// Handle the `example run` command. -pub fn handle_example_run_command( - name: &str, - patch: bool, - opts: &RunOpts, - settings: Option, -) -> Result<()> { +pub fn handle_example_run_command(name: &str, patch: bool, opts: &RunOpts) -> Result<()> { let temp_dir = TempDir::new().context("Failed to create temporary directory")?; let model_path = temp_dir.path().join(name); extract_example(name, patch, &model_path)?; - handle_run_command(&model_path, opts, settings) -} - -#[cfg(test)] -mod tests { - use super::*; - use rstest::rstest; - - fn assert_dir_non_empty(path: &Path) { - assert!( - path.read_dir().unwrap().next().is_some(), - "Directory is empty" - ); - } - - #[rstest] - #[case("muse1_default", false)] - #[case("simple_divisible", true)] - fn check_extract_example(#[case] name: &str, #[case] patch: bool) { - let tmp = TempDir::new().unwrap(); - let dest = tmp.path().join("out"); - extract_example(name, patch, &dest).unwrap(); - assert_dir_non_empty(&dest); - } + handle_run_command(&model_path, opts) } diff --git a/src/settings.rs b/src/settings.rs index 55479388..7403a1b3 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -5,6 +5,7 @@ use crate::log::DEFAULT_LOG_LEVEL; use anyhow::Result; use documented::DocumentedFields; use serde::{Deserialize, Serialize}; +use std::env; use std::fmt::Write; use std::path::{Path, PathBuf}; @@ -66,19 +67,25 @@ impl Default for Settings { } impl Settings { - /// Read the contents of a settings file from the model directory. + /// Read the contents of a settings file from the global MUSE2 configuration directory. /// - /// If the file is not present, default settings will be used. + /// If the file is not present or the user has set the `MUSE2_USE_DEFAULT_SETTINGS` environment + /// variable to 1, then the default settings will be used. /// /// # Returns /// /// The program settings as a `Settings` struct or an error if loading fails. - pub fn load() -> Result { - Self::load_from_path(&get_settings_file_path()) + pub fn load_or_default() -> Result { + if env::var("MUSE2_USE_DEFAULT_SETTINGS").is_ok_and(|v| v == "1") { + Ok(Settings::default()) + } else { + Self::from_path_or_default(&get_settings_file_path()) + } } - /// Read from the specified path, returning - fn load_from_path(file_path: &Path) -> Result { + /// Try to read settings from the specified path, returning `Settings::default()` if it doesn't + /// exist + fn from_path_or_default(file_path: &Path) -> Result { if !file_path.is_file() { return Ok(Settings::default()); } @@ -124,17 +131,17 @@ mod tests { use tempfile::tempdir; #[test] - fn settings_load_from_path_no_file() { + fn settings_from_path_or_default_no_file() { let dir = tempdir().unwrap(); let file_path = dir.path().join(SETTINGS_FILE_NAME); // NB: doesn't exist assert_eq!( - Settings::load_from_path(&file_path).unwrap(), + Settings::from_path_or_default(&file_path).unwrap(), Settings::default() ); } #[test] - fn settings_load_from_path() { + fn settings_from_path_or_default() { let dir = tempdir().unwrap(); let file_path = dir.path().join(SETTINGS_FILE_NAME); @@ -144,7 +151,7 @@ mod tests { } assert_eq!( - Settings::load_from_path(&file_path).unwrap(), + Settings::from_path_or_default(&file_path).unwrap(), Settings { log_level: "warn".to_string(), ..Settings::default() diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 00000000..1cae4c26 --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,96 @@ +//! Integration tests for CLI commands. +use rstest::rstest; + +use itertools::Itertools; +use tempfile::tempdir; + +mod common; +use common::{assert_muse2_runs, get_muse2_stdout}; + +const EXAMPLE_NAME: &str = "simple"; +const MODEL_DIR: &str = "examples/simple"; +const PATCH_EXAMPLE_NAME: &str = "simple_divisible"; + +/// Test the `run` command +#[test] +fn check_run_command() { + // Save results to non-existent directory to check that directory creation works + let tempdir = tempdir().unwrap(); + let output_dir = tempdir.path().join("results"); + assert_muse2_runs(&[ + "run", + MODEL_DIR, + "--output-dir", + &output_dir.to_string_lossy(), + ]); +} + +/// Test the `save-graphs` command +#[test] +fn check_save_graphs_command() { + // Save results to non-existent directory to check that directory creation works + let tempdir = tempdir().unwrap(); + let output_dir = tempdir.path().join("graphs"); + assert_muse2_runs(&[ + "save-graphs", + MODEL_DIR, + "--output-dir", + &output_dir.to_string_lossy(), + ]); + + // Check that at least one DOT file was created + assert!(output_dir.join("GBR_2020.dot").exists()); +} + +/// Test the `validate` command +#[test] +fn check_validate_command() { + assert_muse2_runs(&["validate", MODEL_DIR]); +} + +/// Test the `example list` command +#[rstest] +#[case(true)] +#[case(false)] +fn check_example_list_command(#[case] patch: bool) { + let mut args = vec!["example", "list"]; + if patch { + args.push("--patch"); + } + + let stdout = get_muse2_stdout(&args); + let lines = stdout.split('\n').collect_vec(); + assert!(lines.first().is_some_and(|s| !s.is_empty())); + assert!(lines.last().is_some_and(|s| s.is_empty())); +} + +/// Test the `example info` command +#[test] +fn check_example_info_command() { + assert!(!get_muse2_stdout(&["example", "info", EXAMPLE_NAME]).is_empty()); +} + +/// Test the `example extract` +#[rstest] +#[case(true)] +#[case(false)] +fn check_example_extract_command(#[case] patch: bool) { + let tmp = tempdir().unwrap(); + let output_dir = tmp.path().join("out"); + let output_dir_str = output_dir.to_string_lossy(); + let mut args = vec!["example", "extract"]; + if patch { + args.extend(["--patch", PATCH_EXAMPLE_NAME]); + } else { + args.push(EXAMPLE_NAME); + } + args.push(&output_dir_str); + + assert_muse2_runs(&args); + assert!( + output_dir.read_dir().unwrap().next().is_some(), + "Output dir is empty" + ); +} + +// NB: `example run` is covered by regression tests diff --git a/tests/common.rs b/tests/common.rs new file mode 100644 index 00000000..92c535ab --- /dev/null +++ b/tests/common.rs @@ -0,0 +1,67 @@ +use assert_cmd::cargo_bin_cmd; + +macro_rules! muse2_cmd { + ($args:expr) => { + cargo_bin_cmd!("muse2") + .env("MUSE2_USE_DEFAULT_SETTINGS", "1") + .args($args) + }; +} + +pub fn assert_muse2_runs(args: &[&str]) { + muse2_cmd!(args).assert().success(); +} + +#[allow(dead_code)] +#[must_use] +pub fn get_muse2_stdout(args: &[&str]) -> String { + let output = muse2_cmd!(args).output().expect("Failed to run muse2"); + assert!(output.status.success()); + + str::from_utf8(&output.stdout) + .expect("Non-unicode chars in stdout") + .into() +} + +/// Define a regression test with extra command-line arguments +#[allow(unused_macros)] +macro_rules! define_regression_test_with_extra_args { + ($example:ident, $extra_args:expr) => { + #[test] + fn $example() { + run_regression_test(stringify!($example), $extra_args); + } + }; +} +#[allow(unused_imports)] +pub(crate) use define_regression_test_with_extra_args; + +/// Define a regression test for an example model +#[allow(unused_macros)] +macro_rules! define_regression_test { + ($example:ident) => { + define_regression_test_with_extra_args!($example, &[]); + }; +} +#[allow(unused_imports)] +pub(crate) use define_regression_test; + +/// Define a regression test for an example model, including debug output files +#[allow(unused_macros)] +macro_rules! define_regression_test_with_debug_files { + ($example:ident) => { + define_regression_test_with_extra_args!($example, &["--debug-model"]); + }; +} +#[allow(unused_imports)] +pub(crate) use define_regression_test_with_debug_files; + +/// Define a regression test for a patched example +#[allow(unused_macros)] +macro_rules! define_regression_test_with_patches { + ($example:ident) => { + define_regression_test_with_extra_args!($example, &["--patch"]); + }; +} +#[allow(unused_imports)] +pub(crate) use define_regression_test_with_patches; diff --git a/tests/graph.rs b/tests/graph.rs deleted file mode 100644 index 5b34c633..00000000 --- a/tests/graph.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! Integration tests for the `graph` command. -use muse2::cli::{GraphOpts, handle_save_graphs_command}; -use muse2::log::is_logger_initialised; -use muse2::settings::Settings; -use std::path::PathBuf; -use tempfile::tempdir; - -/// Get the path to the example model. -fn get_model_dir() -> PathBuf { - PathBuf::from("examples/simple") -} - -/// An integration test for the `graph` command. -/// -/// We also check that the logger is initialised after it is run. -#[test] -fn handle_graph_command() { - unsafe { std::env::set_var("MUSE2_LOG_LEVEL", "off") }; - - assert!(!is_logger_initialised()); - - // Save results to non-existent directory to check that directory creation works - let tempdir = tempdir().unwrap(); - let output_dir = tempdir.path().join("graphs"); - let opts = GraphOpts { - output_dir: Some(output_dir.clone()), - overwrite: false, - }; - handle_save_graphs_command(&get_model_dir(), &opts, Some(Settings::default())).unwrap(); - assert!(is_logger_initialised()); - - // Check that at least one DOT file was created - assert!(output_dir.join("GBR_2020.dot").exists()); -} diff --git a/tests/regenerate_test_data.sh b/tests/regenerate_test_data.sh index 263ba07b..d44ed265 100755 --- a/tests/regenerate_test_data.sh +++ b/tests/regenerate_test_data.sh @@ -19,14 +19,13 @@ fi run_example() { example=$1 - debug=$2 - shift 2 # allow for passing extra args + shift 1 # allow for passing extra args echo Generating data for example: $example - env MUSE2_LOG_LEVEL=error \ + env MUSE2_LOG_LEVEL=error MUSE2_USE_DEFAULT_SETTINGS=1 \ cargo -q run example run -o "data/$example" "$example" \ - --overwrite --debug-model=$debug $@ + --overwrite $@ } for example in $examples; do @@ -36,14 +35,14 @@ for example in $examples; do fi # We only need debug files for the simple model - debug=false + unset extra_args if [ "$example" = simple ]; then - debug=true + extra_args=--debug-model fi - run_example "$example" $debug + run_example "$example" $extra_args done for example in $patch_examples; do - run_example "$example" false --patch + run_example "$example" --patch done diff --git a/tests/regression.rs b/tests/regression.rs index 38f45302..8658b3df 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -2,81 +2,59 @@ use anyhow::Result; use float_cmp::approx_eq; use itertools::Itertools; -use muse2::cli::RunOpts; -use muse2::cli::example::handle_example_run_command; -use muse2::cli::handle_run_command; -use muse2::example::patches::get_patches; -use muse2::patch::ModelPatch; -use muse2::settings::Settings; use std::env; use std::fs::{File, read_dir}; use std::io::{BufRead, BufReader}; use std::path::{Path, PathBuf}; use tempfile::{TempDir, tempdir}; -const FLOAT_CMP_TOLERANCE: f64 = 1e-10; +mod common; +use common::*; -// The two functions below give spurious warnings about being unused because of the multiple `mod -// regression` declarations in different test files, so we suppress the warnings manually +// ------ BEGIN: regression tests ------ -/// Run a regression test for an example model -#[allow(dead_code)] -pub fn run_regression_test(example_name: &str) { - run_regression_test_common(example_name, false, |opts, settings| { - handle_example_run_command(example_name, false, opts, settings) - }); -} +// We only check the debug files for the `simple` example at present +define_regression_test_with_debug_files!(simple); -/// Run a regression test for an example model -#[allow(dead_code)] -pub fn run_regression_test_with_debug_files(example_name: &str) { - run_regression_test_common(example_name, true, |opts, settings| { - handle_example_run_command(example_name, false, opts, settings) - }); -} +// Other example models +define_regression_test!(missing_commodity); +define_regression_test!(muse1_default); +define_regression_test!(two_outputs); +define_regression_test!(two_regions); -/// Run a regression test for an example model with file patches applied -#[allow(dead_code)] -pub fn run_regression_test_with_patches(example_name: &str, test_case_name: &str) { - let patches = get_patches(test_case_name).unwrap(); +// Patched examples +define_regression_test_with_patches!(simple_divisible); - // Patch model to a temporary directory - let model_dir = ModelPatch::from_example(example_name) - .with_file_patches(patches.to_owned()) - .build_to_tempdir() - .unwrap(); - - run_regression_test_common(test_case_name, false, |opts, settings| { - handle_run_command(model_dir.path(), opts, settings) - }); -} +// ------ END: regression tests ------ -fn run_regression_test_common(test_name: &str, debug_model: bool, run_fn: F) -where - F: FnOnce(&RunOpts, Option) -> Result<()>, -{ - unsafe { env::set_var("MUSE2_LOG_LEVEL", "off") }; +/// The tolerance when comparing floating-point values in CSV files +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]) { // 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; let output_dir = if let Ok(dir) = env::var("MUSE2_TEST_OUTPUT_DIR") { - [&dir, test_name].iter().collect() + [&dir, example].iter().collect() } else { tmp = tempdir().unwrap(); tmp.path().to_path_buf() }; - let opts = RunOpts { - output_dir: Some(output_dir.clone()), - overwrite: false, - debug_model: Some(true), // NB: Always enable this as it helps to have the files for debugging - }; - - run_fn(&opts, Some(Settings::default())).unwrap(); - - let test_data_dir = PathBuf::from(format!("tests/data/{test_name}")); - compare_output_dirs(&output_dir, &test_data_dir, debug_model); + // Invoke muse2 + let output_dir_str = output_dir.to_string_lossy(); + let mut args = vec!["example", "run", example, "--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"), + ); } fn compare_output_dirs(cur_output_dir1: &Path, test_data_dir: &Path, debug_model: bool) { diff --git a/tests/regression_missing_commodity.rs b/tests/regression_missing_commodity.rs deleted file mode 100644 index 4c32a654..00000000 --- a/tests/regression_missing_commodity.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! A regression test for the `missing_commodity` example -mod regression; -use regression::run_regression_test; - -#[test] -fn regression_missing_commodity() { - run_regression_test("missing_commodity"); -} diff --git a/tests/regression_muse1_default.rs b/tests/regression_muse1_default.rs deleted file mode 100644 index d2e1f876..00000000 --- a/tests/regression_muse1_default.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! A regression test for the `muse1_default` example -mod regression; -use regression::run_regression_test; - -#[test] -fn regression_muse1_default() { - run_regression_test("muse1_default"); -} diff --git a/tests/regression_simple.rs b/tests/regression_simple.rs deleted file mode 100644 index 92901116..00000000 --- a/tests/regression_simple.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! A regression test for the "simple" example -mod regression; -use regression::run_regression_test_with_debug_files; - -#[test] -fn regression_simple() { - run_regression_test_with_debug_files("simple"); -} diff --git a/tests/regression_simple_divisible.rs b/tests/regression_simple_divisible.rs deleted file mode 100644 index 938c880e..00000000 --- a/tests/regression_simple_divisible.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! A regression test for a patched version of the "simple" example with divisible gas boilers. -mod regression; -use regression::run_regression_test_with_patches; - -#[test] -fn regression_simple_divisible() { - run_regression_test_with_patches("simple", "simple_divisible"); -} diff --git a/tests/regression_two_outputs.rs b/tests/regression_two_outputs.rs deleted file mode 100644 index b2a9d7d0..00000000 --- a/tests/regression_two_outputs.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! A regression test for the `two_outputs` example -mod regression; -use regression::run_regression_test; - -#[test] -fn regression_two_outputs() { - run_regression_test("two_outputs"); -} diff --git a/tests/regression_two_regions.rs b/tests/regression_two_regions.rs deleted file mode 100644 index a4be8c00..00000000 --- a/tests/regression_two_regions.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! A regression test for the `two_regions` example -mod regression; -use regression::run_regression_test; - -#[test] -fn regression_two_regions() { - run_regression_test("two_regions"); -} diff --git a/tests/run.rs b/tests/run.rs deleted file mode 100644 index 1a19e7fc..00000000 --- a/tests/run.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! Integration tests for the `run` command. -use muse2::cli::{RunOpts, handle_run_command}; -use muse2::log::is_logger_initialised; -use muse2::settings::Settings; -use std::path::PathBuf; -use tempfile::tempdir; - -/// Get the path to the example model. -fn get_model_dir() -> PathBuf { - PathBuf::from("examples/simple") -} - -/// An integration test for the `run` command. -/// -/// We also check that the logger is initialised after it is run. -#[test] -fn handle_run_command_works() { - unsafe { std::env::set_var("MUSE2_LOG_LEVEL", "off") }; - - assert!(!is_logger_initialised()); - - // Save results to non-existent directory to check that directory creation works - let tempdir = tempdir().unwrap(); - let output_dir = tempdir.path().join("results"); - let opts = RunOpts { - output_dir: Some(output_dir), - overwrite: false, - debug_model: None, - }; - handle_run_command(&get_model_dir(), &opts, Some(Settings::default())).unwrap(); - - assert!(is_logger_initialised()); -} diff --git a/tests/validate.rs b/tests/validate.rs deleted file mode 100644 index 04c09dfc..00000000 --- a/tests/validate.rs +++ /dev/null @@ -1,24 +0,0 @@ -//! Integration tests for the `validate` command. -use muse2::cli::handle_validate_command; -use muse2::log::is_logger_initialised; -use muse2::settings::Settings; -use std::path::PathBuf; - -/// Get the path to the example model. -fn get_model_dir() -> PathBuf { - PathBuf::from("examples/simple") -} - -/// An integration test for the `validate` command. -/// -/// We also check that the logger is initialised after it is run. -#[test] -fn handle_validate_command_works() { - unsafe { std::env::set_var("MUSE2_LOG_LEVEL", "off") }; - - assert!(!is_logger_initialised()); - - handle_validate_command(&get_model_dir(), Some(Settings::default())).unwrap(); - - assert!(is_logger_initialised()); -}