Skip to content

Commit

Permalink
Expand Env test to check that separate tests are written for multiple…
Browse files Browse the repository at this point in the history
… Envs (#1157)

### What
Expand Env test to check that separate tests are written for multiple
Envs.

### Why
We don't have a test that checks that multiple files get written in
tests with multiple unique Envs.

Close #1156 

### Merging

Intended to be merged to `main` after:
- #1153
  • Loading branch information
leighmcculloch authored Nov 15, 2023
1 parent ff72a2f commit f70ac78
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions soroban-sdk/src/tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,42 @@ fn register_contract_deploys_predictable_contract_ids() {
/// Test that the test snapshot file is written.
#[test]
fn test_snapshot_file() {
let path = std::path::Path::new("test_snapshots")
let p = std::path::Path::new("test_snapshots")
.join("tests")
.join("env")
.join("test_snapshot_file")
.with_extension("1.json");
assert!(!path.exists());
.join("test_snapshot_file");
let p1 = p.with_extension("1.json");
let p2 = p.with_extension("2.json");
assert!(!p1.exists());
assert!(!p2.exists());
{
let e1 = Env::default();
assert!(!path.exists());
assert!(!p1.exists());
assert!(!p2.exists());
let e2 = e1.clone();
assert!(!path.exists());
assert!(!p1.exists());
assert!(!p2.exists());
{
let _ = Env::default(); // When dropped won't be written because empty.
} // Env dropped, nothing written.
assert!(!p1.exists());
assert!(!p2.exists());
{
let e3 = Env::default(); // When dropped will be written to p1.
let _ = e3.register_contract(None, Contract);
} // Env dropped, written to p1.
let c = e1.register_contract(None, Contract);
assert!(!path.exists());
assert!(p1.exists());
assert!(!p2.exists());
e1.as_contract(&c, || {});
assert!(!path.exists());
assert!(p1.exists());
assert!(!p2.exists());
e2.as_contract(&c, || {});
assert!(!path.exists());
}
assert!(path.exists());
let _ = std::fs::remove_file(&path);
assert!(p1.exists());
assert!(!p2.exists());
} // Env dropped, written to p2.
assert!(p1.exists());
assert!(p2.exists());
let _ = std::fs::remove_file(&p1);
let _ = std::fs::remove_file(&p2);
}

0 comments on commit f70ac78

Please sign in to comment.