-
Notifications
You must be signed in to change notification settings - Fork 287
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
Test coverage #1073
Test coverage #1073
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1073 +/- ##
======================================
Coverage 71.4% 71.4%
======================================
Files 148 148
Lines 17439 17439
======================================
Hits 12453 12453
Misses 4986 4986 Continue to review full report at Codecov.
|
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.
Thanks for the contribution!
After some trial and error I could finally obtain the desired coverage reports 🎊 . It is important to note that the gcov and gcc versions must match. I had some issues because of that, since I have many gcc versions installed in my system and I the gcov version was not matching with the gcc one.
I left some suggestions to improve a little bit the code. Once these comments are addressed I will be happy to merge the changes.
CMakeLists.txt
Outdated
@@ -8,6 +8,9 @@ project(exiv2 | |||
include(cmake/mainSetup.cmake REQUIRED) | |||
include(CTest) | |||
|
|||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) | |||
include (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.
[minor] Although this is correct, we are trying in this project to not modify the CMAKE_MODULE_PATH
internally so that we can clearly differentiate between the CMake provided modules and the ones provided by us.
Please remove line 11 and change line 12 to:
include(cmake/gcovr.cmake REQUIRED)
cmake/gcovr.cmake
Outdated
@@ -0,0 +1,16 @@ | |||
if(USE_GCOV) |
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.
We should create a option in the main CMakeLists.txt
for this variable. Ideally we should reuse the existing one for remote coverage BUILD_WITH_COVERAGE
.
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.
Note that the line include(cmake/gcovr.cmake REQUIRED)
should appear after that option.
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.
@piponazo, should we continue using the new gcovr.cmake
file, or should we append the code to BUILD_WITH_COVERAGE
within the compilerFlags.cmake
file?
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.
I do not have a strong opinion about that. Either you add it in compilerFlags.cmake
well separated from the "generic" compiler flags or you keep it in that new file. Up to you 😉
cmake/gcovr.cmake
Outdated
@@ -0,0 +1,16 @@ | |||
if(USE_GCOV) | |||
|
|||
SET(GCOVR 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.
Here we are assuming the existence of gcovr
. Please, use find_program
to check whether it exists:
cmake/gcovr.cmake
Outdated
|
||
SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage") | ||
SET(GCC_COVERAGE_LINK_FLAGS "-lgcov") | ||
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" ) |
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.
We are moving away from using CMAKE_CXX_FLAGS
variables which is considered a bad practice in CMake. Instead of that, we should be using add_compile_options
and add_link_options
. However, the second one is only available from CMake 3.13 and therefore we keep using CMAKE_EXE_LINKER_FLAGS
and CMAKE_SHARED_LINKER_FLAGS
instead. You can take a look to the file cmake/compilerFlags.cmake
to see some examples.
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 is only a missing piece (see the previous comment). I would appreciate if you add the additional changes, but I would not block the PR just because of that.
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" ) | ||
if(BUILD_WITH_COVERAGE) | ||
|
||
find_program (GCOVR 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.
Thanks for the changes.
The only missing piece would be to add a check after this line, something like:
if(NOT GCOVR)
message(FATAL_ERROR "gcovr not found")
endif()
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.
Just added the change. Thank you very much for the help!
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.
@piponazo , there are some failures in the CI tests due to the lack of gcovr. If a user doesn't have it, should we just not apply the target?
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.
@piponazo , there are some failures in the CI tests due to the lack of gcovr. If a user doesn't have it, should we just not apply the target?
I agree with that suggestion: gcovr is not essential for obtaining the test coverage data on the CI.
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 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.
Fine for me as it is! Thank you a lot for the contribution 😄
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! We greatly enjoyed this experience!
Pull request has been modified.
Lgtm to me now! @piponazo what do you think? |
* Compiles and runs * Created gcovr reports in separate directory * Improved style and degree of coverage * Added error check for existence of gcovr * CI test fixes
Implements creation of local coverage reports using gcovr as stated in #1068
Example usage:
It will create a directory called coverage_output inside the CMAKE_BINARY_DIR directory, storing the html output from gcovr.