From b174c9291c618944c1ec8289959a2256ae6b5328 Mon Sep 17 00:00:00 2001 From: Nora Sandler Date: Mon, 24 Jun 2024 23:02:48 +0000 Subject: [PATCH] use python instead of bash for test runner --- .github/run-tests.sh | 28 ----------------- .github/run_tests.py | 44 +++++++++++++++++++++++++++ .github/workflows/build_and_test.yaml | 16 +++------- 3 files changed, 49 insertions(+), 39 deletions(-) delete mode 100755 .github/run-tests.sh create mode 100755 .github/run_tests.py diff --git a/.github/run-tests.sh b/.github/run-tests.sh deleted file mode 100755 index d4e60dc..0000000 --- a/.github/run-tests.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -# sanity check -if (( CHAPTER < 1 | CHAPTER > 20)); then - echo "Bogus chapter number" - exit 1 -fi - -# define the stages we're going to test -declare -a STAGES -if ((CHAPTER == 1)); then - # no --tacky or --validate stage yet - STAGES=(lex parse codegen run) -elif ((CHAPTER < 5)); then - # --tacky but not --validate - STAGES=(lex parse tacky codegen run) -elif ((CHAPTER < 19)); then - # all the stages! - STAGES=(lex parse tacky validate codegen run) -else - # don't run intermediate stages for optimization tests - STAGES=(run) -fi -readonly STAGES - -for stage in "${STAGES[@]}"; do - ./test_compiler "${CC}" --chapter "${CHAPTER}" --stage "${stage}" -done diff --git a/.github/run_tests.py b/.github/run_tests.py new file mode 100755 index 0000000..0bc9309 --- /dev/null +++ b/.github/run_tests.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import platform +import subprocess +import sys + +# get/sanity check chapter number +cc = sys.argv[1] +chapter = int(sys.argv[2]) +if chapter < 1 or chapter > 20: + exit("Bad chapter number") + +# do we need rosetta? +prefix = "" +if platform.machine().lower() == "arm64": + prefix = "arch -x86_64 " + +# define the stages we're going to test +stages = ["lex", "parse", "tacky", "validate", "codegen", "run"] +if chapter == 1: + # tacky and validate stages not added yet + stages.remove("tacky") + stages.remove("validate") +elif chapter < 5: + # TACKY stage added, validate not + stages.remove("validate") +elif chapter > 18: + # don't test intermediate stages for chapters 19/20 + stages = ["run"] + + +for stage in stages: + print(f"Testing '{stage}' stage") + try: + subprocess.run( + f"{prefix}./test_compiler {cc} --chapter {chapter} --stage {stage}", + shell=True, + check=True, + ) + except subprocess.CalledProcessError as cpe: + print(cpe.stderr) + print(cpe.stdout) + exit("command failed") diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 0b319e6..f185464 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -35,8 +35,9 @@ jobs: with: repository: nlsandler/nqcc2 sparse-checkout: | - .github/run-tests.sh + .github/run_tests.py sparse-checkout-cone-mode: false + path: script - name: Download the compiler uses: actions/download-artifact@v4 @@ -47,14 +48,7 @@ jobs: # make NQCC executable - run: chmod u+x nqcc/main.exe - # Invoke the run-tests script to test each intermediate stage - - # use Rosetta on macOS since that's what most readers are doing - - name: Run the tests (Apple Silicon) - if: runner.arch == 'ARM64' - run: arch -x86_64 ./.github/run-tests.sh - - - name: Run the tests (x86-64) - if: runner.arch != 'ARM64' - run: ./.github/run-tests.sh + # Invoke the run_tests.py script to test each intermediate stage + - name: Run the tests + run: ./script/.github/run_tests.py nqcc/main.exe "{$CHAPTER}"