From 36910151b956334221553661880e958de140edfb Mon Sep 17 00:00:00 2001 From: Kapil Date: Wed, 11 Jul 2018 16:20:05 +0530 Subject: [PATCH 1/2] Add support for swift --- containers/swift/Dockerfile | 7 +++++++ containers/swift/compile.sh | 3 +++ containers/swift/run.sh | 4 ++++ test.sh | 3 +++ tests/swift/program.swift | 1 + tests/swift/run.stdin | 1 + tests/swift/test_worker.sh | 38 +++++++++++++++++++++++++++++++++++++ 7 files changed, 57 insertions(+) create mode 100644 containers/swift/Dockerfile create mode 100644 containers/swift/compile.sh create mode 100644 containers/swift/run.sh create mode 100644 tests/swift/program.swift create mode 100644 tests/swift/run.stdin create mode 100755 tests/swift/test_worker.sh 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 4592172..4c677c6 100755 --- a/test.sh +++ b/test.sh @@ -36,3 +36,6 @@ 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..696a153 --- /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 +rm -rf $RUNBOX From 4e28763b96719e1d050929b9674146daf41c830a Mon Sep 17 00:00:00 2001 From: Kapil Date: Wed, 11 Jul 2018 16:28:01 +0530 Subject: [PATCH 2/2] Update test for swift --- tests/swift/test_worker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/swift/test_worker.sh b/tests/swift/test_worker.sh index 696a153..375232a 100755 --- a/tests/swift/test_worker.sh +++ b/tests/swift/test_worker.sh @@ -35,4 +35,4 @@ else fi # Delete runbox -rm -rf $RUNBOX +sudo rm -rf $RUNBOX