mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-07 01:06:54 +08:00
Use catch's test parser
This commit is contained in:
parent
21b397c2cb
commit
c902771f16
@ -117,6 +117,7 @@ configure_file(Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile)
|
|||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
include(cmake/Catch.cmake)
|
||||||
|
|
||||||
if(NOT MINGW)
|
if(NOT MINGW)
|
||||||
find_library(READLINE_LIBRARY NAMES readline PATH /usr/lib /usr/local/lib /opt/local/lib)
|
find_library(READLINE_LIBRARY NAMES readline PATH /usr/lib /usr/local/lib /opt/local/lib)
|
||||||
@ -337,37 +338,6 @@ endif()
|
|||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
|
|
||||||
# Add catch tests macro
|
|
||||||
macro(ADD_CATCH_TESTS executable)
|
|
||||||
if (MSVC)
|
|
||||||
file(TO_NATIVE_PATH "${QT_LIBRARY_DIR}" QT_LIB_PATH)
|
|
||||||
set(NEWPATH "${QT_LIB_PATH};$ENV{PATH}")
|
|
||||||
else()
|
|
||||||
set(NEWPATH $ENV{PATH})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
get_target_property(target_files ${executable} SOURCES)
|
|
||||||
|
|
||||||
foreach(source ${target_files})
|
|
||||||
if(NOT "${source}" MATCHES "/moc_.*cxx")
|
|
||||||
string(REGEX MATCH .*cpp source "${source}")
|
|
||||||
if(source)
|
|
||||||
file(READ "${source}" contents)
|
|
||||||
string(REGEX MATCHALL "TEST_CASE\\([ ]*\"[^\"]+\"" found_tests ${contents})
|
|
||||||
foreach(hit ${found_tests})
|
|
||||||
string(REGEX REPLACE "TEST_CASE\\([ ]*(\"[^\"]+\").*" "\\1" test_name ${hit})
|
|
||||||
add_test(compiled.${test_name} "${executable}" ${test_name})
|
|
||||||
set_tests_properties(compiled.${test_name} PROPERTIES TIMEOUT 660 ENVIRONMENT "PATH=${NEWPATH}")
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
option(UNIT_TEST_LIGHT "Unit tests light (expect module loading failures)" FALSE)
|
option(UNIT_TEST_LIGHT "Unit tests light (expect module loading failures)" FALSE)
|
||||||
|
|
||||||
add_test(version_check chai -c "if(\"\\\${ version() };\\\${version_major()};\\\${version_minor()};\\\${version_patch()}\" != \"${CHAI_VERSION};${CPACK_PACKAGE_VERSION_MAJOR};${CPACK_PACKAGE_VERSION_MINOR};${CPACK_PACKAGE_VERSION_PATCH}\") { exit(-1) }")
|
add_test(version_check chai -c "if(\"\\\${ version() };\\\${version_major()};\\\${version_minor()};\\\${version_patch()}\" != \"${CHAI_VERSION};${CPACK_PACKAGE_VERSION_MAJOR};${CPACK_PACKAGE_VERSION_MINOR};${CPACK_PACKAGE_VERSION_PATCH}\") { exit(-1) }")
|
||||||
@ -425,7 +395,7 @@ if(BUILD_TESTING)
|
|||||||
if(NOT UNIT_TEST_LIGHT)
|
if(NOT UNIT_TEST_LIGHT)
|
||||||
add_executable(compiled_tests unittests/compiled_tests.cpp)
|
add_executable(compiled_tests unittests/compiled_tests.cpp)
|
||||||
target_link_libraries(compiled_tests ${LIBS} ${CHAISCRIPT_LIBS})
|
target_link_libraries(compiled_tests ${LIBS} ${CHAISCRIPT_LIBS})
|
||||||
ADD_CATCH_TESTS(compiled_tests)
|
catch_discover_tests(compiled_tests)
|
||||||
|
|
||||||
add_executable(static_chaiscript_test unittests/static_chaiscript.cpp)
|
add_executable(static_chaiscript_test unittests/static_chaiscript.cpp)
|
||||||
target_link_libraries(static_chaiscript_test ${LIBS})
|
target_link_libraries(static_chaiscript_test ${LIBS})
|
||||||
|
|||||||
@ -50,23 +50,21 @@ string(REPLACE "\n" ";" output "${output}")
|
|||||||
|
|
||||||
# Parse output
|
# Parse output
|
||||||
foreach(line ${output})
|
foreach(line ${output})
|
||||||
# Test name; strip spaces to get just the name...
|
|
||||||
string(REGEX REPLACE " +" "" test "${line}")
|
|
||||||
# ...and add to script
|
# ...and add to script
|
||||||
add_command(add_test
|
add_command(add_test
|
||||||
"${prefix}${test}${suffix}"
|
"${prefix}${line}${suffix}"
|
||||||
${TEST_EXECUTOR}
|
${TEST_EXECUTOR}
|
||||||
"${TEST_EXECUTABLE}"
|
"${TEST_EXECUTABLE}"
|
||||||
"${test}"
|
"${line}"
|
||||||
${extra_args}
|
${extra_args}
|
||||||
)
|
)
|
||||||
add_command(set_tests_properties
|
add_command(set_tests_properties
|
||||||
"${prefix}${test}${suffix}"
|
"${prefix}${line}${suffix}"
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
||||||
${properties}
|
${properties}
|
||||||
)
|
)
|
||||||
list(APPEND tests "${prefix}${test}${suffix}")
|
list(APPEND tests "${prefix}${line}${suffix}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Create a list of all discovered tests, which users may use to e.g. set
|
# Create a list of all discovered tests, which users may use to e.g. set
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user