Skip to content

Commit

Permalink
#414 cleanup previous model based test run
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-kuprianov committed Sep 25, 2020
1 parent 6ef740e commit 48a2819
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions light-client/tests/model_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ fn model_based_test(
output_env: &TestEnv,
) {
println!(" Running model-based single-step test case: {}", test.test);
// Cleanup possible previous runs
output_env.clear_log();
output_env.remove_file("counterexample.tla");
output_env.remove_file("counterexample.json");
output_env.remove_file("test.json");

// Check for the necessary programs
let check_program = |program| {
if !Command::exists_program(program) {
output_env.logln(&format!(" > {} not found", program));
Expand Down
9 changes: 9 additions & 0 deletions testgen/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ impl TestEnv {
&self.current_dir
}

pub fn clear_log(&self) -> Option<()> {
fs::remove_file(self.full_path("log")).ok()
}

pub fn logln(&self, msg: &str) -> Option<()> {
println!("{}", msg);
fs::OpenOptions::new()
Expand Down Expand Up @@ -88,6 +92,11 @@ impl TestEnv {
self.copy_file_from(other.full_path(path))
}

/// Remove a file from a path relative to the environment current dir
pub fn remove_file(&self, rel_path: impl AsRef<Path>) -> Option<()> {
fs::remove_file(self.full_path(rel_path)).ok()
}

/// Convert a relative path to the full path from the test root
/// Return None if the full path can't be formed
pub fn full_path(&self, rel_path: impl AsRef<Path>) -> PathBuf {
Expand Down

0 comments on commit 48a2819

Please sign in to comment.