Skip to content

Commit

Permalink
chore: clear only when not coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Jun 1, 2024
1 parent f35166d commit 593890d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
8 changes: 2 additions & 6 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,6 @@ impl TestArgs {
// processing the remaining tests and print the suite summary.
any_test_failed |= result.status == TestStatus::Failure;

if result.traces.is_empty() {
continue;
}

// Clear the addresses and labels from previous runs.
decoder.clear_addresses();
decoder
Expand Down Expand Up @@ -524,8 +520,8 @@ impl TestArgs {
// Print suite summary.
shell::println(suite_result.summary())?;

// Free memory.
suite_result.keep_only_results();
// Free memory if it's not needed.
suite_result.clear_unneeded();

// Add the suite result to the outcome.
outcome.results.insert(contract_name, suite_result);
Expand Down
6 changes: 4 additions & 2 deletions crates/forge/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ impl SuiteResult {
}

/// Frees memory that is not used for the final output.
pub fn keep_only_results(&mut self) {
ContractsByArtifact::clear(&mut self.known_contracts);
pub fn clear_unneeded(&mut self) {
if !self.test_results.values().any(|r| r.coverage.is_some()) {
ContractsByArtifact::clear(&mut self.known_contracts);
}
}

/// Returns an iterator over all individual succeeding tests and their names.
Expand Down
12 changes: 5 additions & 7 deletions crates/forge/tests/cli/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ contract AContractTest is DSTest {
let lcov_data = std::fs::read_to_string(lcov_info).unwrap();
// AContract.init must be hit at least once
let re = Regex::new(r"FNDA:(\d+),AContract\.init").unwrap();
assert!(lcov_data.lines().any(|line| re.captures(line).map_or(false, |caps| caps
.get(1)
.unwrap()
.as_str()
.parse::<i32>()
.unwrap() >
0)));
let valid_line = |line| {
re.captures(line)
.map_or(false, |caps| caps.get(1).unwrap().as_str().parse::<i32>().unwrap() > 0)
};
assert!(lcov_data.lines().any(valid_line), "{lcov_data}");
});

0 comments on commit 593890d

Please sign in to comment.