1 cmake_minimum_required(VERSION 3.16)
4 # Runs a single regressoion test
7 if(NOT REGRESSION_TEST)
8 message(FATAL_ERROR "Script needs REGRESSION_TEST defined (tip: use -DREGRESSION_TEST=..)")
10 if(NOT OPENTTD_EXECUTABLE)
11 message(FATAL_ERROR "Script needs OPENTTD_EXECUTABLE defined (tip: use -DOPENTTD_EXECUTABLE=..)")
14 if(NOT EXISTS ai/${REGRESSION_TEST}/test.sav)
15 message(FATAL_ERROR "Regression test ${REGRESSION_TEST} does not exist (tip: check regression folder for the correct spelling)")
18 # If editbin is given, copy the executable to a new folder, and change the
19 # subsystem to console. The copy is needed as multiple regressions can run
21 if(EDITBIN_EXECUTABLE)
22 execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${OPENTTD_EXECUTABLE} regression_${REGRESSION_TEST}.exe)
23 set(OPENTTD_EXECUTABLE "regression_${REGRESSION_TEST}.exe")
25 execute_process(COMMAND ${EDITBIN_EXECUTABLE} /nologo /subsystem:console ${OPENTTD_EXECUTABLE})
28 # Run the regression test
29 execute_process(COMMAND ${OPENTTD_EXECUTABLE}
31 -c regression/regression.cfg
32 -g ai/${REGRESSION_TEST}/test.sav
38 OUTPUT_VARIABLE REGRESSION_OUTPUT
39 ERROR_VARIABLE REGRESSION_RESULT
40 OUTPUT_STRIP_TRAILING_WHITESPACE
44 message(FATAL_ERROR "Unexpected output: ${REGRESSION_OUTPUT}")
47 if(NOT REGRESSION_RESULT)
48 message(FATAL_ERROR "Regression did not output anything; did the compilation fail?")
51 # For some reason pointer can be printed as '0x(nil)', '0x0000000000000000', or '0x0x0'
52 string(REPLACE "0x(nil)" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}")
53 string(REPLACE "0x0000000000000000" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}")
54 string(REPLACE "0x0x0" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}")
56 # Convert path separators
57 string(REPLACE "\\" "/" REGRESSION_RESULT "${REGRESSION_RESULT}")
59 # Remove timestamps if any
60 string(REGEX REPLACE "\\\[[0-9-]+ [0-9:]+\\\] " "" REGRESSION_RESULT "${REGRESSION_RESULT}")
63 string(REGEX REPLACE "\\\[script:[0-9]\\\]" "" REGRESSION_RESULT "${REGRESSION_RESULT}")
65 # Convert the output to a format that is expected (and more readable) by result.txt
66 string(REPLACE "dbg: " "ERROR: " REGRESSION_RESULT "${REGRESSION_RESULT}")
67 string(REPLACE "ERROR: [1] " "" REGRESSION_RESULT "${REGRESSION_RESULT}")
68 string(REPLACE "[P] " "" REGRESSION_RESULT "${REGRESSION_RESULT}")
69 string(REPLACE "[S] " "" REGRESSION_RESULT "${REGRESSION_RESULT}")
70 string(REGEX REPLACE "dbg: ([^\n]*)\n?" "" REGRESSION_RESULT "${REGRESSION_RESULT}")
72 # Remove duplicate script info
73 string(REGEX REPLACE "ERROR: Registering([^\n]*)\n?" "" REGRESSION_RESULT "${REGRESSION_RESULT}")
74 string(REGEX REPLACE "ERROR: [12]([^\n]*)\n?" "" REGRESSION_RESULT "${REGRESSION_RESULT}")
75 string(REGEX REPLACE "ERROR: The first([^\n]*)\n?" "" REGRESSION_RESULT "${REGRESSION_RESULT}")
77 # Read the expected result
78 file(READ ai/${REGRESSION_TEST}/result.txt REGRESSION_EXPECTED)
80 # Convert the string to a list
81 string(REPLACE "\n" ";" REGRESSION_RESULT "${REGRESSION_RESULT}")
82 string(REPLACE "\n" ";" REGRESSION_EXPECTED "${REGRESSION_EXPECTED}")
87 list(LENGTH REGRESSION_EXPECTED REGRESSION_EXPECTED_LENGTH)
90 foreach(RESULT IN LISTS REGRESSION_RESULT)
92 if(ARGC LESS REGRESSION_EXPECTED_LENGTH)
93 list(GET REGRESSION_EXPECTED ${ARGC} EXPECTED)
96 math(EXPR ARGC "${ARGC} + 1")
98 if(NOT RESULT STREQUAL EXPECTED)
99 message("${ARGC}: - ${EXPECTED}")
100 message("${ARGC}: + ${RESULT}")
105 if(NOT REGRESSION_EXPECTED_LENGTH EQUAL ARGC)
106 message("(${REGRESSION_EXPECTED_LENGTH} lines were expected but ${ARGC} were found)")
111 # Ouput the regression result to a file
112 set(REGRESSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/regression_${REGRESSION_TEST}_output.txt")
113 string(REPLACE ";" "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
114 file(WRITE ${REGRESSION_FILE} "${REGRESSION_RESULT}")
116 message(FATAL_ERROR "Regression failed - Output in ${REGRESSION_FILE}")