Skip to content

Commit

Permalink
[INFRA] Some more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Jan 29, 2024
1 parent 4aef199 commit 04bd0e2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ jobs:
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
make -j2 gtest_main yaml-cpp
make -j2 -k gtest_main yaml-cpp
- name: Build tests
env:
CCACHE_IGNOREOPTIONS: "-fprofile-abs-path"
run: |
ccache -z
cd build
CMAKE_BUILD_PARALLEL_LEVEL=2 cmake --build . -- -k test
make -j2 -k check
ccache -sv
- name: Generate coverage report
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ jobs:
cd build
cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
make -j2 gtest_main yaml-cpp
make -j2 -k gtest_main yaml-cpp
- name: Build application
run: |
cd build
CMAKE_BUILD_PARALLEL_LEVEL=2 cmake --build . -- -k
make -j2 -k
- name: Build and run tests
run: |
cd build
CMAKE_BUILD_PARALLEL_LEVEL=2 cmake --build . -- -k test
make -j2 -k check
6 changes: 3 additions & 3 deletions .github/workflows/ci_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ jobs:
cd build
cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
make -j3 gtest_main yaml-cpp
make -j3 -k gtest_main yaml-cpp
- name: Build application
run: |
cd build
CMAKE_BUILD_PARALLEL_LEVEL=3 cmake --build . -- -k
make -j3 -k
- name: Build and run tests
run: |
cd build
CMAKE_BUILD_PARALLEL_LEVEL=3 cmake --build . -- -k test
make -j3 -k check
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ string (ASCII 27 Esc)
set (FontBold "${Esc}[1m")
set (FontReset "${Esc}[m")

# Allow to include CMake scripts from the app-template.
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

# Use ccache.
Expand All @@ -40,16 +41,12 @@ CPMUsePackageLock (${CMAKE_CURRENT_LIST_DIR}/cmake/package-lock.cmake)
CPMGetSystemPackage (sharg)
CPMGetSystemPackage (seqan3)

# Allow to include CMake scripts from seqan3.
list (APPEND CMAKE_MODULE_PATH "${seqan3_SOURCE_DIR}/test/cmake/")
# Allow to include CMake scripts from the app-template.
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/test/cmake/")

# Add the application.
add_subdirectory (src)
message (STATUS "${FontBold}You can run `make` to build the application.${FontReset}")

## TEST

list (APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure") # Must be before `enable_testing ()`.
enable_testing ()
add_subdirectory (test EXCLUDE_FROM_ALL)
50 changes: 30 additions & 20 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required (VERSION 3.16)

# Allow to include CMake scripts from seqan3.
list (APPEND CMAKE_MODULE_PATH "${seqan3_SOURCE_DIR}/test/cmake/")
# Allow to include CMake scripts from the app-template.
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/")

CPMGetSystemPackage (googletest)
include (GoogleTest OPTIONAL)

Expand Down Expand Up @@ -39,6 +44,8 @@ target_link_libraries (${PROJECT_NAME}_test INTERFACE "${PROJECT_NAME}_lib" "GTe
target_include_directories (${PROJECT_NAME}_test INTERFACE "${seqan3_SOURCE_DIR}/test/include")
add_library (${PROJECT_NAME}::test ALIAS ${PROJECT_NAME}_test)

add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND})

# A macro that adds an api or cli test.
macro (add_app_test test_filename)
# Extract the test target name.
Expand All @@ -52,36 +59,39 @@ macro (add_app_test test_filename)

# Generate and set the test name.
add_test (NAME "${test_name}" COMMAND ${target})
add_dependencies (check ${target})

unset (source_file)
unset (target)
unset (test_name)
endmacro ()

# Build tests just before their execution, because they have not been built with "all" target.
# The trick is here to provide a cmake file as a directory property that executes the build command.
file (WRITE "${CMAKE_CURRENT_BINARY_DIR}/build_test_targets.cmake"
"execute_process (COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target api_test)\n"
"execute_process (COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target cli_test)\n"
"execute_process (COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${PROJECT_NAME}_header_test)\n"
)
set_directory_properties (PROPERTIES TEST_INCLUDE_FILE "${CMAKE_CURRENT_BINARY_DIR}/build_test_targets.cmake")
list (APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")

# Fetch data and add the tests.
include (data/datasources.cmake)

add_custom_target (api_test ALL)

macro (add_api_test test_filename)
add_app_test (${test_filename})

seqan3_test_component (target "${test_filename}" TARGET_NAME)
add_dependencies (api_test ${target})
endmacro ()

add_subdirectory (api)

add_custom_target (cli_test ALL)

macro (add_cli_test test_filename)
add_app_test (${test_filename})

seqan3_test_component (target "${test_filename}" TARGET_NAME)
add_dependencies (cli_test ${target})
add_dependencies (${target} "${PROJECT_NAME}")
endmacro ()

add_subdirectory (cli)
add_subdirectory (header)
add_subdirectory (coverage)

add_custom_target (unit_test
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target api_test cli_test
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -R \"api/ \|cli/\"
)
add_custom_target (header_test
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${PROJECT_NAME}_header_test
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -R \"header\"
)

message (STATUS "${FontBold}You can run `make test` to build and run tests.${FontReset}")
message (STATUS "${FontBold}You can run `make check` to build and run tests.${FontReset}")
9 changes: 0 additions & 9 deletions test/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
cmake_minimum_required (VERSION 3.16)

add_custom_target (api_test ALL)

macro (add_api_test test_filename)
add_app_test (${test_filename})

seqan3_test_component (target "${test_filename}" TARGET_NAME)
add_dependencies (api_test ${target})
endmacro ()

add_api_test (convert_fastq_test.cpp)
target_use_datasources (convert_fastq_test FILES in.fastq)
10 changes: 0 additions & 10 deletions test/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
cmake_minimum_required (VERSION 3.16)

add_custom_target (cli_test ALL)

macro (add_cli_test test_filename)
add_app_test (${test_filename})

seqan3_test_component (target "${test_filename}" TARGET_NAME)
add_dependencies (cli_test ${target})
add_dependencies (${target} "${PROJECT_NAME}")
endmacro ()

add_cli_test (fastq_to_fasta_options_test.cpp)
target_use_datasources (fastq_to_fasta_options_test FILES in.fastq)
1 change: 1 addition & 0 deletions test/header/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ file (WRITE "${PROJECT_BINARY_DIR}/${target}.cpp" "")
add_executable (${target} ${PROJECT_BINARY_DIR}/${target}.cpp)
target_link_libraries (${target} ${PROJECT_NAME}_header_test_lib)
add_test (NAME "${target}" COMMAND ${target})
add_dependencies (check ${target})

foreach (header ${header_files})
seqan3_test_component (header_test_name "${header}" TEST_NAME)
Expand Down

0 comments on commit 04bd0e2

Please sign in to comment.