Skip to content

Commit ddc1d0e

Browse files
committed
feat(test): run tests and update build result
Although the project's language is now `CXX`, the setup of the C++ environment is as was before. I.e., - The environment of the build test can only be set globally (through CMake defaults, the environment, etc.). - The environment of this project should match that of the build test. It doesn't attempt to propagate any aspect explicitly.
1 parent 1267251 commit ddc1d0e

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

regression-tests/CMakeLists.txt

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.23)
2-
project(cppfront-regression-tests LANGUAGES NONE)
2+
project(cppfront-regression-tests LANGUAGES CXX)
33

44
option(CPPFRONT_DEVELOPING "Test results are updated.")
55

@@ -10,7 +10,33 @@ find_package(cppfront REQUIRED)
1010

1111
set(REGRESSION_TESTS_DIR "${CMAKE_CURRENT_LIST_DIR}/../cppfront/regression-tests")
1212

13+
if (CPPFRONT_DEVELOPING)
14+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
15+
set(compiler_id "gcc")
16+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
17+
set(compiler_id "apple-clang")
18+
else (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
19+
string(TOLOWER "${CMAKE_CXX_COMPILER_ID}" compiler_id)
20+
endif ()
21+
string(REGEX MATCH "[0-9]+" compiler_version "${CMAKE_CXX_COMPILER_VERSION}")
22+
23+
set(TEST_RESULTS_BUILD_DIR "${REGRESSION_TESTS_DIR}/test-results/${compiler_id}-${compiler_version}")
24+
file(MAKE_DIRECTORY "${TEST_RESULTS_BUILD_DIR}")
25+
26+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
27+
set(compiler_version_command "${CMAKE_CXX_COMPILER}" "--version")
28+
endif ()
29+
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
30+
set(compiler_id "clang")
31+
endif ()
32+
execute_process(
33+
COMMAND ${compiler_version_command}
34+
OUTPUT_FILE "${TEST_RESULTS_BUILD_DIR}/${compiler_id}-version.output"
35+
)
36+
endif ()
37+
1338
configure_file("cmake/ExecuteWithRedirection.cmake" "ExecuteWithRedirection.cmake" COPYONLY)
39+
configure_file("cmake/ExecuteTestCase.cmake.in" "ExecuteTestCase.cmake" @ONLY)
1440

1541
function(cppfront_command_tests)
1642
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "SOURCE;EXPECTED_FILE" "EXTRA_FLAGS")
@@ -106,6 +132,7 @@ function(cppfront_build_tests)
106132

107133
configure_file("${REGRESSION_TESTS_DIR}/${ARG_SOURCE}" "${test_dir}/${ARG_SOURCE}" COPYONLY)
108134
configure_file("cmake/CMakeLists.txt.in" "${test_dir}/CMakeLists.txt" @ONLY)
135+
configure_file("cmake/test-case-config.cmake.in" "${test_dir}/test-case-config.cmake.in" COPYONLY)
109136

110137
add_test(
111138
NAME "build/${test_name}"
@@ -119,8 +146,48 @@ function(cppfront_build_tests)
119146
"-Dcppfront_DIR=${cppfront_DIR}"
120147
"-Dcppfront-exe_DIR=${cppfront-exe_DIR}"
121148
"-DCPPFRONT_FLAGS=${ARG_EXTRA_FLAGS}"
149+
# There's `CMAKE_CXX_LINKER_LAUNCHER`, too. So far, it's not needed.
150+
"-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_COMMAND};-D;OUTPUT_FILE=${gen_cpp_src}.output;-P;../../ExecuteWithRedirection.cmake;--"
122151
)
123-
set_tests_properties("build/${test_name}" PROPERTIES DEPENDS "${build_test_depends};codegen/check/${test_name}")
152+
set_tests_properties(
153+
"build/${test_name}"
154+
PROPERTIES
155+
DEPENDS "${build_test_depends};codegen/check/${test_name}"
156+
FIXTURES_SETUP "build/${test_name}"
157+
)
158+
159+
if (CPPFRONT_DEVELOPING)
160+
add_test(
161+
NAME "build/execute/${test_name}"
162+
COMMAND
163+
"${CMAKE_COMMAND}"
164+
-D "OUTPUT_FILE=${test_dir}/${gen_cpp_src}.execution"
165+
-P "../ExecuteTestCase.cmake"
166+
WORKING_DIRECTORY "${test_dir}"
167+
)
168+
set_tests_properties(
169+
"build/execute/${test_name}"
170+
PROPERTIES
171+
FIXTURES_REQUIRED "build/${test_name}"
172+
FIXTURES_SETUP "build/execute/${test_name}"
173+
RESOURCE_LOCK "test.exe")
174+
175+
add_test(
176+
NAME "build/update/${test_name}"
177+
COMMAND
178+
"${CMAKE_COMMAND}"
179+
-E copy_if_different
180+
"build/${gen_cpp_src}.output"
181+
"${gen_cpp_src}.execution"
182+
"${TEST_RESULTS_BUILD_DIR}"
183+
WORKING_DIRECTORY "${test_dir}"
184+
)
185+
set_tests_properties(
186+
"build/update/${test_name}"
187+
PROPERTIES
188+
FIXTURES_CLEANUP "build/${test_name};build/execute${test_name}"
189+
)
190+
endif ()
124191
endfunction()
125192

126193
function(cppfront_tests)

regression-tests/cmake/CMakeLists.txt.in

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,30 @@ target_compile_options(
1313
PRIVATE
1414
"$<$<CXX_COMPILER_ID:MSVC>:/experimental:module>"
1515
)
16+
17+
include(GNUInstallDirs)
18+
include(CMakePackageConfigHelpers)
19+
20+
set(TEST_CASE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/cmake/test-case")
21+
22+
install(
23+
TARGETS test-case
24+
EXPORT test-case-targets
25+
)
26+
27+
install(
28+
EXPORT test-case-targets
29+
DESTINATION "${TEST_CASE_INSTALL_CMAKEDIR}"
30+
)
31+
32+
configure_package_config_file(
33+
"test-case-config.cmake.in"
34+
"test-case-config.cmake"
35+
INSTALL_DESTINATION "${TEST_CASE_INSTALL_CMAKEDIR}"
36+
PATH_VARS CMAKE_INSTALL_BINDIR
37+
)
38+
39+
install(
40+
FILES "${CMAKE_CURRENT_BINARY_DIR}/test-case-config.cmake"
41+
DESTINATION "${TEST_CASE_INSTALL_CMAKEDIR}"
42+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
execute_process(
2+
COMMAND "${CMAKE_COMMAND}" --install "build" --prefix "_local"
3+
COMMAND_ERROR_IS_FATAL ANY
4+
)
5+
find_package(test-case REQUIRED PATHS "${CMAKE_CURRENT_BINARY_DIR}/_local" NO_DEFAULT_PATH)
6+
execute_process(
7+
COMMAND
8+
"${CMAKE_COMMAND}"
9+
-E copy
10+
"${TEST_CASE_EXECUTABLE}"
11+
"@TEST_RESULTS_BUILD_DIR@/test.exe"
12+
)
13+
execute_process(
14+
COMMAND
15+
"${CMAKE_COMMAND}"
16+
-D "OUTPUT_FILE=${OUTPUT_FILE}"
17+
-P "@CMAKE_CURRENT_BINARY_DIR@/ExecuteWithRedirection.cmake"
18+
--
19+
"./test.exe"
20+
COMMAND_ERROR_IS_FATAL ANY
21+
WORKING_DIRECTORY "@TEST_RESULTS_BUILD_DIR@"
22+
)
23+
execute_process(COMMAND "${CMAKE_COMMAND}" -E rm "@TEST_RESULTS_BUILD_DIR@/test.exe")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.23)
2+
@PACKAGE_INIT@
3+
4+
set_and_check(
5+
TEST_CASE_EXECUTABLE
6+
"@PACKAGE_CMAKE_INSTALL_BINDIR@/test-case@CMAKE_EXECUTABLE_SUFFIX@"
7+
)

0 commit comments

Comments
 (0)