Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f67d351

Browse files
committed
update third party libraries
1 parent 63f33d5 commit f67d351

File tree

6 files changed

+310
-17
lines changed

6 files changed

+310
-17
lines changed

.trunk/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.trunk/trunk.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

cmake/doctest.cmake

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or
2+
# https://cmake.org/licensing for details.
3+
4+
#[=======================================================================[.rst:
5+
doctest
6+
-----
7+
8+
This module defines a function to help use the doctest test framework.
9+
10+
The :command:`doctest_discover_tests` discovers tests by asking the compiled test
11+
executable to enumerate its tests. This does not require CMake to be re-run
12+
when tests change. However, it may not work in a cross-compiling environment,
13+
and setting test properties is less convenient.
14+
15+
This command is intended to replace use of :command:`add_test` to register
16+
tests, and will create a separate CTest test for each doctest test case. Note
17+
that this is in some cases less efficient, as common set-up and tear-down logic
18+
cannot be shared by multiple test cases executing in the same instance.
19+
However, it provides more fine-grained pass/fail information to CTest, which is
20+
usually considered as more beneficial. By default, the CTest test name is the
21+
same as the doctest name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
22+
23+
.. command:: doctest_discover_tests
24+
25+
Automatically add tests with CTest by querying the compiled test executable
26+
for available tests::
27+
28+
doctest_discover_tests(target
29+
[TEST_SPEC arg1...]
30+
[EXTRA_ARGS arg1...]
31+
[WORKING_DIRECTORY dir]
32+
[TEST_PREFIX prefix]
33+
[TEST_SUFFIX suffix]
34+
[PROPERTIES name1 value1...]
35+
[ADD_LABELS value]
36+
[TEST_LIST var]
37+
[JUNIT_OUTPUT_DIR dir]
38+
)
39+
40+
``doctest_discover_tests`` sets up a post-build command on the test executable
41+
that generates the list of tests by parsing the output from running the test
42+
with the ``--list-test-cases`` argument. This ensures that the full
43+
list of tests is obtained. Since test discovery occurs at build time, it is
44+
not necessary to re-run CMake when the list of tests changes.
45+
However, it requires that :prop_tgt:`CROSSCOMPILING_EMULATOR` is properly set
46+
in order to function in a cross-compiling environment.
47+
48+
Additionally, setting properties on tests is somewhat less convenient, since
49+
the tests are not available at CMake time. Additional test properties may be
50+
assigned to the set of tests as a whole using the ``PROPERTIES`` option. If
51+
more fine-grained test control is needed, custom content may be provided
52+
through an external CTest script using the :prop_dir:`TEST_INCLUDE_FILES`
53+
directory property. The set of discovered tests is made accessible to such a
54+
script via the ``<target>_TESTS`` variable.
55+
56+
The options are:
57+
58+
``target``
59+
Specifies the doctest executable, which must be a known CMake executable
60+
target. CMake will substitute the location of the built executable when
61+
running the test.
62+
63+
``TEST_SPEC arg1...``
64+
Specifies test cases, wildcarded test cases, tags and tag expressions to
65+
pass to the doctest executable with the ``--list-test-cases`` argument.
66+
67+
``EXTRA_ARGS arg1...``
68+
Any extra arguments to pass on the command line to each test case.
69+
70+
``WORKING_DIRECTORY dir``
71+
Specifies the directory in which to run the discovered test cases. If this
72+
option is not provided, the current binary directory is used.
73+
74+
``TEST_PREFIX prefix``
75+
Specifies a ``prefix`` to be prepended to the name of each discovered test
76+
case. This can be useful when the same test executable is being used in
77+
multiple calls to ``doctest_discover_tests()`` but with different
78+
``TEST_SPEC`` or ``EXTRA_ARGS``.
79+
80+
``TEST_SUFFIX suffix``
81+
Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of
82+
every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may
83+
be specified.
84+
85+
``PROPERTIES name1 value1...``
86+
Specifies additional properties to be set on all tests discovered by this
87+
invocation of ``doctest_discover_tests``.
88+
89+
``ADD_LABELS value``
90+
Specifies if the test labels should be set automatically.
91+
92+
``TEST_LIST var``
93+
Make the list of tests available in the variable ``var``, rather than the
94+
default ``<target>_TESTS``. This can be useful when the same test
95+
executable is being used in multiple calls to ``doctest_discover_tests()``.
96+
Note that this variable is only available in CTest.
97+
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+
105+
#]=======================================================================]
106+
107+
# ------------------------------------------------------------------------------
108+
function(doctest_discover_tests TARGET)
109+
cmake_parse_arguments(
110+
"" "" "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;JUNIT_OUTPUT_DIR"
111+
"TEST_SPEC;EXTRA_ARGS;PROPERTIES;ADD_LABELS" ${ARGN}
112+
)
113+
114+
if(NOT _WORKING_DIRECTORY)
115+
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
116+
endif()
117+
if(NOT _TEST_LIST)
118+
set(_TEST_LIST ${TARGET}_TESTS)
119+
endif()
120+
121+
# Generate a unique name based on the extra arguments
122+
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS}")
123+
string(SUBSTRING ${args_hash} 0 7 args_hash)
124+
125+
# Define rule to generate test list for aforementioned test executable
126+
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include-${args_hash}.cmake")
127+
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests-${args_hash}.cmake")
128+
get_property(
129+
crosscompiling_emulator
130+
TARGET ${TARGET}
131+
PROPERTY CROSSCOMPILING_EMULATOR
132+
)
133+
add_custom_command(
134+
TARGET ${TARGET}
135+
POST_BUILD
136+
BYPRODUCTS "${ctest_tests_file}"
137+
COMMAND
138+
"${CMAKE_COMMAND}" -D "TEST_TARGET=${TARGET}" -D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>" -D
139+
"TEST_EXECUTOR=${crosscompiling_emulator}" -D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}" -D
140+
"TEST_SPEC=${_TEST_SPEC}" -D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}" -D
141+
"TEST_PROPERTIES=${_PROPERTIES}" -D "TEST_ADD_LABELS=${_ADD_LABELS}" -D
142+
"TEST_PREFIX=${_TEST_PREFIX}" -D "TEST_SUFFIX=${_TEST_SUFFIX}" -D "TEST_LIST=${_TEST_LIST}" -D
143+
"TEST_JUNIT_OUTPUT_DIR=${_JUNIT_OUTPUT_DIR}" -D "CTEST_FILE=${ctest_tests_file}" -P
144+
"${_DOCTEST_DISCOVER_TESTS_SCRIPT}"
145+
VERBATIM
146+
)
147+
148+
file(
149+
WRITE "${ctest_include_file}"
150+
"if(EXISTS \"${ctest_tests_file}\")\n" " include(\"${ctest_tests_file}\")\n" "else()\n"
151+
" add_test(${TARGET}_NOT_BUILT-${args_hash} ${TARGET}_NOT_BUILT-${args_hash})\n" "endif()\n"
152+
)
153+
154+
if(NOT CMAKE_VERSION VERSION_LESS 3.10)
155+
# Add discovered tests to directory TEST_INCLUDE_FILES
156+
set_property(
157+
DIRECTORY
158+
APPEND
159+
PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
160+
)
161+
else()
162+
# Add discovered tests as directory TEST_INCLUDE_FILE if possible
163+
get_property(
164+
test_include_file_set
165+
DIRECTORY
166+
PROPERTY TEST_INCLUDE_FILE
167+
SET
168+
)
169+
if(NOT ${test_include_file_set})
170+
set_property(DIRECTORY PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}")
171+
else()
172+
message(FATAL_ERROR "Cannot set more than one TEST_INCLUDE_FILE")
173+
endif()
174+
endif()
175+
176+
endfunction()
177+
178+
# ##################################################################################################
179+
180+
set(_DOCTEST_DISCOVER_TESTS_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/doctestAddTests.cmake)

cmake/doctestAddTests.cmake

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or
2+
# https://cmake.org/licensing for details.
3+
4+
set(prefix "${TEST_PREFIX}")
5+
set(suffix "${TEST_SUFFIX}")
6+
set(spec ${TEST_SPEC})
7+
set(extra_args ${TEST_EXTRA_ARGS})
8+
set(properties ${TEST_PROPERTIES})
9+
set(add_labels ${TEST_ADD_LABELS})
10+
set(junit_output_dir "${TEST_JUNIT_OUTPUT_DIR}")
11+
set(script)
12+
set(suite)
13+
set(tests)
14+
15+
function(add_command NAME)
16+
set(_args "")
17+
foreach(_arg ${ARGN})
18+
if(_arg MATCHES "[^-./:a-zA-Z0-9_]")
19+
set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument
20+
else()
21+
set(_args "${_args} ${_arg}")
22+
endif()
23+
endforeach()
24+
set(script
25+
"${script}${NAME}(${_args})\n"
26+
PARENT_SCOPE
27+
)
28+
endfunction()
29+
30+
# Run test executable to get list of available tests
31+
if(NOT EXISTS "${TEST_EXECUTABLE}")
32+
message(FATAL_ERROR "Specified test executable '${TEST_EXECUTABLE}' does not exist")
33+
endif()
34+
35+
if("${spec}" MATCHES .)
36+
set(spec "--test-case=${spec}")
37+
endif()
38+
39+
execute_process(
40+
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-cases
41+
OUTPUT_VARIABLE output
42+
RESULT_VARIABLE result
43+
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
44+
)
45+
if(NOT ${result} EQUAL 0)
46+
message(FATAL_ERROR "Error running test executable '${TEST_EXECUTABLE}':\n"
47+
" Result: ${result}\n" " Output: ${output}\n"
48+
)
49+
endif()
50+
51+
string(REPLACE "\n" ";" output "${output}")
52+
53+
# Parse output
54+
foreach(line ${output})
55+
if("${line}" STREQUAL
56+
"==============================================================================="
57+
OR "${line}" MATCHES [==[^\[doctest\] ]==]
58+
)
59+
continue()
60+
endif()
61+
set(test ${line})
62+
set(labels "")
63+
if(${add_labels})
64+
# get test suite that test belongs to
65+
execute_process(
66+
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" --test-case=${test} --list-test-suites
67+
OUTPUT_VARIABLE labeloutput
68+
RESULT_VARIABLE labelresult
69+
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
70+
)
71+
if(NOT ${labelresult} EQUAL 0)
72+
message(FATAL_ERROR "Error running test executable '${TEST_EXECUTABLE}':\n"
73+
" Result: ${labelresult}\n" " Output: ${labeloutput}\n"
74+
)
75+
endif()
76+
77+
string(REPLACE "\n" ";" labeloutput "${labeloutput}")
78+
foreach(labelline ${labeloutput})
79+
if("${labelline}" STREQUAL
80+
"==============================================================================="
81+
OR "${labelline}" MATCHES [==[^\[doctest\] ]==]
82+
)
83+
continue()
84+
endif()
85+
list(APPEND labels ${labelline})
86+
endforeach()
87+
endif()
88+
89+
if(NOT "${junit_output_dir}" STREQUAL "")
90+
# turn testname into a valid filename by replacing all special characters with "-"
91+
string(REGEX REPLACE "[/\\:\"|<>]" "-" test_filename "${test}")
92+
set(TEST_JUNIT_OUTPUT_PARAM "--reporters=junit"
93+
"--out=${junit_output_dir}/${prefix}${test_filename}${suffix}.xml"
94+
)
95+
else()
96+
unset(TEST_JUNIT_OUTPUT_PARAM)
97+
endif()
98+
# use escape commas to handle properly test cases with commas inside the name
99+
string(REPLACE "," "\\," test_name ${test})
100+
# ...and add to script
101+
add_command(
102+
add_test
103+
"${prefix}${test}${suffix}"
104+
${TEST_EXECUTOR}
105+
"${TEST_EXECUTABLE}"
106+
"--test-case=${test_name}"
107+
"${TEST_JUNIT_OUTPUT_PARAM}"
108+
${extra_args}
109+
)
110+
add_command(
111+
set_tests_properties
112+
"${prefix}${test}${suffix}"
113+
PROPERTIES
114+
WORKING_DIRECTORY
115+
"${TEST_WORKING_DIR}"
116+
${properties}
117+
LABELS
118+
${labels}
119+
)
120+
unset(labels)
121+
list(APPEND tests "${prefix}${test}${suffix}")
122+
endforeach()
123+
124+
# Create a list of all discovered tests, which users may use to e.g. set properties on the tests
125+
add_command(set ${TEST_LIST} ${tests})
126+
127+
# Write CTest script
128+
file(WRITE "${CTEST_FILE}" "${script}")

specific.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CPMAddPackage(
22
NAME fmt
3-
GIT_TAG 9.1.0
3+
GIT_TAG 10.2.1
44
GITHUB_REPOSITORY fmtlib/fmt
55
OPTIONS "FMT_INSTALL YES" # create an installable target
66
)

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
55

66
# ---- Dependencies ----
77

8-
CPMAddPackage("gh:doctest/doctest#v2.4.9")
8+
CPMAddPackage("gh:doctest/doctest#v2.4.11")
99
CPMAddPackage("gh:TheLartians/[email protected]")
1010

1111
# if(TEST_INSTALLED_VERSION) find_package(${PROJECT_NAME} REQUIRED) else() CPMAddPackage(NAME

0 commit comments

Comments
 (0)