Skip to content

Commit 8e66fd1

Browse files
authored
feat(forge): --exclude-tests option from coverage (#10807)
feat: exclude tests option from coverage
1 parent 23e8841 commit 8e66fd1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

crates/forge/src/cmd/coverage.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub struct CoverageArgs {
7575
#[arg(long)]
7676
include_libs: bool,
7777

78+
/// Whether to exclude tests from the coverage report.
79+
#[arg(long)]
80+
exclude_tests: bool,
81+
7882
/// The coverage reporters to use. Constructed from the other fields.
7983
#[arg(skip)]
8084
reporters: Vec<Box<dyn CoverageReporter>>,
@@ -194,8 +198,10 @@ impl CoverageArgs {
194198
for (path, source_file, version) in output.output().sources.sources_with_version() {
195199
report.add_source(version.clone(), source_file.id as usize, path.clone());
196200

197-
// Filter out dependencies.
198-
if !self.include_libs && project_paths.has_library_ancestor(path) {
201+
// Filter out libs dependencies and tests.
202+
if (!self.include_libs && project_paths.has_library_ancestor(path)) ||
203+
(self.exclude_tests && project_paths.is_test(path))
204+
{
199205
continue;
200206
}
201207

0 commit comments

Comments
 (0)