Skip to content

Commit 4d98b67

Browse files
Merge branch 'master' into swift
2 parents 32f8196 + 08fc5c6 commit 4d98b67

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

containers/golang/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM alpine:3.6
2+
3+
RUN apk add --no-cache bash go="1.8.4-r0"
4+
5+
COPY ./compile.sh /bin/compile.sh
6+
COPY ./run.sh /bin/run.sh
7+
8+
RUN chmod 777 /bin/compile.sh; \
9+
chmod 777 /bin/run.sh

containers/golang/compile.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env bash

containers/golang/run.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
chmod 777 main.go
4+
go run main.go < run.stdin 1> run.stdout 2> run.stderr

test.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
bash tests/csharp/test_worker.sh
1313
}
1414

15+
@test "test golang" {
16+
bash tests/csharp/test_worker.sh
17+
}
18+
1519
@test "test java8" {
1620
bash tests/java8/test_worker.sh
1721
}
@@ -38,4 +42,4 @@
3842

3943
@test "test swift" {
4044
bash tests/swift/test_worker.sh
41-
}
45+
}

tests/golang/main.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main;
2+
3+
import "fmt";
4+
5+
func main() {
6+
var text string
7+
fmt.Scanf("%s", &text)
8+
fmt.Println("Hello " + text)
9+
10+
}

tests/golang/run.stdin

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
World

tests/golang/test_worker.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
pushd $(dirname "$0")
3+
DIR=$(pwd)
4+
RUNBOX="${DIR}/runbox"
5+
6+
echo $RUNBOX
7+
# Remove RUNBOX
8+
rm -rf $RUNBOX
9+
10+
# Create runbox
11+
mkdir -p $RUNBOX
12+
13+
# Copy source to runbox
14+
cp -fv $DIR/main.go $RUNBOX/main.go
15+
cp -fv $DIR/run.stdin $RUNBOX/run.stdin
16+
17+
# Test Compile
18+
docker run \
19+
--cpus="1" \
20+
--memory="100m" \
21+
--ulimit nofile=64:64 \
22+
--rm \
23+
--read-only \
24+
-v "$RUNBOX":/usr/src/runbox \
25+
-v "$RUNBOX":/tmp \
26+
-w /usr/src/runbox codingblocks/judge-worker-golang \
27+
bash -c "/bin/compile.sh && /bin/run.sh"
28+
29+
ls -lh ${RUNBOX}
30+
31+
expected="Hello World"
32+
actual="$(cat ${RUNBOX}/run.stdout)"
33+
if [ "$expected" == "$actual" ] ;then
34+
:
35+
else
36+
echo "MISMATCH: Expected = $expected; Actual = $actual"
37+
exit 1
38+
fi
39+
40+
# Delete runbox
41+
rm -rf $RUNBOX

0 commit comments

Comments
 (0)