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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dimazhornyk
Copy link

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
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
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
Author

Choose a reason for hiding this comment

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

renamed

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.

None yet

2 participants