-
Notifications
You must be signed in to change notification settings - Fork 265
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
Move script/gcovr to gcovr/__main__.py #214
Conversation
To run coverage test: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is a very valuable change! However, it is actually three changes:
- Moving the script to
__main__
. - Collecting test coverage data on gcovr.
- Disabling the
filter2
test on Windows.
Can you split moving gcovr vs. collecting coverage into two separate commits? Each of those is important enough to have a commit of its own. The current commit message doesn't mention coverage at all on the summary in the first line.
About disabling filter2, I'm not sure why that's necessary?
I've also added a few comments below. Even though I'd like to polish this PR a bit before merging, this is a really great solution, and moves the project along much faster than I would have expected :)
gcovr/__main__.py
Outdated
@@ -2309,7 +2308,9 @@ def build_filter(regex): | |||
return re.compile(os.path.realpath(regex)) | |||
|
|||
|
|||
def main(options, args): | |||
def main(): | |||
global options, args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason why options needs to be global? While that's technically a precise translation of the status quo, that isn't the semantics I intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still some functions that are expecting those variables to be defined at the global scope. Without this, gcovr
fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, we will fix that in a future commit when different modules are extracted.
gcovr/tests/test_gcovr.py
Outdated
|
||
if 'coverage' in sys.modules: | ||
run_coverage = True | ||
env['GCOVR'] = python_interpreter + ' -m coverage run --branch --parallel-mode -m gcovr' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the GCOVR environment variable like this is clever. I like it!
setup.cfg
Outdated
|
||
[coverage:run] | ||
branch = True | ||
parallel = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment that the same options need to be set when building the command in test_gcovr.py?
scripts=scripts | ||
entry_points={ | ||
'console_scripts': [ | ||
'gcovr=gcovr.__main__:main', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally 🎉 :) By moving the whole script to __main__
, you've managed to introduce entry_points much earlier than I would have expected!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pip install
on Windows automatically creates .exe
wrapper in Scripts directory due to this change! It's great! No more manual .bat
wrappers necessary (for cross-platform gcovr
calls)! 👍
gcovr/tests/filter-test2/Makefile
Outdated
@@ -2,8 +2,7 @@ CFLAGS= -fprofile-arcs -ftest-coverage -fPIC | |||
|
|||
BASE_OS:=$(shell uname | cut -d'-' -f1) | |||
ifeq ($(BASE_OS),MSYS_NT) | |||
#GCOVR_TEST_OPTIONS := -f $(shell cygpath -w "$$PWD")\main.cpp | |||
GCOVR_TEST_OPTIONS := -f main.cpp | |||
GCOVR_TEST_OPTIONS := -f $(shell cygpath -w "$$PWD")\main.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute filters are known to not work on Windows right now. I would rather have this test run with a relative filter on Windows than skipping it entirely.
Can you explain how this change is related to collecting coverage or to extracting __main__
? If there is a need for this commit, OK. I'd otherwise prefer to not merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the rebase was a bit to extensive... I had no preference between running a relative filter or skipping the test. I will re-enable the test as proposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: the test was not passing the correct options anyway before those commits. It worked with python 2.7 but failed with python 3.6 now that tests are run with the correct interpreter on windows.
example of coverage ran through CI: https://codecov.io/gh/mayeut/gcovr/list/module-coverage/ |
I will reorganize as 3 distinct commits |
Absolute filters are known to not work on Windows right now.
This prepares for future re-architecture of gcovr.
Use nosetests -v --with-coverage
Fixes #213 |
Move script/gcovr to gcovr/__main__.py
This allows to run coverage on the module quite easily.
It will also prepare for future re-architecture of gcovr.