Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnitTests: Fix compilation error on MSVC. Update doctest to v2.4.11. #491

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Tests/Dependencies/doctest/cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compiler_flags(-Wnoexcept)
endif()

if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
add_compiler_flags(-Wno-missing-field-initializers)
endif()

# no way to silence it in the expression decomposition macros: _Pragma() in macros doesn't work for the c++ front-end of g++
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69543
Expand Down Expand Up @@ -179,7 +183,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compiler_flags(-Wno-c++98-compat-pedantic)
add_compiler_flags(-Wno-c++98-compat-bind-to-temporary-copy)
add_compiler_flags(-Wno-c++98-compat-local-type-template-args)
add_compiler_flags(-Qunused-arguments -fcolor-diagnostics) # needed for ccache integration on travis
add_compiler_flags(-Qunused-arguments -fcolor-diagnostics) # needed for ccache integration
endif()

if(MSVC)
Expand All @@ -191,6 +195,7 @@ if(MSVC)
add_compiler_flags(
/wd4514 # unreferenced inline function has been removed
/wd4571 # SEH related
/wd5264 # const variable is not used
/wd4710 # function not inlined
/wd4711 # function 'x' selected for automatic inline expansion

Expand Down
18 changes: 16 additions & 2 deletions Tests/Dependencies/doctest/cmake/doctest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ same as the doctest name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
[TEST_PREFIX prefix]
[TEST_SUFFIX suffix]
[PROPERTIES name1 value1...]
[ADD_LABELS value]
[TEST_LIST var]
[JUNIT_OUTPUT_DIR dir]
)

``doctest_discover_tests`` sets up a post-build command on the test executable
Expand Down Expand Up @@ -84,21 +86,31 @@ same as the doctest name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
Specifies additional properties to be set on all tests discovered by this
invocation of ``doctest_discover_tests``.

``ADD_LABELS value``
Specifies if the test labels should be set automatically.

``TEST_LIST var``
Make the list of tests available in the variable ``var``, rather than the
default ``<target>_TESTS``. This can be useful when the same test
executable is being used in multiple calls to ``doctest_discover_tests()``.
Note that this variable is only available in CTest.

``JUNIT_OUTPUT_DIR dir``
If specified, the parameter is passed along with ``--reporters=junit``
and ``--out=`` to the test executable. The actual file name is the same
as the test target, including prefix and suffix. This should be used
instead of EXTRA_ARGS to avoid race conditions writing the XML result
output when using parallel test execution.

#]=======================================================================]

#------------------------------------------------------------------------------
function(doctest_discover_tests TARGET)
cmake_parse_arguments(
""
""
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST"
"TEST_SPEC;EXTRA_ARGS;PROPERTIES"
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;JUNIT_OUTPUT_DIR"
"TEST_SPEC;EXTRA_ARGS;PROPERTIES;ADD_LABELS"
${ARGN}
)

Expand Down Expand Up @@ -131,9 +143,11 @@ function(doctest_discover_tests TARGET)
-D "TEST_SPEC=${_TEST_SPEC}"
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
-D "TEST_PROPERTIES=${_PROPERTIES}"
-D "TEST_ADD_LABELS=${_ADD_LABELS}"
-D "TEST_PREFIX=${_TEST_PREFIX}"
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
-D "TEST_LIST=${_TEST_LIST}"
-D "TEST_JUNIT_OUTPUT_DIR=${_JUNIT_OUTPUT_DIR}"
-D "CTEST_FILE=${ctest_tests_file}"
-P "${_DOCTEST_DISCOVER_TESTS_SCRIPT}"
VERBATIM
Expand Down
39 changes: 39 additions & 0 deletions Tests/Dependencies/doctest/cmake/doctestAddTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set(suffix "${TEST_SUFFIX}")
set(spec ${TEST_SPEC})
set(extra_args ${TEST_EXTRA_ARGS})
set(properties ${TEST_PROPERTIES})
set(add_labels ${TEST_ADD_LABELS})
set(junit_output_dir "${TEST_JUNIT_OUTPUT_DIR}")
set(script)
set(suite)
set(tests)
Expand Down Expand Up @@ -37,6 +39,7 @@ execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-cases
OUTPUT_VARIABLE output
RESULT_VARIABLE result
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
)
if(NOT ${result} EQUAL 0)
message(FATAL_ERROR
Expand All @@ -54,6 +57,39 @@ foreach(line ${output})
continue()
endif()
set(test ${line})
set(labels "")
if(${add_labels})
# get test suite that test belongs to
execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" --test-case=${test} --list-test-suites
OUTPUT_VARIABLE labeloutput
RESULT_VARIABLE labelresult
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
)
if(NOT ${labelresult} EQUAL 0)
message(FATAL_ERROR
"Error running test executable '${TEST_EXECUTABLE}':\n"
" Result: ${labelresult}\n"
" Output: ${labeloutput}\n"
)
endif()

string(REPLACE "\n" ";" labeloutput "${labeloutput}")
foreach(labelline ${labeloutput})
if("${labelline}" STREQUAL "===============================================================================" OR "${labelline}" MATCHES [==[^\[doctest\] ]==])
continue()
endif()
list(APPEND labels ${labelline})
endforeach()
endif()

if(NOT "${junit_output_dir}" STREQUAL "")
# turn testname into a valid filename by replacing all special characters with "-"
string(REGEX REPLACE "[/\\:\"|<>]" "-" test_filename "${test}")
set(TEST_JUNIT_OUTPUT_PARAM "--reporters=junit" "--out=${junit_output_dir}/${prefix}${test_filename}${suffix}.xml")
else()
unset(TEST_JUNIT_OUTPUT_PARAM)
endif()
# use escape commas to handle properly test cases with commas inside the name
string(REPLACE "," "\\," test_name ${test})
# ...and add to script
Expand All @@ -62,14 +98,17 @@ foreach(line ${output})
${TEST_EXECUTOR}
"${TEST_EXECUTABLE}"
"--test-case=${test_name}"
"${TEST_JUNIT_OUTPUT_PARAM}"
${extra_args}
)
add_command(set_tests_properties
"${prefix}${test}${suffix}"
PROPERTIES
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
${properties}
LABELS ${labels}
)
unset(labels)
list(APPEND tests "${prefix}${test}${suffix}")
endforeach()

Expand Down
Loading