Skip to content

Commit 70158e5

Browse files
version one test runner for factor
1 parent 17c481f commit 70158e5

19 files changed

Lines changed: 73 additions & 18 deletions

Dockerfile

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
FROM alpine:3.18
1+
FROM debian:bookworm-slim AS builder
22

3-
# install packages required to run the tests
4-
RUN apk add --no-cache jq coreutils
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
bash curl git g++ make wget ca-certificates \
5+
&& rm -rf /var/lib/apt/lists/*
6+
7+
WORKDIR /opt
8+
RUN git clone https://github.com/factor/factor.git && \
9+
cd factor && \
10+
git checkout cd14ceed53f6f9a43bbd3aec3950d8beb5439ed8
11+
WORKDIR /opt/factor
12+
RUN ./build.sh update
13+
14+
# Remove files not needed at runtime
15+
RUN rm -rf .git build vm src misc Factor.app \
16+
factor.image.fresh boot.*.image libfactor.a libfactor-ffi-test.so \
17+
extra GNUmakefile Nmakefile LICENSE.txt README.md \
18+
build.sh build.cmd unmaintained
19+
20+
FROM debian:bookworm-slim
21+
22+
RUN apt-get update && apt-get install -y --no-install-recommends \
23+
bash jq coreutils libstdc++6 \
24+
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
25+
/usr/share/zoneinfo /usr/share/perl5 /var/lib/dpkg /var/cache
26+
27+
COPY --from=builder /opt/factor /opt/factor
28+
ENV PATH="/opt/factor:${PATH}" \
29+
XDG_CACHE_HOME=/tmp
530

631
WORKDIR /opt/test-runner
732
COPY . .

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exercism Factor Test Runner
22

3-
The Docker image to automatically run tests on Factor solutions submitted to [Exercism].
3+
The Docker image to automatically run tests on [Factor] solutions submitted to [Exercism].
44

55
## Getting started
66

@@ -69,3 +69,4 @@ Bear in mind though that the performance on Exercism's production servers is oft
6969
[test-runners]: https://github.com/exercism/docs/tree/main/building/tooling/test-runners
7070
[golden]: https://ro-che.info/articles/2017-12-04-golden-tests
7171
[exercism]: https://exercism.org
72+
[factor]: https://factorcode.org/

bin/run-tests-in-docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ docker run \
2323
--rm \
2424
--network none \
2525
--read-only \
26+
--user "$(id -u):$(id -g)" \
2627
--mount type=bind,src="${PWD}/tests",dst=/opt/test-runner/tests \
2728
--mount type=tmpfs,dst=/tmp \
2829
--volume "${PWD}/bin/run-tests.sh:/opt/test-runner/bin/run-tests.sh" \

bin/run-tests.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ for test_dir in tests/*; do
2020

2121
bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}"
2222

23-
# OPTIONAL: Normalize the results file
24-
# If the results.json file contains information that changes between
25-
# different test runs (e.g. timing information or paths), you should normalize
26-
# the results file to allow the diff comparison below to work as expected
27-
23+
# Normalize paths in results to match Docker environment
2824
file="results.json"
25+
sed -i "s~${test_dir_path}~/opt/test-runner/tests/${test_dir_name}~g" "${test_dir_path}/${file}"
2926
expected_file="expected_${file}"
3027
echo "${test_dir_name}: comparing ${file} to ${expected_file}"
3128

bin/run.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ mkdir -p "${output_dir}"
3131

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

34+
# Remove STOP-HERE lines to unskip all tests
35+
sed -i '/STOP-HERE/d' "${solution_dir}/${slug}/${slug}-tests.factor"
36+
3437
# Run the tests for the provided implementation file and redirect stdout and
3538
# 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)
39+
test_output=$(cd "${solution_dir}" && factor -e="USING: vocabs.loader tools.test tools.test.private namespaces kernel system ; \".\" add-vocab-root \"${slug}\" require \"${slug}\" test test-failures get empty? [ 0 exit ] [ 1 exit ] if" 2>&1)
40+
test_exit=$?
41+
test_output=$(printf '%s\n' "${test_output}" | grep -v "^fatal error for monitor root")
3942

4043
# Write the results.json file based on the exit code of the command that was
4144
# just executed that tested the implementation file
42-
if [ $? -eq 0 ]; then
45+
if [ $test_exit -eq 0 ]; then
4346
jq -n '{version: 1, status: "pass"}' > ${results_file}
4447
else
4548
# OPTIONAL: Sanitize the output
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
USING: all-fail tools.test ;
2+
{ "hello" } [ greet ] unit-test
3+
{ "world" } [ greet ] unit-test
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
USING: kernel ;
2+
IN: all-fail
3+
4+
: greet ( -- str ) "wrong" ;
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": "Unit Test: { { \"hello\" } [ greet ] }\n--> test failed!\nUnit Test: { { \"world\" } [ greet ] }"
55
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
USING: empty-file tools.test ;
2+
{ "hello" } [ greet ] unit-test

tests/empty-file/empty-file/empty-file.factor

Whitespace-only changes.

0 commit comments

Comments
 (0)