Skip to content

Commit 857240f

Browse files
committed
feat(test): copy new or changed build results only
1 parent cb398b0 commit 857240f

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

Diff for: regression-tests/CMakeLists.txt

+27-10
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ set(CPPFRONT_NO_MAGIC 1)
99
find_package(cppfront REQUIRED)
1010

1111
set(REGRESSION_TESTS_DIR "${CMAKE_CURRENT_LIST_DIR}/../cppfront/regression-tests")
12+
set(TEST_RESULTS_DIR "${REGRESSION_TESTS_DIR}/test-results")
1213

1314
if (CPPFRONT_DEVELOPING)
15+
# Set `compiler_id` and `compiler_major_version`.
1416
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
1517
set(compiler_id "gcc")
1618
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
@@ -20,21 +22,36 @@ if (CPPFRONT_DEVELOPING)
2022
endif ()
2123
string(REGEX MATCH "[0-9]+" compiler_major_version "${CMAKE_CXX_COMPILER_VERSION}")
2224

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}")
2529

30+
# Write compiler version output.
2631
set(compiler_version_command "${CMAKE_CXX_COMPILER}" "--version")
2732
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
2833
set(compiler_id "clang")
2934
endif ()
3035
execute_process(
3136
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"
3338
)
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)
3450
endif ()
3551

3652
configure_file("cmake/ExecuteWithRedirection.cmake" "ExecuteWithRedirection.cmake" COPYONLY)
3753
configure_file("cmake/ExecuteTestCase.cmake.in" "ExecuteTestCase.cmake" @ONLY)
54+
configure_file("cmake/UpdateBuildOutput.cmake.in" "UpdateBuildOutput.cmake" @ONLY)
3855

3956
function(cppfront_command_tests)
4057
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "SOURCE;EXPECTED_FILE" "EXTRA_FLAGS")
@@ -67,13 +84,13 @@ function(cppfront_command_tests)
6784
-E copy_if_different
6885
"${gen_cpp_src}"
6986
"${ARG_SOURCE}.output"
70-
"${REGRESSION_TESTS_DIR}/test-results/"
87+
"${TEST_RESULTS_DIR}"
7188
)
7289
set_tests_properties("codegen/update/${test_name}" PROPERTIES FIXTURES_CLEANUP "codegen/${test_name}")
7390
set(build_test_depends "codegen/update/${test_name}")
7491
endif ()
7592

76-
set(expected_output_file "${REGRESSION_TESTS_DIR}/test-results/${ARG_SOURCE}.output")
93+
set(expected_output_file "${TEST_RESULTS_DIR}/${ARG_SOURCE}.output")
7794
if (EXISTS "${expected_output_file}")
7895
file(READ "${expected_output_file}" expected_output)
7996
string(REPLACE "\\" "\\\\" expected_output "${expected_output}")
@@ -164,10 +181,10 @@ function(cppfront_build_tests)
164181
NAME "build/update/${test_name}"
165182
COMMAND
166183
"${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"
171188
WORKING_DIRECTORY "${test_dir}"
172189
)
173190
set_tests_properties(
@@ -190,7 +207,7 @@ function(cppfront_tests)
190207

191208
foreach (src IN LISTS sources)
192209
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}")
194211

195212
if (NOT EXISTS "${expected_file}")
196213
set(expected_file "")

Diff for: regression-tests/cmake/ExecuteTestCase.cmake.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ execute_process(
88
"${CMAKE_COMMAND}"
99
-E copy
1010
"${TEST_CASE_EXECUTABLE}"
11-
"@TEST_RESULTS_BUILD_DIR@/test.exe"
11+
"@BUILD_RESULTS_DIR@/test.exe"
1212
)
1313
execute_process(
1414
COMMAND
@@ -18,6 +18,6 @@ execute_process(
1818
--
1919
"./test.exe"
2020
COMMAND_ERROR_IS_FATAL ANY
21-
WORKING_DIRECTORY "@TEST_RESULTS_BUILD_DIR@"
21+
WORKING_DIRECTORY "@BUILD_RESULTS_DIR@"
2222
)
23-
execute_process(COMMAND "${CMAKE_COMMAND}" -E rm "@TEST_RESULTS_BUILD_DIR@/test.exe")
23+
execute_process(COMMAND "${CMAKE_COMMAND}" -E rm "@BUILD_RESULTS_DIR@/test.exe")

Diff for: regression-tests/cmake/UpdateBuildOutput.cmake.in

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Updates an output for the current compiler-version
2+
# when it differs from its previous version or
3+
# when no previous version has the output file.
4+
# Objectives:
5+
# - For "absence of output" to mean that "it's the same as the previous version".
6+
# - To commit only new and changed outputs in PRs for easier reviewing.
7+
8+
file(READ "${OUTPUT_FILE}" new_output)
9+
if (EXISTS "${EXECUTION_FILE}")
10+
file(READ "${EXECUTION_FILE}" new_execution)
11+
endif ()
12+
function(write path_var ext)
13+
foreach (build_results_dir IN ITEMS @OLD_BUILD_RESULTS_DIRS@)
14+
set(result_file "@TEST_RESULTS_DIR@/${build_results_dir}/${GEN_CPP_SRC}.${ext}")
15+
if (EXISTS "${result_file}")
16+
file(READ "${result_file}" "old_${ext}")
17+
if (new_${ext} STREQUAL old_${ext})
18+
return()
19+
else ()
20+
break ()
21+
endif ()
22+
endif ()
23+
endforeach ()
24+
file(COPY "${${path_var}}" DESTINATION "@BUILD_RESULTS_DIR@")
25+
endfunction()
26+
write(OUTPUT_FILE "output")
27+
if (DEFINED new_execution)
28+
write(EXECUTION_FILE "execution")
29+
endif ()

0 commit comments

Comments
 (0)