diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a97e20f9..66788c490 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,8 @@ env: # Tell `anyhow` *not* to collect backtraces for errors. # RUST_LIB_BACKTRACE: 0 + # This will cause a test to fail if it has a dependence on a system/user config file. + AIC_DO_NOT_USE_CONFIG_FILES_IN_TESTS: 1 jobs: build: diff --git a/.github/workflows/mutants.yml b/.github/workflows/mutants.yml index 59ca2b0c5..9ce072ebf 100644 --- a/.github/workflows/mutants.yml +++ b/.github/workflows/mutants.yml @@ -8,6 +8,8 @@ on: [workflow_dispatch] env: CARGO_TERM_COLOR: always + # This will cause a test to fail if it has a dependence on a system/user config file. + AIC_DO_NOT_USE_CONFIG_FILES_IN_TESTS: 1 jobs: mutants: diff --git a/.github/workflows/unstable-ci.yml b/.github/workflows/unstable-ci.yml index 9fb2b2e51..e0ac4649e 100644 --- a/.github/workflows/unstable-ci.yml +++ b/.github/workflows/unstable-ci.yml @@ -35,6 +35,8 @@ env: # artifacts, so they won't be useful for anything (other than maybe the exhaustive # builds with different features). CARGO_INCREMENTAL: 0 + # This will cause a test to fail if it has a dependence on a system/user config file. + AIC_DO_NOT_USE_CONFIG_FILES_IN_TESTS: 1 jobs: build: diff --git a/all-is-cubes-desktop/src/config_files.rs b/all-is-cubes-desktop/src/config_files.rs index b14a30c26..efc613ee0 100644 --- a/all-is-cubes-desktop/src/config_files.rs +++ b/all-is-cubes-desktop/src/config_files.rs @@ -12,6 +12,12 @@ use all_is_cubes_render::camera::GraphicsOptions; pub fn load_config() -> Result { // TODO: make testable // TODO: allow users of this library function to pick their own config dir + + if std::env::var("AIC_DO_NOT_USE_CONFIG_FILES_IN_TESTS").is_ok() { + panic!("tests should be hermetic and not touch user config files \ + (environment variable AIC_DO_NOT_USE_CONFIG_FILES_IN_TESTS set but --no-config-files not passed)"); + } + let project_dirs = ProjectDirs::from("org.switchb", "", "all-is-cubes") .ok_or_else(|| anyhow::anyhow!("could not find configuration directory"))?; create_dir_all(project_dirs.config_dir())?; diff --git a/all-is-cubes-desktop/tests/end-to-end.rs b/all-is-cubes-desktop/tests/end-to-end.rs index 6b26acd61..fdb59957b 100644 --- a/all-is-cubes-desktop/tests/end-to-end.rs +++ b/all-is-cubes-desktop/tests/end-to-end.rs @@ -4,6 +4,10 @@ fn trycmd_tests() { let tc = trycmd::TestCases::new(); + // Extra protection against depending on config now or in the future. + // This will cause a test to fail if it has a dependence on a system/user config file. + tc.env("AIC_DO_NOT_USE_CONFIG_FILES_IN_TESTS", "1"); + // Prevent `anyhow` from printing backtraces if it otherwise would due to env having // "RUST_BACKTRACE=1", because they'd cause our error output tests to fail. // Docs: https://docs.rs/anyhow/1.0.75/anyhow/index.html#details diff --git a/all-is-cubes-desktop/tests/gltf-validation.rs b/all-is-cubes-desktop/tests/gltf-validation.rs index 2bdb227df..e2a97fbfb 100644 --- a/all-is-cubes-desktop/tests/gltf-validation.rs +++ b/all-is-cubes-desktop/tests/gltf-validation.rs @@ -10,6 +10,7 @@ fn gltf_round_trip_test(args: &[&str]) { let gltf_path = temp_dir.path().join("output.gltf"); let output = process::Command::new(env!("CARGO_BIN_EXE_all-is-cubes")) + .env("AIC_DO_NOT_USE_CONFIG_FILES_IN_TESTS", "1") .arg("--no-config-files") .arg("--graphics=record") .arg("--output")