Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to ignore directories from coverage report #7301

Closed

Conversation

dimazhornyk
Copy link
Contributor

Motivation

Some files shouldn't be displayed in a coverage report, e.g. utility contracts or dev contracts, and currently there is no way to ignore them from the coverage report. There is a popular issue describing the problem #2988.

Solution

This PR introduces such a possibility using a cli argument --no-coverage-path or config key no_coverage_path.
On the implementation side, it filters out all the ignored files right before the report output. It can't be done earlier because there may be files dependent on the ignored ones, which will not be covered if we remove the ignored files earlier.

Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to format with cargo +nightly fmt --all

@@ -151,6 +154,30 @@ impl CoverageReport {
}
Ok(())
}

pub fn filter_out_ignored_sources(&mut self, filter: &impl CoverageFilter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

self.items = new_items;
}

fn get_source_path(&self, version: &Version, source_id: usize) -> String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -40,6 +41,10 @@ pub struct FilterArgs {
value_name = "GLOB"
)]
pub path_pattern_inverse: Option<GlobMatcher>,

/// Only show coverage for files that do not match the specified glob pattern.
#[arg(long = "no-coverage-path", visible_alias = "ncp", value_name = "GLOB")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's name it ignore instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

@zerosnacks
Copy link
Member

Hi @dimazhornyk thanks for your PR!

Looks like this is almost ready for review, would be great to get this merged

To resolve the formatting issue make sure to run: cargo +nightly fmt --all

@mattsse
Copy link
Member

mattsse commented Jun 25, 2024

sorry about dropping this @dimazhornyk ...

if you don't have the capacity for fixing the conflicts, we can take it from here @zerosnacks

@zerosnacks zerosnacks self-assigned this Jun 26, 2024
@zerosnacks zerosnacks linked an issue Jun 26, 2024 that may be closed by this pull request
@zerosnacks zerosnacks mentioned this pull request Jun 27, 2024
2 tasks
@zerosnacks zerosnacks changed the base branch from master to zerosnacks/ignore-directories-coverage July 1, 2024 09:21
@zerosnacks zerosnacks changed the base branch from zerosnacks/ignore-directories-coverage to master July 1, 2024 09:26
@zerosnacks
Copy link
Member

Closing this PR in favor of #8321

I've included the commits of @dimazhornyk

@zerosnacks zerosnacks closed this Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

forge coverage should allow excluding contracts
4 participants