From c902771f161ca5d80828803635eb8f9e35ef7665 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 19 Feb 2018 16:36:08 -0700 Subject: [PATCH] Use catch's test parser --- CMakeLists.txt | 34 ++-------------------------------- cmake/CatchAddTests.cmake | 10 ++++------ 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74f7e614..af4fd810 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,7 @@ configure_file(Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile) include(CTest) include(CPack) +include(cmake/Catch.cmake) if(NOT MINGW) find_library(READLINE_LIBRARY NAMES readline PATH /usr/lib /usr/local/lib /opt/local/lib) @@ -337,37 +338,6 @@ endif() 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) 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) add_executable(compiled_tests unittests/compiled_tests.cpp) 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) target_link_libraries(static_chaiscript_test ${LIBS}) diff --git a/cmake/CatchAddTests.cmake b/cmake/CatchAddTests.cmake index c68921e4..205e2b87 100644 --- a/cmake/CatchAddTests.cmake +++ b/cmake/CatchAddTests.cmake @@ -50,23 +50,21 @@ string(REPLACE "\n" ";" output "${output}") # Parse output foreach(line ${output}) - # Test name; strip spaces to get just the name... - string(REGEX REPLACE " +" "" test "${line}") # ...and add to script add_command(add_test - "${prefix}${test}${suffix}" + "${prefix}${line}${suffix}" ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" - "${test}" + "${line}" ${extra_args} ) add_command(set_tests_properties - "${prefix}${test}${suffix}" + "${prefix}${line}${suffix}" PROPERTIES WORKING_DIRECTORY "${TEST_WORKING_DIR}" ${properties} ) - list(APPEND tests "${prefix}${test}${suffix}") + list(APPEND tests "${prefix}${line}${suffix}") endforeach() # Create a list of all discovered tests, which users may use to e.g. set