Skip to content

Commit

Permalink
MSVC regression-test job in CI now builds and links with C++ standard…
Browse files Browse the repository at this point in the history
… library modules to enable `import std.compat;` (hsutter#953)

* Fix typo

* MSVC CI regression tests now build and link with the `std.compat` module for the C++ standard library

* Fix syntax to access environment variable

* Need to build `std` module as well as `std.compat`

* Fix syntax typo

* Remove temp `exit` that was used for testing
  • Loading branch information
bluetarpmedia authored Jan 22, 2024
1 parent e7dfcbc commit 0e74bd7
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions regression-tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ check_file () {
failure=1
else
# Compare the content with the reference value checked in git
diff_output=$(git diff --ignore-cr-at-eol -I"\#define CPP2\_.*\_STD" -- "$file")
diff_output=$(git diff --ignore-cr-at-eol -- "$file")
if [[ -n "$diff_output" ]]; then
echo " Non-matching $description:"
printf "\n$diff_output\n\n" | tee -a "$cxx_compiler-patch.diff"
Expand Down Expand Up @@ -103,7 +103,7 @@ expected_results_dir="test-results"
################
# Get the directory with the exec outputs and compilation command
if [[ "$cxx_compiler" == *"cl.exe"* ]]; then
compiler_cmd='cl.exe -nologo -std:c++latest -MD -EHsc -I ..\include -I ..\..\..\include -experimental:module -Fe:'
compiler_cmd='cl.exe -nologo -std:c++latest -MD -EHsc -I ..\include -I ..\..\..\include -Fe:'
exec_out_dir="$expected_results_dir/msvc-2022"
compiler_version=$(cl.exe)
else
Expand Down Expand Up @@ -144,14 +144,26 @@ if [[ $? -ne 0 ]]; then
exit 2
fi

################
# Build the `std` and `std.compat` modules so that the regression tests can use them (currently only supported by MSVC)
# in order to support `import std.compat;`.
regression_test_link_obj=""
if [[ "$cxx_compiler" == *"cl.exe"* ]]; then
echo "Building std and std.compat modules"
(cd $exec_out_dir; \
cl.exe -nologo -std:c++latest -MD -EHsc -c "${VCToolsInstallDir}/modules/std.ixx";
cl.exe -nologo -std:c++latest -MD -EHsc -c "${VCToolsInstallDir}/modules/std.compat.ixx")
regression_test_link_obj="std.obj std.compat.obj"
fi

################
failed_tests=()
failed_compilations=()
skipped_tests=()
echo "Running regression tests"
for test_file in $tests; do
test_name=${test_file%.*}
expeced_output="$expected_results_dir/$test_file.output"
expected_output="$expected_results_dir/$test_file.output"
generated_cpp_name=$test_name.cpp
expected_src="$expected_results_dir/$generated_cpp_name"
test_bin="test.exe"
Expand All @@ -163,24 +175,19 @@ for test_file in $tests; do
if [[ $test_name == "pure2"* ]]; then
descr="pure Cpp2 code"
opt="-p"
# Disable C++ modules with MSVC due to GitHub-hosted runner not supporting it
# See https://github.com/hsutter/cppfront/issues/943
if [[ "$cxx_compiler" == *"cl.exe"* ]]; then
opt="$opt -include-std"
fi
fi
echo " Testing $descr: $test_name.cpp2"

########
# Run the translation test
echo " Generating Cpp1 code"
./"$cppfront_cmd" "$test_file" -o "$expected_src" $opt > "$expeced_output" 2>&1
./"$cppfront_cmd" "$test_file" -o "$expected_src" $opt > "$expected_output" 2>&1

failure=0
compiler_issue=0
########
# The C++1 generation output has to exist and to be tracked by git
check_file "$expeced_output" "Cpp1 generation output file"
check_file "$expected_output" "Cpp1 generation output file"

########
# Check the generated code
Expand All @@ -200,7 +207,7 @@ for test_file in $tests; do
# The source is temporarily copied to avoid issues with bash paths in cl.exe
(cd $exec_out_dir; \
cp ../../$expected_src $generated_cpp_name;
$compiler_cmd"$test_bin" \
$compiler_cmd"$test_bin" $regression_test_link_obj \
$generated_cpp_name \
> $generated_cpp_name.output 2>&1)
compilation_result=$?
Expand Down Expand Up @@ -239,7 +246,7 @@ for test_file in $tests; do
fi
fi
fi
elif [[ $(cat "$expeced_output") != *"error"* ]]; then
elif [[ $(cat "$expected_output") != *"error"* ]]; then
echo " Missing generated src file treated as failure"
echo " Failing compilation message needs to contain 'error'"
failure=1
Expand Down

0 comments on commit 0e74bd7

Please sign in to comment.