Skip to content

Commit

Permalink
[INFRA] cleanup add_app_test
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Jan 29, 2024
1 parent 04bd0e2 commit 46f4360
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 52 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include (ccache)
require_ccache ()

# Add packages.
set (CPM_INDENT " CMake Package Manager CPM: ")
include (CPM)
include (CPMGetSystemPackage)
Expand All @@ -46,7 +47,6 @@ 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)
81 changes: 32 additions & 49 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
cmake_minimum_required (VERSION 3.16)

# Test executables and libraries should not mix with the application files.
unset (CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
unset (CMAKE_LIBRARY_OUTPUT_DIRECTORY)
unset (CMAKE_RUNTIME_OUTPUT_DIRECTORY)

# Add googletest.
CPMGetSystemPackage (googletest)
include (GoogleTest OPTIONAL)

# 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)

# Set directories for test output files, input data and binaries.
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output)
add_definitions (-DOUTPUTDIR=\"${CMAKE_CURRENT_BINARY_DIR}/output/\")
add_definitions (-DDATADIR=\"${CMAKE_CURRENT_BINARY_DIR}/data/\")
add_definitions (-DBINDIR=\"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/\")

# Test executables and libraries should not mix with the application files.
unset (CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
unset (CMAKE_LIBRARY_OUTPUT_DIRECTORY)
unset (CMAKE_RUNTIME_OUTPUT_DIRECTORY)

include (seqan3_test_component)

add_library (${PROJECT_NAME}_test INTERFACE)
target_compile_options (${PROJECT_NAME}_test INTERFACE "-pedantic" "-Wall" "-Wextra" "-Werror")
# Add the test interface library.
if (NOT TARGET ${PROJECT_NAME}_test)
add_library (${PROJECT_NAME}_test INTERFACE)
target_compile_options (${PROJECT_NAME}_test INTERFACE "-pedantic" "-Wall" "-Wextra" "-Werror")

# GCC12 and above: Disable warning about std::hardware_destructive_interference_size not being ABI-stable.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
target_compile_options (${PROJECT_NAME}_test INTERFACE "-Wno-interference-size")
# GCC12 and above: Disable warning about std::hardware_destructive_interference_size not being ABI-stable.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
target_compile_options (${PROJECT_NAME}_test INTERFACE "-Wno-interference-size")
endif ()
endif ()
endif ()

# GCC12 has some bogus warnings. They will not be fixed in googletest.
# https://github.com/google/googletest/issues/4232
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
target_compile_options (${PROJECT_NAME}_test INTERFACE "-Wno-restrict")
# GCC12 has some bogus warnings. They will not be fixed in googletest.
# https://github.com/google/googletest/issues/4232
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
target_compile_options (${PROJECT_NAME}_test INTERFACE "-Wno-restrict")
endif ()
endif ()
endif ()

target_link_libraries (${PROJECT_NAME}_test INTERFACE "${PROJECT_NAME}_lib" "GTest::gtest_main"
)
target_include_directories (${PROJECT_NAME}_test INTERFACE "${seqan3_SOURCE_DIR}/test/include")
add_library (${PROJECT_NAME}::test ALIAS ${PROJECT_NAME}_test)
target_link_libraries (${PROJECT_NAME}_test INTERFACE "${PROJECT_NAME}_lib" "GTest::gtest_main")
target_include_directories (${PROJECT_NAME}_test INTERFACE "${seqan3_SOURCE_DIR}/test/include")
add_library (${PROJECT_NAME}::test ALIAS ${PROJECT_NAME}_test)
endif ()

# Add the check target that builds and runs tests.
add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND})

include (seqan3_test_component)
# A macro that adds an api or cli test.
macro (add_app_test test_filename)
# Extract the test target name.
Expand All @@ -56,10 +59,11 @@ macro (add_app_test test_filename)
# Create the test target.
add_executable (${target} ${test_filename})
target_link_libraries (${target} ${PROJECT_NAME}::test)
add_dependencies (${target} ${PROJECT_NAME})
add_dependencies (check ${target})

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

unset (source_file)
unset (target)
Expand All @@ -68,28 +72,7 @@ endmacro ()

# 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)
Expand Down
2 changes: 1 addition & 1 deletion test/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.16)

add_api_test (convert_fastq_test.cpp)
add_app_test (convert_fastq_test.cpp)
target_use_datasources (convert_fastq_test FILES in.fastq)
2 changes: 1 addition & 1 deletion test/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.16)

add_cli_test (fastq_to_fasta_options_test.cpp)
add_app_test (fastq_to_fasta_options_test.cpp)
target_use_datasources (fastq_to_fasta_options_test FILES in.fastq)

0 comments on commit 46f4360

Please sign in to comment.