diff --git a/containers/swift/Dockerfile b/containers/swift/Dockerfile new file mode 100644 index 0000000..4596405 --- /dev/null +++ b/containers/swift/Dockerfile @@ -0,0 +1,7 @@ +FROM drewcrawford/swift:latest + +COPY ./compile.sh /bin/compile.sh +COPY ./run.sh /bin/run.sh + +RUN chmod 777 /bin/compile.sh; \ + chmod 777 /bin/run.sh diff --git a/containers/swift/compile.sh b/containers/swift/compile.sh new file mode 100644 index 0000000..feca6b4 --- /dev/null +++ b/containers/swift/compile.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +swiftc program.swift 2> compile.stderr 1> compile.stdout diff --git a/containers/swift/run.sh b/containers/swift/run.sh new file mode 100644 index 0000000..77e1d32 --- /dev/null +++ b/containers/swift/run.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +chmod 777 ./program +./program < run.stdin 1> run.stdout 2> run.stderr \ No newline at end of file diff --git a/test.sh b/test.sh index 35d1a9b..d012321 100755 --- a/test.sh +++ b/test.sh @@ -39,3 +39,7 @@ @test "test ruby" { bash tests/ruby/test_worker.sh } + +@test "test swift" { + bash tests/swift/test_worker.sh +} diff --git a/tests/swift/program.swift b/tests/swift/program.swift new file mode 100644 index 0000000..dd136ec --- /dev/null +++ b/tests/swift/program.swift @@ -0,0 +1 @@ +print("Hello \(readLine()!)") diff --git a/tests/swift/run.stdin b/tests/swift/run.stdin new file mode 100644 index 0000000..beef906 --- /dev/null +++ b/tests/swift/run.stdin @@ -0,0 +1 @@ +World \ No newline at end of file diff --git a/tests/swift/test_worker.sh b/tests/swift/test_worker.sh new file mode 100755 index 0000000..375232a --- /dev/null +++ b/tests/swift/test_worker.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +pushd $(dirname "$0") +DIR=$(pwd) +RUNBOX="${DIR}/runbox" + +echo $RUNBOX +# Create runbox +mkdir -p $RUNBOX + +# Copy source to runbox +cp $DIR/program.swift $RUNBOX/program.swift +cp $DIR/run.stdin $RUNBOX/run.stdin + +# Test Compile +docker run \ + --cpus="1" \ + --memory="100m" \ + --ulimit nofile=64:64 \ + --rm \ + --read-only \ + -v "$RUNBOX":/usr/src/runbox \ + -v "$RUNBOX":/tmp \ + -w /usr/src/runbox codingblocks/judge-worker-swift \ + bash -c "/bin/compile.sh && /bin/run.sh" + +ls -lh ${RUNBOX} + +expected="Hello World" +actual="$(cat ${RUNBOX}/run.stdout)" +if [ "$expected" == "$actual" ] ;then + : +else + echo "MISMATCH: Expected = $expected; Actual = $actual" + exit 1 +fi + +# Delete runbox +sudo rm -rf $RUNBOX