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

Is it possible to add custom GCOVR_EXCL_START / END markers via --exclude-lines-by-pattern? #927

Closed
Stan7999 opened this issue May 15, 2024 · 2 comments

Comments

@Stan7999
Copy link

I am using the gcovr --exclude-lines-by-pattern option inside a Makefile in order to have platform specific exclude markers:

gcovr --exclude-lines-by-pattern '^.*$(PLATFORM)_EXCL_LINE.*$$'

This works great and would exclude for instance lines with /* TESTPLATFORM_EXCL_LINE */ when the make target is TESTPLATFORM.

I am wondering if this option is intended too for creating custom block excludes. For instance if I try on a regex checker the regex
.* TESTPLATFORM_EXCL_LINE_START(\n|.)*?TESTPLATFORM_EXCL_LINE_STOP.*

would match any code encapsulated by comments with TESTPLATFORM_EXCL_LINE_START and TESTPLATFORM_EXCL_LINE_STOP

I have seen the discussion on this issue
#675

And there it is mentioned "the option is intended to override Gcovr's default exclusion pattern" and "you can combine multiple patterns for this option with |"
Therefore I thought I would simply add
gcovr --exclude-lines-by-pattern '^.*$(PLATFORM)_EXCL_LINE.*$$'|$(PLATFORM)_EXCL_LINE_START(\n|.)*?$(PLATFORM)_EXCL_LINE_STOP'

or for easier testing in gcovr.cfg.
exclude-lines-by-pattern=TESTPLATFORM_EXCL_LINE_START(\n|.)*?TESTPLATFORM_EXCL_LINE_STOP|^.*TESTPLATFORM_EXCL_LINE.*$
or alternatively only the block exclude:
exclude-lines-by-pattern=.*TESTPLATFORM_EXCL_LINE_START(\n|.)*?TESTPLATFORM_EXCL_LINE_STOP.*

However none of these works for the block exclude. I guess I misunderstand the option and indeed you can only use it for custom single line excludes?

@Spacetown
Copy link
Member

Spacetown commented May 15, 2024

The --exclude-lines-by-pattern is only for lines and not for blocks. If you define --exclude-pattern-prefix=TESTPLATFORM you will activate the markers TESTPLATFORM_EXCL_LINE, TESTPLATFORM_EXCL_START and TESTPLATFORM_EXCL_STOP. In this case the default markers starting with GCOVR, LCOVR, GCOV or LCOV.

@Stan7999
Copy link
Author

Stan7999 commented May 17, 2024

A colleague found a way to achieve what I wanted using the exclude-pattern-prefix:

--exclude-pattern-prefix '[GL]COVR?(?:_$(PLATFORM))?'

Like that you are still able to use the standard GCOV_EXCL_LINE, GCOV_EXCL_START and so on together with a platform specific exclude, i.e. GCOVR_TEST_PLATFORM_EXCL_START.

So I was simply trying with the wrong option. Great how you implemented this so configurable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants