Skip to content

Commit 0a1ca7e

Browse files
Add initial version (#7)
1 parent 6abadf5 commit 0a1ca7e

File tree

17 files changed

+128
-24
lines changed

17 files changed

+128
-24
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
/tests/**/*/results.json
1+
/tests/**/results.json
2+
/tests/**/test
3+
/tests/**/test.c
4+
/tests/**/*.actual
5+
/tests/**/*.expected

Dockerfile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
FROM alpine:3.18
1+
FROM alpine:3.20 AS builder
22

3-
# install packages required to run the tests
4-
RUN apk add --no-cache jq coreutils
3+
RUN apk add --no-cache curl
4+
5+
ARG VERSION=0.25.31
6+
7+
RUN curl -O "https://futhark-lang.org/releases/futhark-${VERSION}-linux-x86_64.tar.xz" && \
8+
tar -xJf "futhark-${VERSION}-linux-x86_64.tar.xz" && \
9+
cp "futhark-${VERSION}-linux-x86_64/bin/futhark" /usr/local/bin/
10+
11+
FROM alpine:3.20 AS runtime
12+
13+
RUN apk add --no-cache jq gcc musl-dev
14+
15+
COPY --from=builder /usr/local/bin/futhark /usr/local/bin/futhark
516

617
WORKDIR /opt/test-runner
718
COPY . .

bin/run.sh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,13 @@ echo "${slug}: testing..."
3333

3434
# Run the tests for the provided implementation file and redirect stdout and
3535
# stderr to capture it
36-
test_output=$(false)
37-
# TODO: substitute "false" with the actual command to run the test:
38-
# test_output=$(command_to_run_tests 2>&1)
36+
test_output=$(futhark test "${solution_dir}/test.fut" 2>&1)
3937

4038
# Write the results.json file based on the exit code of the command that was
4139
# just executed that tested the implementation file
4240
if [ $? -eq 0 ]; then
4341
jq -n '{version: 1, status: "pass"}' > ${results_file}
4442
else
45-
# OPTIONAL: Sanitize the output
46-
# In some cases, the test output might be overly verbose, in which case stripping
47-
# the unneeded information can be very helpful to the student
48-
# sanitized_test_output=$(printf "${test_output}" | sed -n '/Test results:/,$p')
49-
50-
# OPTIONAL: Manually add colors to the output to help scanning the output for errors
51-
# If the test output does not contain colors to help identify failing (or passing)
52-
# tests, it can be helpful to manually add colors to the output
53-
# colorized_test_output=$(echo "${test_output}" \
54-
# | GREP_COLOR='01;31' grep --color=always -E -e '^(ERROR:.*|.*failed)$|$' \
55-
# | GREP_COLOR='01;32' grep --color=always -E -e '^.*passed$|$')
56-
5743
jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > ${results_file}
5844
fi
5945

tests/all-fail/all_fail.fut

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def is_leap (year: i32): bool =
2+
!(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"version": 1,
33
"status": "fail",
4-
"message": "TODO: replace with correct output"
4+
"message": "0 failed, 0 passed, 1 to go.\n/opt/test-runner/tests/all-fail/test.fut:\nCompiling with --backend=c:\nRunning compiled program:\nRunning /opt/test-runner/tests/all-fail/test:\nEntry point: main; dataset: #0 (\"2015i32\"):\n/opt/test-runner/tests/all-fail/test.fut.main.0.actual and /opt/test-runner/tests/all-fail/test.fut.main.0.expected do not match:\nValue #0: expected False, got True\nEntry point: main; dataset: #0 (\"1960i32\"):\n/opt/test-runner/tests/all-fail/test.fut.main.0.actual and /opt/test-runner/tests/all-fail/test.fut.main.0.expected do not match:\nValue #0: expected True, got False\nEntry point: main; dataset: #0 (\"2100i32\"):\n/opt/test-runner/tests/all-fail/test.fut.main.0.actual and /opt/test-runner/tests/all-fail/test.fut.main.0.expected do not match:\nValue #0: expected False, got True\n0/1 passed."
55
}

tests/all-fail/test.fut

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import "all_fail"
2+
3+
-- Year not divisible by 4 in common year
4+
-- ==
5+
-- input { 2015 }
6+
-- output { false }
7+
8+
-- Year divisible by 4 and 5 is still a leap year
9+
-- ==
10+
-- input { 1960 }
11+
-- output { true }
12+
13+
-- Year divisible by 100, not divisible by 400 in common year
14+
-- ==
15+
-- input { 2100 }
16+
-- output { false }
17+
18+
let main (year: i32): bool =
19+
is_leap year

tests/empty-file/empty_file.fut

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"version": 1,
33
"status": "fail",
4-
"message": "TODO: replace with correct output"
4+
"message": "0 failed, 0 passed, 1 to go.\n/opt/test-runner/tests/empty-file/test.fut:\nCompiling with --backend=c:\nError at /opt/test-runner/tests/empty-file/test.fut:19:3-10:\nUnknown name \"is_leap\"\nIf you find this error message confusing, uninformative, or wrong, please open an issue:\n https://github.com/diku-dk/futhark/issues\n\n0/1 passed."
55
}

tests/empty-file/test.fut

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import "empty_file"
2+
3+
-- Year not divisible by 4 in common year
4+
-- ==
5+
-- input { 2015 }
6+
-- output { false }
7+
8+
-- Year divisible by 4 and 5 is still a leap year
9+
-- ==
10+
-- input { 1960 }
11+
-- output { true }
12+
13+
-- Year divisible by 100, not divisible by 400 in common year
14+
-- ==
15+
-- input { 2100 }
16+
-- output { false }
17+
18+
let main (year: i32): bool =
19+
is_leap year
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"version": 1,
33
"status": "fail",
4-
"message": "TODO: replace with correct output"
4+
"message": "0 failed, 0 passed, 1 to go.\n/opt/test-runner/tests/partial-fail/test.fut:\nCompiling with --backend=c:\nRunning compiled program:\nRunning /opt/test-runner/tests/partial-fail/test:\nEntry point: main; dataset: #0 (\"2100i32\"):\n/opt/test-runner/tests/partial-fail/test.fut.main.0.actual and /opt/test-runner/tests/partial-fail/test.fut.main.0.expected do not match:\nValue #0: expected False, got True\n0/1 passed."
55
}

0 commit comments

Comments
 (0)