Skip to content

Commit b0971c4

Browse files
authored
Update doctest to version 2.4.9 (#54)
1 parent 167571d commit b0971c4

File tree

8 files changed

+2617
-1440
lines changed

8 files changed

+2617
-1440
lines changed

test/doctest/Config.cmake.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if(NOT TARGET doctest::doctest)
2+
# Provide path for scripts
3+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
4+
5+
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
6+
endif()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set(doctest_include_folder "${CMAKE_CURRENT_LIST_DIR}/../../doctest/")
2+
3+
file(READ ${doctest_include_folder}/parts/doctest_fwd.h fwd)
4+
file(READ ${doctest_include_folder}/parts/doctest.cpp impl)
5+
6+
file(WRITE ${doctest_include_folder}/doctest.h "// ====================================================================== lgtm [cpp/missing-header-guard]\n")
7+
file(APPEND ${doctest_include_folder}/doctest.h "// == DO NOT MODIFY THIS FILE BY HAND - IT IS AUTO GENERATED BY CMAKE! ==\n")
8+
file(APPEND ${doctest_include_folder}/doctest.h "// ======================================================================\n")
9+
file(APPEND ${doctest_include_folder}/doctest.h "${fwd}\n")
10+
file(APPEND ${doctest_include_folder}/doctest.h "#ifndef DOCTEST_SINGLE_HEADER\n")
11+
file(APPEND ${doctest_include_folder}/doctest.h "#define DOCTEST_SINGLE_HEADER\n")
12+
file(APPEND ${doctest_include_folder}/doctest.h "#endif // DOCTEST_SINGLE_HEADER\n")
13+
file(APPEND ${doctest_include_folder}/doctest.h "\n${impl}")

test/doctest/common.cmake

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
include(CMakeParseArguments)
2+
3+
# cache this for use inside of the function
4+
set(CURRENT_LIST_DIR_CACHED ${CMAKE_CURRENT_LIST_DIR})
5+
6+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
7+
8+
enable_testing()
9+
10+
find_package(Threads)
11+
12+
set(DOCTEST_TEST_MODE "COMPARE" CACHE STRING "Test mode - normal/run through valgrind/collect output/compare with output")
13+
set_property(CACHE DOCTEST_TEST_MODE PROPERTY STRINGS "NORMAL;VALGRIND;COLLECT;COMPARE")
14+
15+
function(doctest_add_test_impl)
16+
cmake_parse_arguments(ARG "NO_VALGRIND;NO_OUTPUT;XML_OUTPUT;JUNIT_OUTPUT" "NAME" "COMMAND" ${ARGN})
17+
if(NOT "${ARG_UNPARSED_ARGUMENTS}" STREQUAL "" OR "${ARG_NAME}" STREQUAL "" OR "${ARG_COMMAND}" STREQUAL "")
18+
message(FATAL_ERROR "doctest_add_test() called with wrong options!")
19+
endif()
20+
21+
set(the_test_mode NORMAL)
22+
23+
# construct the command that will be called by the exec_test.cmake script
24+
set(the_command "")
25+
if(${DOCTEST_TEST_MODE} STREQUAL "VALGRIND" AND NOT ARG_NO_VALGRIND)
26+
set(the_test_mode VALGRIND)
27+
set(the_command "valgrind -v --leak-check=full --track-origins=yes --error-exitcode=1")
28+
endif()
29+
foreach(cur ${ARG_COMMAND})
30+
set(the_command "${the_command} ${cur}")
31+
endforeach()
32+
if(ARG_XML_OUTPUT)
33+
set(the_command "${the_command} --reporters=xml")
34+
set(ARG_NAME ${ARG_NAME}_xml)
35+
endif()
36+
if(ARG_JUNIT_OUTPUT)
37+
set(the_command "${the_command} --reporters=junit")
38+
set(ARG_NAME ${ARG_NAME}_junit)
39+
endif()
40+
41+
# append the argument for removing paths from filenames in the output so tests give the same output everywhere
42+
set(the_command "${the_command} --dt-no-path-filenames=1")
43+
# append the argument for substituting source line numbers with 0 in the output so tests give the same output when lines change a bit
44+
set(the_command "${the_command} --dt-no-line-numbers=1")
45+
# append the argument for ignoring the exit code of the test programs because some are intended to have failing tests
46+
set(the_command "${the_command} --dt-no-exitcode=1")
47+
# append the argument for using the same line format in the output - so gcc/non-gcc builds have the same output
48+
set(the_command "${the_command} --dt-gnu-file-line=0")
49+
# append the argument for skipping any time-related output so that the reference output from reporters is stable on CI
50+
set(the_command "${the_command} --dt-no-time-in-output=1")
51+
52+
string(STRIP ${the_command} the_command)
53+
54+
if(${DOCTEST_TEST_MODE} STREQUAL "COLLECT" OR ${DOCTEST_TEST_MODE} STREQUAL "COMPARE")
55+
if(NOT ARG_NO_OUTPUT)
56+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test_output/)
57+
set(the_test_mode ${DOCTEST_TEST_MODE})
58+
list(APPEND ADDITIONAL_FLAGS -DTEST_OUTPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/test_output/${ARG_NAME}.txt)
59+
list(APPEND ADDITIONAL_FLAGS -DTEST_TEMP_FILE=${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/temp_test_output_${ARG_NAME}.txt)
60+
endif()
61+
endif()
62+
63+
list(APPEND ADDITIONAL_FLAGS -DTEST_MODE=${the_test_mode})
64+
65+
add_test(NAME ${ARG_NAME} COMMAND ${CMAKE_COMMAND} -DCOMMAND=${the_command} ${ADDITIONAL_FLAGS} -P ${CURRENT_LIST_DIR_CACHED}/exec_test.cmake)
66+
endfunction()
67+
68+
# a custom version of add_test() to suite my needs
69+
function(doctest_add_test)
70+
doctest_add_test_impl(${ARGN})
71+
doctest_add_test_impl(${ARGN} XML_OUTPUT)
72+
doctest_add_test_impl(${ARGN} JUNIT_OUTPUT)
73+
endfunction()
74+
75+
macro(add_compiler_flags)
76+
foreach(flag ${ARGV})
77+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
78+
endforeach()
79+
endmacro()
80+
81+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
82+
add_compiler_flags(-Werror)
83+
add_compiler_flags(-fstrict-aliasing)
84+
85+
# The following options are not valid when clang-cl is used.
86+
if(NOT MSVC)
87+
add_compiler_flags(-pedantic)
88+
add_compiler_flags(-pedantic-errors)
89+
add_compiler_flags(-fvisibility=hidden)
90+
endif()
91+
endif()
92+
93+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
94+
#add_compiler_flags(-Wno-unknown-pragmas)
95+
add_compiler_flags(-Wall)
96+
add_compiler_flags(-Wextra)
97+
add_compiler_flags(-fdiagnostics-show-option)
98+
add_compiler_flags(-Wconversion)
99+
add_compiler_flags(-Wold-style-cast)
100+
add_compiler_flags(-Wfloat-equal)
101+
add_compiler_flags(-Wlogical-op)
102+
add_compiler_flags(-Wundef)
103+
add_compiler_flags(-Wredundant-decls)
104+
add_compiler_flags(-Wshadow)
105+
add_compiler_flags(-Wstrict-overflow=5)
106+
add_compiler_flags(-Wwrite-strings)
107+
add_compiler_flags(-Wpointer-arith)
108+
add_compiler_flags(-Wcast-qual)
109+
add_compiler_flags(-Wformat=2)
110+
add_compiler_flags(-Wswitch-default)
111+
add_compiler_flags(-Wmissing-include-dirs)
112+
add_compiler_flags(-Wcast-align)
113+
add_compiler_flags(-Wswitch-enum)
114+
add_compiler_flags(-Wnon-virtual-dtor)
115+
add_compiler_flags(-Wctor-dtor-privacy)
116+
add_compiler_flags(-Wsign-conversion)
117+
add_compiler_flags(-Wdisabled-optimization)
118+
add_compiler_flags(-Weffc++)
119+
add_compiler_flags(-Winvalid-pch)
120+
add_compiler_flags(-Wmissing-declarations)
121+
add_compiler_flags(-Woverloaded-virtual)
122+
add_compiler_flags(-Wunused-but-set-variable)
123+
add_compiler_flags(-Wunused-result)
124+
125+
# add_compiler_flags(-Wsuggest-override)
126+
# add_compiler_flags(-Wmultiple-inheritance)
127+
# add_compiler_flags(-Wcatch-value)
128+
# add_compiler_flags(-Wsuggest-attribute=cold)
129+
# add_compiler_flags(-Wsuggest-attribute=const)
130+
# add_compiler_flags(-Wsuggest-attribute=format)
131+
# add_compiler_flags(-Wsuggest-attribute=malloc)
132+
# add_compiler_flags(-Wsuggest-attribute=noreturn)
133+
# add_compiler_flags(-Wsuggest-attribute=pure)
134+
# add_compiler_flags(-Wsuggest-final-methods)
135+
# add_compiler_flags(-Wsuggest-final-types)
136+
137+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
138+
add_compiler_flags(-Wnoexcept)
139+
endif()
140+
141+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
142+
add_compiler_flags(-Wno-missing-field-initializers)
143+
endif()
144+
145+
# no way to silence it in the expression decomposition macros: _Pragma() in macros doesn't work for the c++ front-end of g++
146+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
147+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69543
148+
# Also the warning is completely worthless nowadays - https://stackoverflow.com/questions/14016993
149+
#add_compiler_flags(-Waggregate-return)
150+
151+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
152+
add_compiler_flags(-Wdouble-promotion)
153+
add_compiler_flags(-Wtrampolines)
154+
add_compiler_flags(-Wzero-as-null-pointer-constant)
155+
add_compiler_flags(-Wuseless-cast)
156+
add_compiler_flags(-Wvector-operation-performance)
157+
endif()
158+
159+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
160+
add_compiler_flags(-Wshift-overflow=2)
161+
add_compiler_flags(-Wnull-dereference)
162+
add_compiler_flags(-Wduplicated-cond)
163+
endif()
164+
165+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
166+
add_compiler_flags(-Walloc-zero)
167+
add_compiler_flags(-Walloca)
168+
add_compiler_flags(-Wduplicated-branches)
169+
endif()
170+
171+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
172+
add_compiler_flags(-Wcast-align=strict)
173+
endif()
174+
endif()
175+
176+
# necessary for some older compilers which don't default to C++11
177+
set(CMAKE_CXX_STANDARD 11)
178+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
179+
180+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
181+
add_compiler_flags(-Weverything)
182+
add_compiler_flags(-Wno-c++98-compat)
183+
add_compiler_flags(-Wno-c++98-compat-pedantic)
184+
add_compiler_flags(-Wno-c++98-compat-bind-to-temporary-copy)
185+
add_compiler_flags(-Wno-c++98-compat-local-type-template-args)
186+
add_compiler_flags(-Qunused-arguments -fcolor-diagnostics) # needed for ccache integration
187+
endif()
188+
189+
if(MSVC)
190+
add_compiler_flags(/std:c++latest) # for post c++14 updates in MSVC
191+
add_compiler_flags(/permissive-) # force standard conformance - this is the better flag than /Za
192+
add_compiler_flags(/WX)
193+
add_compiler_flags(/Wall) # turns on warnings from levels 1 through 4 which are off by default - https://msdn.microsoft.com/en-us/library/23k5d385.aspx
194+
195+
add_compiler_flags(
196+
/wd4514 # unreferenced inline function has been removed
197+
/wd4571 # SEH related
198+
/wd4710 # function not inlined
199+
/wd4711 # function 'x' selected for automatic inline expansion
200+
201+
/wd4616 # invalid compiler warnings - https://msdn.microsoft.com/en-us/library/t7ab6xtd.aspx
202+
/wd4619 # invalid compiler warnings - https://msdn.microsoft.com/en-us/library/tacee08d.aspx
203+
204+
#/wd4820 # padding in structs
205+
#/wd4625 # copy constructor was implicitly defined as deleted
206+
#/wd4626 # assignment operator was implicitly defined as deleted
207+
#/wd5027 # move assignment operator was implicitly defined as deleted
208+
#/wd5026 # move constructor was implicitly defined as deleted
209+
#/wd4623 # default constructor was implicitly defined as deleted
210+
)
211+
endif()

test/doctest/doctest.cmake

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ same as the doctest name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
3232
[TEST_PREFIX prefix]
3333
[TEST_SUFFIX suffix]
3434
[PROPERTIES name1 value1...]
35+
[ADD_LABELS value]
3536
[TEST_LIST var]
37+
[JUNIT_OUTPUT_DIR dir]
3638
)
3739
3840
``doctest_discover_tests`` sets up a post-build command on the test executable
@@ -84,21 +86,31 @@ same as the doctest name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
8486
Specifies additional properties to be set on all tests discovered by this
8587
invocation of ``doctest_discover_tests``.
8688
89+
``ADD_LABELS value``
90+
Specifies if the test labels should be set automatically.
91+
8792
``TEST_LIST var``
8893
Make the list of tests available in the variable ``var``, rather than the
8994
default ``<target>_TESTS``. This can be useful when the same test
9095
executable is being used in multiple calls to ``doctest_discover_tests()``.
9196
Note that this variable is only available in CTest.
9297
98+
``JUNIT_OUTPUT_DIR dir``
99+
If specified, the parameter is passed along with ``--reporters=junit``
100+
and ``--out=`` to the test executable. The actual file name is the same
101+
as the test target, including prefix and suffix. This should be used
102+
instead of EXTRA_ARGS to avoid race conditions writing the XML result
103+
output when using parallel test execution.
104+
93105
#]=======================================================================]
94106

95107
#------------------------------------------------------------------------------
96108
function(doctest_discover_tests TARGET)
97109
cmake_parse_arguments(
98110
""
99111
""
100-
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST"
101-
"TEST_SPEC;EXTRA_ARGS;PROPERTIES"
112+
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;JUNIT_OUTPUT_DIR"
113+
"TEST_SPEC;EXTRA_ARGS;PROPERTIES;ADD_LABELS"
102114
${ARGN}
103115
)
104116

@@ -131,9 +143,11 @@ function(doctest_discover_tests TARGET)
131143
-D "TEST_SPEC=${_TEST_SPEC}"
132144
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
133145
-D "TEST_PROPERTIES=${_PROPERTIES}"
146+
-D "TEST_ADD_LABELS=${_ADD_LABELS}"
134147
-D "TEST_PREFIX=${_TEST_PREFIX}"
135148
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
136149
-D "TEST_LIST=${_TEST_LIST}"
150+
-D "TEST_JUNIT_OUTPUT_DIR=${_JUNIT_OUTPUT_DIR}"
137151
-D "CTEST_FILE=${ctest_tests_file}"
138152
-P "${_DOCTEST_DISCOVER_TESTS_SCRIPT}"
139153
VERBATIM

0 commit comments

Comments
 (0)