Skip to content

Commit 2ce20e9

Browse files
committed
[INFRA] Update tests
1 parent 3bfc884 commit 2ce20e9

File tree

2 files changed

+40
-50
lines changed

2 files changed

+40
-50
lines changed

test/header/generate_header_source.cmake

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,61 +13,57 @@ option (HEADER_SUB_TEST "")
1313

1414
file (WRITE "${HEADER_TARGET_SOURCE}" "") # write empty file
1515

16+
# cmake-format: off
17+
1618
if (HEADER_SUB_TEST STREQUAL "no-self-include")
1719
# this test ensures that a header will not be included by itself later
1820
file (READ "${HEADER_FILE_ABSOLUTE}" header_content)
1921

2022
string (REPLACE "#pragma once" "" header_content "${header_content}")
2123

22-
file (APPEND "${HEADER_TARGET_SOURCE}" "${header_content}")
24+
file (APPEND "${HEADER_TARGET_SOURCE}"
25+
"// sharg-header-test-no-self-include-start\n"
26+
"${header_content}\n"
27+
"// sharg-header-test-no-self-include-end\n\n")
2328
else ()
2429
# this test ensures that a header guard is in place
2530
file (APPEND "${HEADER_TARGET_SOURCE}"
26-
"
27-
#include <${HEADER_FILE_INCLUDE}>
28-
#include <${HEADER_FILE_INCLUDE}>")
31+
"// sharg-header-test-header-guard-start\n"
32+
"#include <${HEADER_FILE_INCLUDE}>\n"
33+
"#include <${HEADER_FILE_INCLUDE}>\n"
34+
"// sharg-header-test-header-guard-end\n\n")
2935
endif ()
3036

3137
# these includes are required by some headers (note that they follow)
3238
file (APPEND "${HEADER_TARGET_SOURCE}"
33-
"
34-
#include <gtest/gtest.h>
35-
TEST(${HEADER_TEST_NAME_SAFE}) {}")
39+
"// sharg-header-test-dependencies-start\n"
40+
"#include <gtest/gtest.h>\n"
41+
"TEST(${HEADER_TEST_NAME_SAFE}) {}\n"
42+
"// sharg-header-test-dependencies-end\n\n")
3643

3744
# test that sharg headers include platform.hpp
3845
if ("${HEADER_COMPONENT}" MATCHES "sharg")
3946

4047
# exclude sharg/std/* and sharg/version.hpp from platform test
4148
if (NOT HEADER_FILE_INCLUDE MATCHES "sharg/(std/|version.hpp)")
4249
file (APPEND "${HEADER_TARGET_SOURCE}"
43-
"
44-
#ifndef SHARG_DOXYGEN_ONLY
45-
#error \"Your header '${HEADER_FILE_INCLUDE}' file is missing #include <sharg/platform.hpp>\"
46-
#endif")
50+
"// sharg-header-test-platform-start\n"
51+
"#ifndef SHARG_DOXYGEN_ONLY\n"
52+
"#error \"Your header '${HEADER_FILE_INCLUDE}' file is missing #include <sharg/platform.hpp>\"\n"
53+
"#endif\n"
54+
"// sharg-header-test-platform-end\n\n")
4755
endif ()
4856

4957
# sharg/std/* must not include platform.hpp (and therefore any other sharg header)
5058
# See https://github.com/seqan/product_backlog/issues/135
5159
if (HEADER_FILE_INCLUDE MATCHES "sharg/std/")
5260
file (APPEND "${HEADER_TARGET_SOURCE}"
53-
"
54-
#ifdef SHARG_DOXYGEN_ONLY
55-
#error \"The standard header '${HEADER_FILE_INCLUDE}' file MUST NOT include any other sharg header\"
56-
#endif")
61+
"// sharg-header-test-no-platform-start\n"
62+
"#ifdef SHARG_DOXYGEN_ONLY\n"
63+
"#error \"The standard header '${HEADER_FILE_INCLUDE}' file MUST NOT include any other sharg header\"\n"
64+
"#endif\n"
65+
"// sharg-header-test-no-platform-end\n\n")
5766
endif ()
58-
59-
# test whether sharg has the visibility bug on lower gcc versions
60-
# https://github.com/seqan/seqan3/issues/1317
61-
if (NOT HEADER_FILE_INCLUDE MATCHES "sharg/version.hpp")
62-
file (APPEND "${HEADER_TARGET_SOURCE}"
63-
"
64-
#include <sharg/platform.hpp>
65-
class A{ int i{5}; };
66-
67-
template <typename t>
68-
concept private_bug = requires(t a){a.i;};
69-
70-
static_assert(!private_bug<A>, \"See https://github.com/seqan/seqan3/issues/1317\");")
71-
endif ()
72-
7367
endif ()
68+
69+
# cmake-format: on

test/sharg-test.cmake

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ include (FindPackageMessage)
3434

3535
option (SHARG_TEST_BUILD_OFFLINE "Skip the update step of external projects." OFF)
3636

37+
option (SHARG_WITH_WERROR "Report compiler warnings as errors." ON)
38+
3739
# ----------------------------------------------------------------------------
3840
# Paths to folders.
3941
# ----------------------------------------------------------------------------
@@ -54,13 +56,23 @@ list (APPEND CMAKE_MODULE_PATH "${SHARG_TEST_CMAKE_MODULE_DIR}")
5456
# libraries which are in common for **all** seqan3 tests
5557
if (NOT TARGET sharg::test)
5658
add_library (sharg_test INTERFACE)
57-
target_compile_options (sharg_test INTERFACE "-pedantic" "-Wall" "-Wextra" "-Werror")
59+
target_compile_options (sharg_test INTERFACE "-pedantic" "-Wall" "-Wextra")
60+
61+
if (SHARG_WITH_WERROR)
62+
target_compile_options (sharg_test INTERFACE "-Werror")
63+
message (STATUS "Building tests with -Werror.")
64+
endif ()
5865

59-
# GCC12 and above: Disable warning about std::hardware_destructive_interference_size not being ABI-stable.
6066
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
67+
# GCC12 and above: Disable warning about std::hardware_destructive_interference_size not being ABI-stable.
6168
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
6269
target_compile_options (sharg_test INTERFACE "-Wno-interference-size")
6370
endif ()
71+
72+
# Warn about failed return value optimization.
73+
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14)
74+
target_compile_options (sharg_test INTERFACE "-Wnrvo")
75+
endif ()
6476
endif ()
6577

6678
target_link_libraries (sharg_test INTERFACE "sharg::sharg" "pthread")
@@ -76,24 +88,6 @@ if (NOT TARGET sharg::test::unit)
7688
add_library (sharg::test::unit ALIAS sharg_test_unit)
7789
endif ()
7890

79-
# sharg::test::coverage specifies required flags, includes and libraries
80-
# needed for coverage test cases in sharg/test/coverage
81-
if (NOT TARGET sharg::test::coverage)
82-
add_library (sharg_test_coverage INTERFACE)
83-
target_compile_options (sharg_test_coverage INTERFACE "--coverage" "-fprofile-arcs" "-ftest-coverage")
84-
# -fprofile-abs-path requires at least gcc8, it forces gcov to report absolute instead of relative paths.
85-
# gcovr has trouble detecting the headers otherwise.
86-
# ccache is not aware of this option, so it needs to be skipped with `--ccache-skip`.
87-
find_program (CCACHE_PROGRAM ccache)
88-
if (CCACHE_PROGRAM)
89-
target_compile_options (sharg_test_coverage INTERFACE "--ccache-skip" "-fprofile-abs-path")
90-
else ()
91-
target_compile_options (sharg_test_coverage INTERFACE "-fprofile-abs-path")
92-
endif ()
93-
target_link_libraries (sharg_test_coverage INTERFACE "sharg::test::unit" "gcov")
94-
add_library (sharg::test::coverage ALIAS sharg_test_coverage)
95-
endif ()
96-
9791
# sharg::test::header specifies required flags, includes and libraries
9892
# needed for header test cases in sharg/test/header
9993
if (NOT TARGET sharg::test::header)

0 commit comments

Comments
 (0)