Browse Source

Add shellcheck, simplify image building

content-update
4 years ago committed by xpetit
parent
commit
fb4eea5c99
  1. 16
      go/tests/Dockerfile
  2. 12
      go/tests/entrypoint.sh
  3. 2
      go/tests/lib/lib.go
  4. 6
      sh/tests/entrypoint.sh

16
go/tests/Dockerfile

@ -4,19 +4,7 @@ ENV GIT_TERMINAL_PROMPT=0
RUN apk add --no-cache git
RUN go get golang.org/x/tools/cmd/goimports
RUN go get github.com/01-edu/z01
WORKDIR src
COPY entrypoint.sh /usr/local/bin
COPY . .
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
COPY . src
RUN go install rc prog/...
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)

12
go/tests/entrypoint.sh

@ -1,5 +1,6 @@
#!/bin/sh
set -o noglob
set -o errexit
set -o nounset
IFS='
@ -13,7 +14,7 @@ if test "$REPOSITORY"; then
git clone --quiet --depth=1 --shallow-submodules http://root:"${password}"@"$REPOSITORY" .
else
first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1)
mkdir -p "$(dirname $first_file)"
mkdir -p "$(dirname "$first_file")"
cat > "$first_file"
fi
@ -28,6 +29,7 @@ fi
# Check restrictions
if test "$ALLOWED_FUNCTIONS"; then
for file in $EXPECTED_FILES; do
# shellcheck disable=SC2086
rc "$file" $ALLOWED_FUNCTIONS
done
fi
@ -35,11 +37,11 @@ fi
# Compile and run test
cd
GOPATH=$HOME:$GOPATH
if command -v "$EXERCISE"_test &>/dev/null; then
if command -v "${EXERCISE}_test" >/dev/null 2>&1; then
# The exercise is a program
go build "student/$EXERCISE"
"$EXERCISE"_test
go build "./src/student/$EXERCISE"
"${EXERCISE}_test"
else
# The exercise is a function
go run "$EXERCISE"_test
go run "func/${EXERCISE}_test"
fi

2
go/tests/lib/lib.go

@ -372,7 +372,7 @@ func ChallengeMainStdin(exercise, input string, args ...string) {
return fmt.Sprintf("echo $?\n%d\n$", code)
}
student, studentCode := run("./" + exercise)
solution, solutionCode := run(exercise + "_correct")
solution, solutionCode := run(exercise + "_prog")
if solutionCode == 0 {
if studentCode != 0 {
Fatalln("Your program fails (non-zero exit status) when it should not :\n" +

6
sh/tests/entrypoint.sh

@ -13,7 +13,7 @@ if test "$REPOSITORY"; then
git clone --quiet --depth=1 --shallow-submodules http://root:"${password}"@"$REPOSITORY" .
else
first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1)
mkdir -p "$(dirname $first_file)"
mkdir -p "$(dirname "$first_file")"
cat > "$first_file"
chmod +x "$first_file"
fi
@ -21,9 +21,9 @@ fi
cd
cp -rT /app .
if ! test -f ${EXERCISE}_test.sh; then
if ! test -f "${EXERCISE}_test.sh"; then
echo No test file found for the exercise : "$EXERCISE"
exit 1
fi
bash ${EXERCISE}_test.sh
bash "${EXERCISE}_test.sh"

Loading…
Cancel
Save