From c42a00ca168b38004e6cdd7991ef483ca2f73159 Mon Sep 17 00:00:00 2001 From: realaltffour <56314286+realaltffour@users.noreply.github.com> Date: Sat, 18 Apr 2020 11:59:19 +0300 Subject: [PATCH] Add dummy tests --- CMakeLists.txt | 30 +++++++++++++++++++----------- buildCodeCov.sh | 2 +- coverage.info | 0 src/CMakeLists.txt | 10 ++++++++++ tests/CMakeLists.txt | 2 ++ tests/test_main.cpp | 4 ++++ 6 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 coverage.info create mode 100644 src/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/test_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 15a812b..b550aae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,20 +5,28 @@ project("fixmydownloads" VERSION 0.0.1) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH}) -if (CMAKE_COMPILER_IS_GNUCC) - option(ENABLE_COVERAGE "Enable coverage reporting" FALSE) +# Code Coverage Configuration +add_library(coverage_config INTERFACE) - if (ENABLE_COVERAGE) - add_compile_options(--coverage -O0 -fprofile-arcs -ftest-coverage) - endif() -endif() +option(CODE_COVERAGE "Enable coverage reporting" OFF) +if(CODE_COVERAGE) + # Add required flags (GCC & LLVM/Clang) + target_compile_options(coverage_config INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags + ) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(coverage_config INTERFACE --coverage) + else() + target_link_libraries(coverage_config INTERFACE --coverage) + endif() +endif(CODE_COVERAGE) -# Set C compiler options -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Wall -Werror -Wno-unused-function") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Wall -Werror -Wno-unused-function") +add_subdirectory(src) -add_executable(fixmydl src/main.c) -target_link_libraries(fixmydl --coverage) +enable_testing() +add_subdirectory(tests) install(TARGETS fixmydl RUNTIME DESTINATION bin diff --git a/buildCodeCov.sh b/buildCodeCov.sh index 9b68b8f..b62e6f6 100755 --- a/buildCodeCov.sh +++ b/buildCodeCov.sh @@ -2,6 +2,6 @@ mkdir -p build && cd build -cmake -DENABLE_COVERAGE:BOOL=TRUE .. +cmake -DCODE_COVERAGE:BOOL=TRUE .. make -j$(nproc) cd .. diff --git a/coverage.info b/coverage.info new file mode 100644 index 0000000..e69de29 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..4b18690 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,10 @@ +# Set C compiler options +if (NOT CODE_COVERAGE) + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3") +endif(NOT CODE_COVERAGE) + +add_executable(fixmydl main.c) +target_compile_options(fixmydl PUBLIC -Wall -Werror -Wno-unused-function -pedantic) + +target_link_libraries(fixmydl PUBLIC coverage_config) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..0efd188 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(tests test_main.cpp) +add_test(NAME test COMMAND tests) diff --git a/tests/test_main.cpp b/tests/test_main.cpp new file mode 100644 index 0000000..a46866d --- /dev/null +++ b/tests/test_main.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +}