Skip to content

Commit

Permalink
added report-file option and new coverage test (foundry-rs#5888)
Browse files Browse the repository at this point in the history
* add report-file and test

* chore: clean code by removing unused comments

* fmt

* add corrections

* fmt

---------

Co-authored-by: Enrique Ortiz <[email protected]>
  • Loading branch information
Perelyn-sama and Evalir committed Oct 5, 2023
1 parent 469b856 commit 87283bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
24 changes: 20 additions & 4 deletions crates/forge/bin/cmd/coverage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{install, test::FilterArgs};
use alloy_primitives::{Address, Bytes, U256};
use clap::{Parser, ValueEnum};
use clap::{Parser, ValueEnum, ValueHint};
use ethers::{
prelude::{
artifacts::{Ast, CompactBytecode, CompactDeployedBytecode},
Expand Down Expand Up @@ -29,7 +29,7 @@ use foundry_common::{compile::ProjectCompiler, evm::EvmArgs, fs};
use foundry_config::{Config, SolcReq};
use foundry_utils::types::ToEthers;
use semver::Version;
use std::{collections::HashMap, sync::mpsc::channel};
use std::{collections::HashMap, path::PathBuf, sync::mpsc::channel};
use tracing::trace;
use yansi::Paint;

Expand All @@ -55,6 +55,17 @@ pub struct CoverageArgs {
#[clap(long)]
ir_minimum: bool,

/// The path to output the report.
///
/// If not specified, the report will be stored in the root of the project.
#[clap(
long,
short,
value_hint = ValueHint::FilePath,
value_name = "PATH"
)]
report_file: Option<PathBuf>,

#[clap(flatten)]
filter: FilterArgs,

Expand Down Expand Up @@ -342,9 +353,14 @@ impl CoverageArgs {
for report_kind in self.report {
match report_kind {
CoverageReportKind::Summary => SummaryReporter::default().report(&report),
// TODO: Sensible place to put the LCOV file
CoverageReportKind::Lcov => {
LcovReporter::new(&mut fs::create_file(root.join("lcov.info"))?).report(&report)
if let Some(report_file) = self.report_file {
return LcovReporter::new(&mut fs::create_file(root.join(report_file))?)
.report(&report)
} else {
return LcovReporter::new(&mut fs::create_file(root.join("lcov.info"))?)
.report(&report)
}
}
CoverageReportKind::Debug => DebugReporter.report(&report),
}?;
Expand Down
10 changes: 10 additions & 0 deletions crates/forge/tests/cli/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ forgetest!(basic_coverage, |_prj: TestProject, mut cmd: TestCommand| {
cmd.args(["coverage"]);
cmd.assert_success();
});

forgetest!(report_file_coverage, |prj: TestProject, mut cmd: TestCommand| {
cmd.arg("coverage").args([
"--report".to_string(),
"lcov".to_string(),
"--report-file".to_string(),
prj.root().join("lcov.info").to_str().unwrap().to_string(),
]);
cmd.assert_success();
});

0 comments on commit 87283bc

Please sign in to comment.