Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions containers/swift/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions containers/swift/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

swiftc program.swift 2> compile.stderr 1> compile.stdout
4 changes: 4 additions & 0 deletions containers/swift/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

chmod 777 ./program
./program < run.stdin 1> run.stdout 2> run.stderr
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@
@test "test ruby" {
bash tests/ruby/test_worker.sh
}

@test "test swift" {
bash tests/swift/test_worker.sh
}
1 change: 1 addition & 0 deletions tests/swift/program.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello \(readLine()!)")
1 change: 1 addition & 0 deletions tests/swift/run.stdin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
World
38 changes: 38 additions & 0 deletions tests/swift/test_worker.sh
Original file line number Diff line number Diff line change
@@ -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