From 9b17b4c748a0c363107adc498238a317271f37c8 Mon Sep 17 00:00:00 2001 From: Corey Dean Date: Mon, 11 May 2026 09:07:57 -0500 Subject: [PATCH 1/3] test: lock target-flag workflow contract --- test.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/test.sh b/test.sh index 3db5526..e78f2ae 100755 --- a/test.sh +++ b/test.sh @@ -3,6 +3,8 @@ set -euo pipefail ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TESTDIR="${ROOTDIR}/tests" +TEST_TMPDIR="$(mktemp -d "${TMPDIR:-/tmp}/blitzforge-tests.XXXXXX")" +trap 'rm -rf "${TEST_TMPDIR}"' EXIT BLITZCC_UNIX="${ROOTDIR}/bin/blitzcc" BLITZCC_WIN="${ROOTDIR}/bin/blitzcc.exe" @@ -24,6 +26,52 @@ else fi FAILED=0 +TARGET_SAMPLE="${TESTDIR}/NumberTest.bb" + +run_target_expect_success() { + local label="$1" + shift + if ! "${BLITZCC}" -c +q "$@" "${TARGET_SAMPLE}" \ + > "${TEST_TMPDIR}/target-success.out" 2> "${TEST_TMPDIR}/target-success.err"; then + echo "target contract FAILED: ${label}" >&2 + cat "${TEST_TMPDIR}/target-success.err" >&2 + FAILED=1 + fi +} + +run_target_expect_failure() { + local label="$1" + shift + set +e + "${BLITZCC}" -c +q "$@" "${TARGET_SAMPLE}" \ + > "${TEST_TMPDIR}/target-failure.out" 2> "${TEST_TMPDIR}/target-failure.err" + local rc=$? + set -e + + if [[ "${rc}" -eq 0 ]]; then + echo "target contract FAILED: ${label} unexpectedly succeeded" >&2 + FAILED=1 + return + fi + + if ! grep -q "Unsupported -target" "${TEST_TMPDIR}/target-failure.out"; then + echo "target contract FAILED: ${label} did not report the unsupported-target error" >&2 + echo "--- stdout ---" >&2 + cat "${TEST_TMPDIR}/target-failure.out" >&2 + echo "--- stderr ---" >&2 + cat "${TEST_TMPDIR}/target-failure.err" >&2 + FAILED=1 + fi +} + +run_target_expect_success "host alias compiles NumberTest" -target host +if [[ "$(uname -s)" == "Darwin" ]]; then + run_target_expect_success "native macOS target compiles NumberTest" -target macos-arm64 + run_target_expect_failure "foreign Windows target is rejected" -target windows-x86 +else + run_target_expect_failure "foreign macOS target is rejected" -target macos-arm64 +fi + while IFS= read -r -d '' f; do if ! "${BLITZCC}" "${TARGET_FLAG[@]}" "${EXEC_FLAG[@]}" -t "${f}"; then echo "\"${f}\" failed at least one test" @@ -39,19 +87,17 @@ if [[ "$(uname -s)" == "Darwin" ]]; then # the stub runtime is still in place. It does NOT silently succeed when # nothing actually ran. STUB_SENTINEL="BlitzForge stub runtime: native execution is not yet implemented" - tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/blitzcc-arm64-exec.XXXXXX")" - trap 'rm -rf "${tmpdir}"' EXIT - cat > "${tmpdir}/arm64_exec_smoke.bb" <<'EOF' + cat > "${TEST_TMPDIR}/arm64_exec_smoke.bb" <<'EOF' Print "arm64_exec_smoke" End EOF set +e - "${BLITZCC}" +q -target macos-arm64 "${tmpdir}/arm64_exec_smoke.bb" \ - > "${tmpdir}/arm64_exec_smoke.out" 2> "${tmpdir}/arm64_exec_smoke.err" + "${BLITZCC}" +q -target macos-arm64 "${TEST_TMPDIR}/arm64_exec_smoke.bb" \ + > "${TEST_TMPDIR}/arm64_exec_smoke.out" 2> "${TEST_TMPDIR}/arm64_exec_smoke.err" smoke_rc=$? set -e - smoke_stdout="$(tr -d '\r' < "${tmpdir}/arm64_exec_smoke.out")" - smoke_stderr="$(cat "${tmpdir}/arm64_exec_smoke.err")" + smoke_stdout="$(tr -d '\r' < "${TEST_TMPDIR}/arm64_exec_smoke.out")" + smoke_stderr="$(cat "${TEST_TMPDIR}/arm64_exec_smoke.err")" if [[ "${smoke_stdout}" == "arm64_exec_smoke" && "${smoke_rc}" -eq 0 ]]; then echo "arm64 execution smoke: native runtime executed program correctly." elif grep -q "${STUB_SENTINEL}" <<<"${smoke_stderr}"; then From 436f9d51344fece8d841eea5a7a169485d9b6289 Mon Sep 17 00:00:00 2001 From: Corey Dean Date: Mon, 11 May 2026 09:07:59 -0500 Subject: [PATCH 2/3] test: lock target-flag workflow contract --- test.bat | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/test.bat b/test.bat index f96771a..77a7844 100644 --- a/test.bat +++ b/test.bat @@ -1,12 +1,17 @@ @echo off -setlocal +setlocal EnableDelayedExpansion set ROOTDIR=%CD% -cd %ROOTDIR%\tests - set BLITZPATH=%ROOTDIR% set FAILED=0 +set SAMPLE=%ROOTDIR%\tests\NumberTest.bb + +call :expect_success "host alias compiles NumberTest" -c +q -target host "%SAMPLE%" +call :expect_success "native Windows target compiles NumberTest" -c +q -target windows-x86 "%SAMPLE%" +call :expect_failure "foreign macOS target is rejected" "Unsupported -target" -c +q -target macos-arm64 "%SAMPLE%" + +cd %ROOTDIR%\tests for /R %%f in (*.bb) do ( "%BLITZPATH%\bin\blitzcc.exe" -t "%%f" || (echo "%%f failed at least one test" && SET FAILED=1) @@ -15,7 +20,7 @@ for /R %%f in (*.bb) do ( cd %ROOTDIR% -if %FAILED% == 1 ( +if !FAILED! == 1 ( echo "Tests failed" endlocal exit /b 1 @@ -23,4 +28,37 @@ if %FAILED% == 1 ( echo "Tests passed" -endlocal \ No newline at end of file +endlocal +exit /b 0 + +:expect_success +set "LABEL=%~1" +shift /1 +"%BLITZPATH%\bin\blitzcc.exe" %* >nul 2>&1 +if errorlevel 1 ( + echo target contract FAILED: !LABEL! + set FAILED=1 +) +exit /b 0 + +:expect_failure +set "LABEL=%~1" +set "EXPECTED=%~2" +shift /1 +shift /1 +set "TARGET_LOG=%TEMP%\blitzforge-target-%RANDOM%-%RANDOM%.log" +"%BLITZPATH%\bin\blitzcc.exe" %* >"!TARGET_LOG!" 2>&1 +set "TARGET_RC=!ERRORLEVEL!" +if !TARGET_RC! EQU 0 ( + echo target contract FAILED: !LABEL! unexpectedly succeeded + set FAILED=1 +) else ( + findstr /C:"!EXPECTED!" "!TARGET_LOG!" >nul + if errorlevel 1 ( + echo target contract FAILED: !LABEL! did not report the unsupported-target error + type "!TARGET_LOG!" + set FAILED=1 + ) +) +del /q "!TARGET_LOG!" >nul 2>&1 +exit /b 0 From b65408bbc8c093832ca30cc2d23398d1a019e12f Mon Sep 17 00:00:00 2001 From: Corey Ryan Dean Date: Mon, 11 May 2026 09:40:28 -0500 Subject: [PATCH 3/3] fix(test): preserve shifted args in Windows target checks --- test.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.bat b/test.bat index 77a7844..e5a7063 100644 --- a/test.bat +++ b/test.bat @@ -34,7 +34,7 @@ exit /b 0 :expect_success set "LABEL=%~1" shift /1 -"%BLITZPATH%\bin\blitzcc.exe" %* >nul 2>&1 +"%BLITZPATH%\bin\blitzcc.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9 >nul 2>&1 if errorlevel 1 ( echo target contract FAILED: !LABEL! set FAILED=1 @@ -47,7 +47,7 @@ set "EXPECTED=%~2" shift /1 shift /1 set "TARGET_LOG=%TEMP%\blitzforge-target-%RANDOM%-%RANDOM%.log" -"%BLITZPATH%\bin\blitzcc.exe" %* >"!TARGET_LOG!" 2>&1 +"%BLITZPATH%\bin\blitzcc.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9 >"!TARGET_LOG!" 2>&1 set "TARGET_RC=!ERRORLEVEL!" if !TARGET_RC! EQU 0 ( echo target contract FAILED: !LABEL! unexpectedly succeeded