1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
message(
"\n${BoldGreen}Now configuring tests for ${CMAKE_PROJECT_NAME}${ColourReset}")
message("")
message("To make the tests and then perform the coverage analysis:")
message(
"cmake ../../development -DBUILD_TESTS=On -DCODE_COVERAGE=On -DCMAKE_BUILD_TYPE=Debug"
)
message("make")
message("make coverage")
message(
"And the coverage results will be output (HTML) in ${CMAKE_CURRENT_BINARY_DIR}/coverage"
)
# This export will allow using the flags to be used by the Clang-based code
# analyzer.
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json")
execute_process(
COMMAND
cmake -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json)
endif()
# This file is included if BUILD_TESTS option is set to ON
configure_file(${CMAKE_UTILS_PATH}/tests-config.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/tests-config.h @ONLY)
find_package(Catch2 3 REQUIRED)
# Whatever the platform, this always works.
find_package(
Qt6
COMPONENTS Core Svg Xml Network
REQUIRED)
message("Using local XPERTMASS libraries build the tests")
message("")
set(XpertMass_FOUND 1)
set(XpertMass_INCLUDE_DIRS
"$ENV{HOME}/devel/xpertmass/development/src/XpertMass/includes")
set(XpertMass_LIBRARIES
"$ENV{HOME}/devel/xpertmass/build-area/unix/src/XpertMass/libXpertMass.so")
if(NOT TARGET XpertMass::Core)
add_library(XpertMass::Core UNKNOWN IMPORTED GLOBAL)
set_target_properties(
XpertMass::Core
PROPERTIES IMPORTED_LOCATION ${XpertMass_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${XpertMass_INCLUDE_DIRS})
endif()
message("")
set(tests_SRCS
catch2-test-main.cpp
TestUtils.cpp
test_CalcOptions.cpp
test_Isotope.cpp
test_IsotopicData.cpp
test_IsotopicDataLibraryHandler.cpp
test_IsotopicDataUserConfigHandler.cpp
test_IsotopicDataManualConfigHandler.cpp
test_Formula.cpp
test_Ionizer.cpp
test_ChemicalGroupRule.cpp
test_ChemicalGroup.cpp
test_IndexRangeCollection.cpp
test_Modif.cpp
test_Monomer.cpp
test_Sequence.cpp
test_CrossLinker.cpp
test_CrossLinkedRegion.cpp
test_CrossLink.cpp
test_CleavageMotif.cpp
test_CleavageRule.cpp
test_CleavageAgent.cpp
test_CleavageConfig.cpp
test_FragmentationRule.cpp
test_FragmentationPathway.cpp
test_FragmentationConfig.cpp
test_PolChemDef.cpp
test_PolChemDefSpec.cpp
test_Polymer.cpp
test_Oligomer.cpp
test_Cleaver.cpp
test_Fragmenter.cpp
test_MassCollection.cpp
)
add_executable(testRunner ${tests_SRCS} ${${TARGET}_QRC_CPP})
# We set the target link libraries this way to reuse them later.
set(TARGET_LINK_LIBRARIES
-Wl,--whole-archive
XpertMass::Core
-Wl,--no-whole-archive
-Wl,--no-as-needed
PappsoMSpp::Core
-Wl,--as-needed
IsoSpec++::IsoSpec++
Qt6::Core
Qt6::Xml
Qt6::Network
Catch2::Catch2WithMain)
# Finally actually set the linking dependencies to the executable.
target_link_libraries(testRunner ${TARGET_LINK_LIBRARIES})
# For the tests-config.h file
target_include_directories(testRunner PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
set_property(TARGET testRunner PROPERTY CXX_STANDARD 17) # we want C++17
# Enable testing
# enable_testing()
include(Catch)
catch_discover_tests(testRunner)
# Add the Catch2-based single binary test file to the CMake's test suite so that
# it gets called using 'make test'. To see the output, add "ARGS=-V" to the
# call.
add_test(NAME CoreTests COMMAND testRunner)
# add_custom_target(runtests ALL
add_custom_target(runtests
COMMAND testRunner --success
DEPENDS testRunner XpertMass::Core
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Now running the tests")
if(CMAKE_COMPILER_IS_GNUCXX AND CODE_COVERAGE)
include(CodeCoverage)
append_coverage_compiler_flags()
# Added to change the theme, by looking into the code
set(GCOVR_ADDITIONAL_ARGS ${GCOVR_ADDITIONAL_ARGS} --html-theme
github.dark-blue)
# Added to ouput the gcovr command to the terminal, by looking into the code
set(CODE_COVERAGE_VERBOSE On)
setup_target_for_coverage_gcovr_html(
NAME
coverage
EXECUTABLE
${CMAKE_CURRENT_BINARY_DIR}/testRunner
||
/dev/true
BASE_DIRECTORY
${CMAKE_SOURCE_DIR})
add_dependencies(coverage testRunner XpertMass::Core)
endif()
|