Skip to content

Commit 7fffd14

Browse files
authored
chore(coverage): improve debug report (#11190)
1 parent ca7e2c8 commit 7fffd14

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

crates/evm/coverage/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub struct CoverageReport {
4444
/// All coverage items for the codebase, keyed by the compiler version.
4545
pub analyses: HashMap<Version, SourceAnalysis>,
4646
/// All item anchors for the codebase, keyed by their contract ID.
47+
///
48+
/// `(id, (creation, runtime))`
4749
pub anchors: HashMap<ContractId, (Vec<ItemAnchor>, Vec<ItemAnchor>)>,
4850
/// All the bytecode hits for the codebase.
4951
pub bytecode_hits: HashMap<ContractId, HitMap>,
@@ -77,6 +79,8 @@ impl CoverageReport {
7779
}
7880

7981
/// Add anchors to this report.
82+
///
83+
/// `(id, (creation, runtime))`
8084
pub fn add_anchors(
8185
&mut self,
8286
anchors: impl IntoIterator<Item = (ContractId, (Vec<ItemAnchor>, Vec<ItemAnchor>))>,
@@ -356,7 +360,7 @@ impl Display for CoverageItem {
356360
write!(f, r#"Function "{name}""#)?;
357361
}
358362
}
359-
write!(f, " (location: {}, hits: {})", self.loc, self.hits)
363+
write!(f, " (location: ({}), hits: {})", self.loc, self.hits)
360364
}
361365
}
362366

@@ -375,7 +379,7 @@ pub struct SourceLocation {
375379

376380
impl Display for SourceLocation {
377381
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
378-
write!(f, "source ID {}, lines {:?}, bytes {:?}", self.source_id, self.lines, self.bytes)
382+
write!(f, "source ID: {}, lines: {:?}, bytes: {:?}", self.source_id, self.lines, self.bytes)
379383
}
380384
}
381385

crates/forge/src/coverage.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,31 +201,32 @@ impl CoverageReporter for DebugReporter {
201201

202202
fn report(&mut self, report: &CoverageReport) -> eyre::Result<()> {
203203
for (path, items) in report.items_by_file() {
204+
let uncovered = items.iter().copied().filter(|item| item.hits == 0);
205+
if uncovered.clone().count() == 0 {
206+
continue;
207+
}
208+
204209
sh_println!("Uncovered for {}:", path.display())?;
205-
for item in items {
206-
if item.hits == 0 {
207-
sh_println!("- {item}")?;
208-
}
210+
for item in uncovered {
211+
sh_println!("- {item}")?;
209212
}
210213
sh_println!()?;
211214
}
212215

213-
for (contract_id, anchors) in &report.anchors {
216+
for (contract_id, (cta, rta)) in &report.anchors {
217+
if cta.is_empty() && rta.is_empty() {
218+
continue;
219+
}
220+
214221
sh_println!("Anchors for {contract_id}:")?;
215-
let anchors = anchors
216-
.0
222+
let anchors = cta
217223
.iter()
218224
.map(|anchor| (false, anchor))
219-
.chain(anchors.1.iter().map(|anchor| (true, anchor)));
220-
for (is_deployed, anchor) in anchors {
221-
sh_println!("- {anchor}")?;
222-
if is_deployed {
223-
sh_println!("- Creation code")?;
224-
} else {
225-
sh_println!("- Runtime code")?;
226-
}
225+
.chain(rta.iter().map(|anchor| (true, anchor)));
226+
for (is_runtime, anchor) in anchors {
227+
let kind = if is_runtime { " runtime" } else { "creation" };
227228
sh_println!(
228-
" - Refers to item: {}",
229+
"- {kind} {anchor}: {}",
229230
report
230231
.analyses
231232
.get(&contract_id.version)

0 commit comments

Comments
 (0)