Skip to content

Commit

Permalink
Initial commit (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Nov 12, 2024
1 parent b755607 commit a3ba5a7
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 41 deletions.
18 changes: 8 additions & 10 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
.git/
.appends/
.github/
.gitattributes
.gitignore
Dockerfile
bin/run-in-docker.sh
bin/run-tests-in-docker.sh
bin/run-tests.sh
tests/
/.git/
/.appends/
/.github/
/.gitattributes
/.gitignore
/bin/
!bin/run.sh
/tests/
13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
FROM alpine:3.18
FROM rust:1.82.0-alpine3.20 AS builder

# install packages required to run the tests
RUN apk add --no-cache jq coreutils
RUN apk add --no-cache linux-headers make musl-dev

RUN cargo install [email protected]

FROM alpine:3.20

RUN apk add --no-cache jq

COPY --from=builder /usr/local/cargo/bin/uiua /usr/local/bin

WORKDIR /opt/test-runner
COPY . .
Expand Down
32 changes: 9 additions & 23 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
# Example:
# ./bin/run.sh two-fer path/to/solution/folder/ path/to/output/directory/

# If any required arguments is missing, print the usage and exit
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
if [ $# -lt 3 ]; then
echo "usage: ./bin/run.sh exercise-slug path/to/solution/folder/ path/to/output/directory/"
exit 1
fi
Expand All @@ -26,35 +25,22 @@ solution_dir=$(realpath "${2%/}")
output_dir=$(realpath "${3%/}")
results_file="${output_dir}/results.json"

# Create the output directory if it doesn't exist
mkdir -p "${output_dir}"

echo "${slug}: testing..."

# Run the tests for the provided implementation file and redirect stdout and
# stderr to capture it
test_output=$(false)
# TODO: substitute "false" with the actual command to run the test:
# test_output=$(command_to_run_tests 2>&1)
test_output=$(uiua test "${solution_dir}/tests.ua")

# Write the results.json file based on the exit code of the command that was
# just executed that tested the implementation file
if [ $? -eq 0 ]; then
jq -n '{version: 1, status: "pass"}' > ${results_file}
else
# OPTIONAL: Sanitize the output
# In some cases, the test output might be overly verbose, in which case stripping
# the unneeded information can be very helpful to the student
# sanitized_test_output=$(printf "${test_output}" | sed -n '/Test results:/,$p')

# OPTIONAL: Manually add colors to the output to help scanning the output for errors
# If the test output does not contain colors to help identify failing (or passing)
# tests, it can be helpful to manually add colors to the output
# colorized_test_output=$(echo "${test_output}" \
# | GREP_COLOR='01;31' grep --color=always -E -e '^(ERROR:.*|.*failed)$|$' \
# | GREP_COLOR='01;32' grep --color=always -E -e '^.*passed$|$')

jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > ${results_file}
if printf "${test_output}" | grep -q -E "tests? (failed|passed)"; then
status="fail"
else
status="error"
fi

jq -n --arg output "${test_output}" --arg status "${status}" '{version: 1, status: $status, message: $output}' > "${results_file}"
fi

echo "${slug}: done"
1 change: 1 addition & 0 deletions tests/all-fail/all-fail.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Square ← ∘
2 changes: 1 addition & 1 deletion tests/all-fail/expected_results.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"status": "fail",
"message": "TODO: replace with correct output"
"message": "Error: 2\n at /opt/test-runner/tests/all-fail/tests.ua:3:1\n3 | ⍤⤙≍ 4 Square 2\n\nError: 4\n at /opt/test-runner/tests/all-fail/tests.ua:4:1\n4 | ⍤⤙≍ 16 Square 4\n\nError: 5\n at /opt/test-runner/tests/all-fail/tests.ua:5:1\n5 | ⍤⤙≍ 25 Square 5\n\nAll 3 tests failed"
}
5 changes: 5 additions & 0 deletions tests/all-fail/tests.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~ "all-fail.ua" ~ Square

⍤⤙≍ 4 Square 2
⍤⤙≍ 16 Square 4
⍤⤙≍ 25 Square 5
Empty file added tests/empty-file/empty-file.ua
Empty file.
4 changes: 2 additions & 2 deletions tests/empty-file/expected_results.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"status": "fail",
"message": "TODO: replace with correct output"
"status": "error",
"message": "Error: `Square` not found in module tests/empty-file/empty-file.ua\n at /opt/test-runner/tests/empty-file/tests.ua:1:21\n1 | ~ \"empty-file.ua\" ~ Square\n ──────\nError: Unknown identifier `Square`\n at /opt/test-runner/tests/empty-file/tests.ua:3:7\n3 | ⍤⤙≍ 4 Square 2\n ──────"
}
5 changes: 5 additions & 0 deletions tests/empty-file/tests.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~ "empty-file.ua" ~ Square

⍤⤙≍ 4 Square 2
⍤⤙≍ 16 Square 4
⍤⤙≍ 25 Square 5
2 changes: 1 addition & 1 deletion tests/partial-fail/expected_results.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"status": "fail",
"message": "TODO: replace with correct output"
"message": "Error: 8\n at /opt/test-runner/tests/partial-fail/tests.ua:4:1\n4 | ⍤⤙≍ 16 Square 4\n\nError: 10\n at /opt/test-runner/tests/partial-fail/tests.ua:5:1\n5 | ⍤⤙≍ 25 Square 5\n\n1 test passed, 2 failed"
}
1 change: 1 addition & 0 deletions tests/partial-fail/partial-fail.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Square ← +.
5 changes: 5 additions & 0 deletions tests/partial-fail/tests.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~ "partial-fail.ua" ~ Square

⍤⤙≍ 4 Square 2
⍤⤙≍ 16 Square 4
⍤⤙≍ 25 Square 5
1 change: 1 addition & 0 deletions tests/success/success.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Square ← ×.
5 changes: 5 additions & 0 deletions tests/success/tests.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~ "success.ua" ~ Square

⍤⤙≍ 4 Square 2
⍤⤙≍ 16 Square 4
⍤⤙≍ 25 Square 5
2 changes: 1 addition & 1 deletion tests/syntax-error/expected_results.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"status": "error",
"message": "TODO: replace with correct output"
"message": "Error: Unexpected token ]\n at tests/syntax-error/syntax-error.ua:1:11\n1 | Square ←@[]]1)\n"
}
1 change: 1 addition & 0 deletions tests/syntax-error/syntax-error.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Square ←@[]]1)
5 changes: 5 additions & 0 deletions tests/syntax-error/tests.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~ "syntax-error.ua" ~ Square

⍤⤙≍ 4 Square 2
⍤⤙≍ 16 Square 4
⍤⤙≍ 25 Square 5

0 comments on commit a3ba5a7

Please sign in to comment.