Skip to content

Commit ed9d696

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 ed9d696

File tree

4 files changed

+124
-2
lines changed

4 files changed

+124
-2
lines changed

regression-tests/CMakeLists.txt

Lines changed: 67 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,31 @@ 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 ()
19+
string(TOLOWER "${CMAKE_CXX_COMPILER_ID}" compiler_id)
20+
endif ()
21+
string(REGEX MATCH "[0-9]+" compiler_major_version "${CMAKE_CXX_COMPILER_VERSION}")
22+
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+
26+
set(compiler_version_command "${CMAKE_CXX_COMPILER}" "--version")
27+
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
28+
set(compiler_id "clang")
29+
endif ()
30+
execute_process(
31+
COMMAND ${compiler_version_command}
32+
OUTPUT_FILE "${TEST_RESULTS_BUILD_DIR}/${compiler_id}-version.output"
33+
)
34+
endif ()
35+
1336
configure_file("cmake/ExecuteWithRedirection.cmake" "ExecuteWithRedirection.cmake" COPYONLY)
37+
configure_file("cmake/ExecuteTestCase.cmake.in" "ExecuteTestCase.cmake" @ONLY)
1438

1539
function(cppfront_command_tests)
1640
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "SOURCE;EXPECTED_FILE" "EXTRA_FLAGS")
@@ -106,6 +130,7 @@ function(cppfront_build_tests)
106130

107131
configure_file("${REGRESSION_TESTS_DIR}/${ARG_SOURCE}" "${test_dir}/${ARG_SOURCE}" COPYONLY)
108132
configure_file("cmake/CMakeLists.txt.in" "${test_dir}/CMakeLists.txt" @ONLY)
133+
configure_file("cmake/test-case-config.cmake.in" "${test_dir}/test-case-config.cmake.in" COPYONLY)
109134

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

126191
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)