18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-17 18:11:56 +01:00
Files
maszyna/tests/unit/run_tests.cmake

36 lines
1.5 KiB
CMake

# runs the unit tests at the end of building the game: cmake -DTESTS=<test binary> -DGAME=<game binary> -P run_tests.cmake
# prints a one line summary when they pass, the full report when they don't. a failure fails the build and
# removes the game binary, so the next build links it again and reruns the tests
# the tests load the libraries the game loads (lua51.dll for the Lua screens): on Windows they're looked for next to
# the game binary as well, where they are for running the game, since nothing puts them next to the tests
if(CMAKE_HOST_WIN32)
get_filename_component(game_folder "${GAME}" DIRECTORY)
file(TO_NATIVE_PATH "${game_folder}" game_folder)
set(ENV{PATH} "${game_folder};$ENV{PATH}")
endif()
execute_process(
COMMAND "${TESTS}" --no-intro --no-version
RESULT_VARIABLE result
OUTPUT_VARIABLE report
ERROR_VARIABLE report)
string(REGEX MATCH "test cases: *([0-9]+) *\\| *([0-9]+) passed *\\| *([0-9]+) failed" _ "${report}")
set(cases "${CMAKE_MATCH_1}")
set(passed "${CMAKE_MATCH_2}")
set(failed "${CMAKE_MATCH_3}")
string(REGEX MATCH "assertions: *([0-9]+)" _ "${report}")
set(checks "${CMAKE_MATCH_1}")
if(result EQUAL 0)
message("Unit tests: ${passed}/${cases} passed (${checks} checks)")
else()
message("${report}")
file(REMOVE "${GAME}")
if(cases STREQUAL "")
message(FATAL_ERROR "Unit tests: didn't run (${result}), see above. -DWITH_TESTS=OFF builds the game without them")
endif()
message(FATAL_ERROR "Unit tests: ${failed} of ${cases} FAILED, see above. -DWITH_TESTS=OFF builds the game without them")
endif()