Skip to content

Commit

Permalink
use python instead of bash for test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
nlsandler committed Jun 24, 2024
1 parent 048ca0f commit b174c92
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
28 changes: 0 additions & 28 deletions .github/run-tests.sh

This file was deleted.

44 changes: 44 additions & 0 deletions .github/run_tests.py
Original file line number Diff line number Diff line change
@@ -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")
16 changes: 5 additions & 11 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"

0 comments on commit b174c92

Please sign in to comment.