Browse Source

working-ish

content-update
Xavier Petit 4 years ago committed by xpetit
parent
commit
4cd53cebe1
  1. 22
      go/Dockerfile
  2. 48
      go/entrypoint.sh
  3. 4
      go/src/lib/lib.go

22
go/Dockerfile

@ -1,8 +1,20 @@
FROM golang:1-alpine FROM golang:1-alpine
RUN apk add git RUN apk add --no-cache git nano
RUN go get golang.org/x/tools/cmd/goimports RUN go get golang.org/x/tools/cmd/goimports
RUN go get github.com/01-edu/z01 WORKDIR src
RUN go get github.com/01-edu/public/rc COPY entrypoint.sh /usr/local/bin
COPY . /app COPY src .
ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"] RUN go install rc
RUN find -mindepth 2 -maxdepth 2 -name '*_correct' -type d|xargs go install
RUN find -mindepth 2 -maxdepth 2 -name '*_correct' -type d|cut -d/ -f1-2|xargs go install
RUN find -mindepth 2 -maxdepth 2 -name '*_correct' -type d|cut -d/ -f1-2|xargs rm -rf
WORKDIR /tmp
USER 1000
ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"]
# compare performance with and without :
# ENV CGO_ENABLED 0
# -trimpath -ldflags="-s -w"
# -i
# -a (to rebuild everything and prepare .a files)
# git clone in Dockerfile to make it work anywhere (no COPY)

48
go/entrypoint.sh

@ -5,30 +5,36 @@ set -o pipefail
IFS=' IFS='
' '
cp -rT /app /jail mkdir -p src/student
cd src/student
if test "$EXPECTED_FILES"; then if test "$REPOSITORY"; then
echo -n 'Formatting (with `goimports -d .`) ... ' git clone --depth=1 --shallow-submodules "$REPOSITORY" .
cd /jail/student
s=$(goimports -d .)
if test "$s"; then
echo
echo "$s"
exit 1
fi
echo OK
if test "$ALLOWED_FUNCTIONS"; then
rc "$EXPECTED_FILES" $ALLOWED_FUNCTIONS
fi
fi fi
cd /jail # Check formatting
s=$(goimports -d .)
if ! test -f ${EXERCISE}_test.go; then if test "$s"; then
echo No test file found for the exercise : "$EXERCISE" echo '$ goimports -d .'
echo "$s"
exit 1 exit 1
fi fi
# TODO: maybe change btree exercises so that they work without student code and then delete this line # Check restrictions
find . -name '*_test.go' ! -name ${EXERCISE}_test.go -delete if test "$ALLOWED_FUNCTIONS"; then
go test -failfast '-run=(?i)'test${EXERCISE} for file in $EXPECTED_FILES; do
rc "$file" $ALLOWED_FUNCTIONS
done
fi
# Compile test
cd
GOPATH=$GOPATH:$HOME
if command -v "$EXERCISE"_test &>/dev/null; then
# The exercise is a program
go build "student/$EXERCISE"
"$EXERCISE"_test
else
# The exercise is a function
go run "$EXERCISE"_test
fi

4
go/src/lib/lib.go

@ -362,8 +362,8 @@ func ChallengeMain(exercise string, args ...string) {
code := func(code int) string { code := func(code int) string {
return fmt.Sprintf("echo $?\n%d\n$", code) return fmt.Sprintf("echo $?\n%d\n$", code)
} }
student, studentCode := run("./student") student, studentCode := run("./" + exercise)
solution, solutionCode := run("test_" + exercise) solution, solutionCode := run(exercise + "_correct")
if solutionCode != 0 { if solutionCode != 0 {
if studentCode == 0 { if studentCode == 0 {
Fatalln("Your program does not fail when it should (with a non-zero exit status) :" + "\n" + Fatalln("Your program does not fail when it should (with a non-zero exit status) :" + "\n" +

Loading…
Cancel
Save