@@ -9,8 +9,10 @@ set(CPPFRONT_NO_MAGIC 1)
9
9
find_package (cppfront REQUIRED)
10
10
11
11
set (REGRESSION_TESTS_DIR "${CMAKE_CURRENT_LIST_DIR} /../cppfront/regression-tests" )
12
+ set (TEST_RESULTS_DIR "${REGRESSION_TESTS_DIR} /test-results" )
12
13
13
14
if (CPPFRONT_DEVELOPING)
15
+ # Set `compiler_id` and `compiler_major_version`.
14
16
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
15
17
set (compiler_id "gcc" )
16
18
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
@@ -20,21 +22,36 @@ if (CPPFRONT_DEVELOPING)
20
22
endif ()
21
23
string (REGEX MATCH "[0-9]+" compiler_major_version "${CMAKE_CXX_COMPILER_VERSION} " )
22
24
23
- set (TEST_RESULTS_BUILD_DIR "${REGRESSION_TESTS_DIR} /test-results/${compiler_id} -${compiler_major_version} " )
24
- file (MAKE_DIRECTORY "${TEST_RESULTS_BUILD_DIR} " )
25
+ # Setup `BUILD_RESULTS_DIR`.
26
+ set (compiler_item_name "${compiler_id} -${compiler_major_version} " )
27
+ set (BUILD_RESULTS_DIR "${TEST_RESULTS_DIR} /${compiler_item_name} " )
28
+ file (MAKE_DIRECTORY "${BUILD_RESULTS_DIR} " )
25
29
30
+ # Write compiler version output.
26
31
set (compiler_version_command "${CMAKE_CXX_COMPILER} " "--version" )
27
32
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" )
28
33
set (compiler_id "clang" )
29
34
endif ()
30
35
execute_process (
31
36
COMMAND ${compiler_version_command}
32
- OUTPUT_FILE "${TEST_RESULTS_BUILD_DIR } /${compiler_id} -version.output"
37
+ OUTPUT_FILE "${BUILD_RESULTS_DIR } /${compiler_id} -version.output"
33
38
)
39
+
40
+ # Set `OLD_BUILD_RESULTS_DIRS`.
41
+ file (
42
+ GLOB build_result_dirs
43
+ RELATIVE "${TEST_RESULTS_DIR} "
44
+ "${TEST_RESULTS_DIR} /${compiler_id} -*"
45
+ )
46
+ list (SORT build_result_dirs)
47
+ list (FIND build_result_dirs "${compiler_item_name} " i)
48
+ list (SUBLIST build_result_dirs 0 ${i} OLD_BUILD_RESULTS_DIRS)
49
+ list (REVERSE OLD_BUILD_RESULTS_DIRS)
34
50
endif ()
35
51
36
52
configure_file ("cmake/ExecuteWithRedirection.cmake" "ExecuteWithRedirection.cmake" COPYONLY )
37
53
configure_file ("cmake/ExecuteTestCase.cmake.in" "ExecuteTestCase.cmake" @ONLY)
54
+ configure_file ("cmake/UpdateBuildOutput.cmake.in" "UpdateBuildOutput.cmake" @ONLY)
38
55
39
56
function (cppfront_command_tests)
40
57
cmake_parse_arguments (PARSE_ARGV 0 ARG "" "SOURCE;EXPECTED_FILE" "EXTRA_FLAGS" )
@@ -67,13 +84,13 @@ function(cppfront_command_tests)
67
84
-E copy_if_different
68
85
"${gen_cpp_src} "
69
86
"${ARG_SOURCE} .output"
70
- "${REGRESSION_TESTS_DIR} /test-results/ "
87
+ "${TEST_RESULTS_DIR} "
71
88
)
72
89
set_tests_properties ("codegen/update/${test_name} " PROPERTIES FIXTURES_CLEANUP "codegen/${test_name} " )
73
90
set (build_test_depends "codegen/update/${test_name} " )
74
91
endif ()
75
92
76
- set (expected_output_file "${REGRESSION_TESTS_DIR} /test-results /${ARG_SOURCE} .output" )
93
+ set (expected_output_file "${TEST_RESULTS_DIR} /${ARG_SOURCE} .output" )
77
94
if (EXISTS "${expected_output_file} " )
78
95
file (READ "${expected_output_file} " expected_output)
79
96
string (REPLACE "\\ " "\\\\ " expected_output "${expected_output} " )
@@ -164,10 +181,10 @@ function(cppfront_build_tests)
164
181
NAME "build/update/${test_name} "
165
182
COMMAND
166
183
"${CMAKE_COMMAND} "
167
- -E copy_if_different
168
- " build/${gen_cpp_src} .output"
169
- " ${gen_cpp_src} .execution"
170
- " ${TEST_RESULTS_BUILD_DIR} "
184
+ -D "GEN_CPP_SRC= ${gen_cpp_src} "
185
+ -D "OUTPUT_FILE= build/${gen_cpp_src} .output"
186
+ -D "EXECUTION_FILE= ${gen_cpp_src} .execution"
187
+ -P "../UpdateBuildOutput.cmake "
171
188
WORKING_DIRECTORY "${test_dir} "
172
189
)
173
190
set_tests_properties (
@@ -190,7 +207,7 @@ function(cppfront_tests)
190
207
191
208
foreach (src IN LISTS sources )
192
209
cmake_path(REPLACE_EXTENSION src "cpp" OUTPUT_VARIABLE expected_file)
193
- set (expected_file "${REGRESSION_TESTS_DIR} /test-results /${expected_file} " )
210
+ set (expected_file "${TEST_RESULTS_DIR} /${expected_file} " )
194
211
195
212
if (NOT EXISTS "${expected_file} " )
196
213
set (expected_file "" )
0 commit comments