Skip to content

Commit

Permalink
Fix tests on macOS and update coverage config (keepassxreboot#6945)
Browse files Browse the repository at this point in the history
Simplifies coverage generation and uses llvm-cov instead of gcov if
compiler is clang.
  • Loading branch information
phoerious authored Sep 26, 2021
1 parent eeba485 commit a46231a
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 206 deletions.
42 changes: 27 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,6 @@ check_add_gcc_compiler_flag("-Werror=format-security")
check_add_gcc_compiler_flag("-Werror=implicit-function-declaration" C)
check_add_gcc_compiler_flag("-Wcast-align")

if(WITH_COVERAGE AND CMAKE_COMPILER_IS_CLANGXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
# then:
# $ llvm-profdata merge -sparse default.profraw -o default.profdata
# $ llvm-cov show ./tests/${the_test_binary} \
# -format=html -instr-profile=default.profdata -output-dir=./coverages \
# `find src -iname '*.h' -or -iname '*.cpp'`
endif()

if(UNIX AND NOT APPLE)
check_add_gcc_compiler_flag("-Qunused-arguments")
check_add_gcc_compiler_flag("-fPIC")
Expand Down Expand Up @@ -394,16 +385,37 @@ endif(WITH_TESTS)
if(WITH_COVERAGE)
# Include code coverage, use with -DCMAKE_BUILD_TYPE=Debug
include(CodeCoverage)
set(COVERAGE_GCOVR_EXCLUDES
set(COVERAGE_EXCLUDES
"\\(.+/\\)?tests/.\\*"
"\\(.+/\\)?build/.\\*"
"\\(.+/\\)?thirdparty/.\\*"
"\\(.+/\\)?CMakeFiles/.\\*"
"src/main.cpp"
".\\*/moc_\\[^/\\]+\\.cpp"
".\\*/ui_\\[^/\\]+\\.h"
"\\(.+/\\)?zxcvbn/.\\*")
".\\*/\\[^/\\]+_autogen/.\\*"
"\\(.+/\\)?zxcvbn/.\\*"
"/Applications/.\\*"
"/opt/.\\*")
append_coverage_compiler_flags()
setup_target_for_coverage_gcovr_html(
NAME coverage
EXECUTABLE $(MAKE) && $(MAKE) test
)

if(WITH_COVERAGE AND CMAKE_COMPILER_IS_CLANGXX)
set(MAIN_BINARIES
"$<TARGET_FILE:${PROGNAME}>"
"$<TARGET_FILE:keepassxc-cli>"
"$<TARGET_FILE:keepassxc-proxy>")
setup_target_for_coverage_llvm(
NAME coverage
EXECUTABLE $(MAKE) test
BINARY ${MAIN_BINARIES}
SOURCES ${CMAKE_SOURCE_DIR}/src
)
else()
setup_target_for_coverage_gcovr(
NAME coverage
EXECUTABLE $(MAKE) test
)
endif()
endif()

include(CLangFormat)
Expand Down
Loading

0 comments on commit a46231a

Please sign in to comment.