Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 30, 2024
1 parent b968251 commit 3a7efed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
36 changes: 15 additions & 21 deletions crates/evm/coverage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,29 @@ impl CoverageReport {
self.anchors.extend(anchors);
}

/// Get coverage summaries by source file path.
pub fn summary_by_file(&self) -> impl Iterator<Item = (PathBuf, CoverageSummary)> {
let mut summaries = BTreeMap::<PathBuf, CoverageSummary>::new();

for (version, items) in self.items.iter() {
for item in items {
let Some(path) =
self.source_paths.get(&(version.clone(), item.loc.source_id)).cloned()
else {
continue;
};
summaries.entry(path).or_default().add_item(item);
}
}
/// Returns an iterator over coverage summaries by source file path.
pub fn summary_by_file(&self) -> impl Iterator<Item = (&Path, CoverageSummary)> {
self.by_file(|summary: &mut CoverageSummary, item| summary.add_item(item))
}

summaries.into_iter()
/// Returns an iterator over coverage items by source file path.
pub fn items_by_file(&self) -> impl Iterator<Item = (&Path, Vec<&CoverageItem>)> {
self.by_file(|list: &mut Vec<_>, item| list.push(item))
}

/// Get coverage items by source file path.
pub fn items_by_source(&self) -> impl Iterator<Item = (&Path, Vec<&CoverageItem>)> {
let mut items_by_source: BTreeMap<&Path, Vec<&CoverageItem>> = BTreeMap::new();
for (version, items) in self.items.iter() {
fn by_file<'a, T: Default>(
&'a self,
mut f: impl FnMut(&mut T, &'a CoverageItem),
) -> impl Iterator<Item = (&'a Path, T)> {
let mut by_file: BTreeMap<&Path, T> = BTreeMap::new();
for (version, items) in &self.items {
for item in items {
let key = (version.clone(), item.loc.source_id);
let Some(path) = self.source_paths.get(&key) else { continue };
items_by_source.entry(path).or_default().push(item);
f(by_file.entry(path).or_default(), item);
}
}
items_by_source.into_iter()
by_file.into_iter()
}

/// Processes data from a [`HitMap`] and sets hit counts for coverage items in this coverage
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/src/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'a> LcovReporter<'a> {

impl CoverageReporter for LcovReporter<'_> {
fn report(self, report: &CoverageReport) -> eyre::Result<()> {
for (path, items) in report.items_by_source() {
for (path, items) in report.items_by_file() {
let summary = CoverageSummary::from_items(items.iter().copied());

writeln!(self.out, "TN:")?;
Expand Down Expand Up @@ -152,7 +152,7 @@ pub struct DebugReporter;

impl CoverageReporter for DebugReporter {
fn report(self, report: &CoverageReport) -> eyre::Result<()> {
for (path, items) in report.items_by_source() {
for (path, items) in report.items_by_file() {
sh_println!("Uncovered for {}:", path.display())?;
items.iter().for_each(|item| {
if item.hits == 0 {
Expand Down

0 comments on commit 3a7efed

Please sign in to comment.