Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Track Exercises on Runner

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

jobs:
ci:
runs-on: ubuntu-24.04

steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- run: docker pull exercism/zig-test-runner
- name: Run tests for all exercises
run: sh ./bin/test
38 changes: 38 additions & 0 deletions bin/.test-in-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# This script is meant to be run in the docker container of zig-test-runner

all_slugs="$*"

exit_code=0

for slug in $all_slugs; do
snake="${slug//-/_}"
local_exit_code=0

rm -rf /tmp/solution
cp -r "/exercises/practice/${slug}" /tmp/solution

# Integration test: Check if the example solution passes the tests
# as run by the zig-test-runner similiarly to a student submitting
# their solution.
cp /tmp/solution/.meta/example.zig "/tmp/solution/${snake}.zig"
bin/run.sh "${slug}" /tmp/solution /tmp/solution > /dev/null
solution_pattern=$(cat /tmp/solution/results.json | jq -r tostring | grep "{\"version\":2,\"status\":\"pass\"")

errors=""

if [ -z "$solution_pattern" ]; then
errors="${errors}\n\nSolution is incorrect:\n$(cat /tmp/solution/results.json | jq -r '.message')"
local_exit_code=1;
fi

if [ $local_exit_code = 0 ]; then
echo -e "${slug}: \e[32mPASSED\e[0m"
else
exit_code=1
echo -e "${slug}: \e[31mFAILED\e[0m\n${errors}\n\n"
fi
done

exit ${exit_code}
27 changes: 27 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Synopsis:
# Test the zig track's exercises.
#
# For each exercise we test if the example solution
# .meta/example.zig passes the tests.
#
# Usage:
# ./bin/test [slug...]

all_slugs="$*"
if [ -z "$all_slugs" ]; then
all_slugs=$(ls ./exercises/practice/)
fi

docker run --rm --entrypoint bash \
--network none \
--mount type=bind,src="$(realpath ./exercises)",dst=/exercises,ro \
--mount type=bind,src="$(realpath ./bin)",dst=/scripts,ro \
--mount type=tmpfs,dst=/tmp \
exercism/zig-test-runner \
/scripts/.test-in-docker "$all_slugs"

exit_code=$?

exit ${exit_code}
Loading