Skip to content

Commit

Permalink
Merge branch 'dev-testing' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierrog committed Apr 10, 2024
2 parents 7905b51 + f5b9d5c commit e39aafa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
toolchain: stable
- name: Test
run: cargo test --verbose
run: TEST_SETTING=0 cargo test --verbose

# Push formatting commit even if compilation/testing fails. This does not
# push a commit if no formatting is required.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
with:
toolchain: stable
- name: Test
run: cargo test --verbose
run: TEST_SETTING=0 cargo test --verbose

check_format:
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions src/game/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ impl mock::Session<'_> {
/// Creates an SVG visualization of the game graph in the visuals directory
/// under the development data directory at the project root.
pub fn visualize(&self, module: &str) -> Result<()> {
match test_setting()? {
TestSetting::Correctness => return Ok(()),
TestSetting::Development => (),
}

let name = format!("{}.svg", self.name()).replace(" ", "-");
let mut dir = get_directory(TestData::Visuals)?;

Expand Down
30 changes: 29 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use strum_macros::Display;

use std::{env, fs, path};

/* DATA RESOURCES DIRECTORY */
/* CONSTANTS */

const DATA_DIRECTORY: &str = "data";

/* DEFINITIONS */

/// Specifies directories for different kinds of data generated for development
/// purposes, which should not be distributed.
#[derive(Display)]
Expand All @@ -24,8 +26,34 @@ pub enum TestData {
Visuals,
}

/// Specifies the level of side effects to generate during testing. This
/// corresponds to the `TEST_SETTING` environment variable.
pub enum TestSetting {
Correctness,
Development,
}

/* UTILITY FUNCTIONS */

/// Returns the testing side effects setting as obtained from the `TEST_SETTING`
/// environment variable.
pub fn test_setting() -> Result<TestSetting> {
if let Ok(setting) = env::var("TEST_SETTING") {
match &setting[..] {
"0" => Ok(TestSetting::Correctness),
"1" => Ok(TestSetting::Development),
_ => Err(anyhow! {
format!(
"TEST_SETTING assignment '{}' not recognized.",
setting
)
}),
}
} else {
Ok(TestSetting::Development)
}
}

/// Returns a PathBuf corresponding to the correct subdirectory for storing
/// development `data`, creating it in the process if it does not exist.
pub fn get_directory(data: TestData) -> Result<path::PathBuf> {
Expand Down

0 comments on commit e39aafa

Please sign in to comment.