From 4cb9d7cdf8d2d490ef4c3981530c94677ac3328c Mon Sep 17 00:00:00 2001 From: xpetit <32063953+xpetit@users.noreply.github.com> Date: Tue, 6 Oct 2020 18:31:45 +0000 Subject: [PATCH] Make tester work again (need to fix sh exercises with curl) --- dom/Dockerfile | 7 +------ dom/entrypoint.sh | 18 +--------------- go/tests/Dockerfile | 5 ++--- go/tests/entrypoint.sh | 47 ++++++++++++++++-------------------------- go/tests/lib/lib.go | 2 +- js/tests/Dockerfile | 6 +----- js/tests/entrypoint.sh | 20 +----------------- sh/tests/Dockerfile | 4 +--- sh/tests/entrypoint.sh | 25 +++++----------------- 9 files changed, 31 insertions(+), 103 deletions(-) diff --git a/dom/Dockerfile b/dom/Dockerfile index 758f0c85..e82d7824 100644 --- a/dom/Dockerfile +++ b/dom/Dockerfile @@ -1,11 +1,6 @@ FROM buildkite/puppeteer:5.2.1 -ENV GIT_TERMINAL_PROMPT=0 -RUN apt-get update -RUN apt-get install -y git -COPY --from=mkcert-ca . /usr/local/share/ca-certificates -RUN update-ca-certificates WORKDIR /app COPY dom . COPY subjects ./subjects -ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"] +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/dom/entrypoint.sh b/dom/entrypoint.sh index 0257e15f..e8c31a03 100644 --- a/dom/entrypoint.sh +++ b/dom/entrypoint.sh @@ -1,22 +1,6 @@ #!/bin/sh -set -o noglob -set -o errexit -set -o nounset -IFS=' -' - -mkdir student -cd student - -if test "$REPOSITORY"; then - password=$(cat) - git clone --quiet --depth=1 --shallow-submodules https://root:"${password}"@"$REPOSITORY" . -else - first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1) - mkdir -p "$(dirname "$first_file")" - cat > "$first_file" -fi +set -e cd /app node --no-warnings --unhandled-rejections=strict test.js "${EXERCISE}" diff --git a/go/tests/Dockerfile b/go/tests/Dockerfile index e6d84300..2c8cd15b 100644 --- a/go/tests/Dockerfile +++ b/go/tests/Dockerfile @@ -7,7 +7,6 @@ RUN go get github.com/01-edu/z01 COPY . src RUN go get rc RUN go install rc prog/... + COPY entrypoint.sh /usr/local/bin -COPY --from=mkcert-ca . /usr/local/share/ca-certificates -RUN update-ca-certificates -ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"] +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/go/tests/entrypoint.sh b/go/tests/entrypoint.sh index ed4dd66f..310d7342 100755 --- a/go/tests/entrypoint.sh +++ b/go/tests/entrypoint.sh @@ -1,25 +1,10 @@ #!/bin/sh -set -o noglob -set -o errexit -set -o nounset -IFS=' -' - -mkdir -p src/student -cd src/student - -if test "$REPOSITORY"; then - password=$(cat) - git clone --quiet --depth=1 --shallow-submodules https://root:"${password}"@"$REPOSITORY" . -else - first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1) - mkdir -p "$(dirname "$first_file")" - cat > "$first_file" -fi +set -e + +cd student -set +o nounset # TODO: Remove me after this variable is always set in all/tester/main.go -if test "$SKIP_FORMATTING"; then +if ! test "$SKIP_FORMATTING"; then s=$(goimports -d .) if test "$s"; then echo 'Your Go files are not correctly formatted :' @@ -29,7 +14,11 @@ if test "$SKIP_FORMATTING"; then exit 1 fi fi -set -o nounset # TODO: Remove me after this variable is always set in all/tester/main.go + +if ! find . -type f -name '*.go' | grep -q .; then + echo "Missing Go file: $FILE" + exit 1 +fi if find . -type f -name '*.go' -exec grep -qE 'print(ln)?\(' {} +; then echo "Your Go files cannot use print & println builtins" @@ -37,23 +26,23 @@ if find . -type f -name '*.go' -exec grep -qE 'print(ln)?\(' {} +; then fi # Check restrictions -if test "$ALLOWED_FUNCTIONS" && test "$EXPECTED_FILES"; then - IFS=' ' - first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1) +if test "$ALLOWED_FUNCTIONS" && test "$FILE"; then # shellcheck disable=SC2086 - rc "$first_file" $ALLOWED_FUNCTIONS + rc "$FILE" $ALLOWED_FUNCTIONS fi -IFS=' -' -# Compile and run test + cd -GOPATH=$HOME:$GOPATH + +# Compile and run test if command -v "${EXERCISE}_test" >/dev/null 2>&1; then # The exercise is a program - go build "./src/student/$EXERCISE" + go build -o exe "./student/$EXERCISE" "${EXERCISE}_test" else # The exercise is a function + mkdir src + ln -s $(pwd)/student $(pwd)/src/student + GOPATH=$GOPATH:$PWD go build "func/${EXERCISE}_test" "./${EXERCISE}_test" fi diff --git a/go/tests/lib/lib.go b/go/tests/lib/lib.go index 3229ed86..e2a9fe35 100644 --- a/go/tests/lib/lib.go +++ b/go/tests/lib/lib.go @@ -371,7 +371,7 @@ func ChallengeMainStdin(exercise, input string, args ...string) { code := func(code int) string { return fmt.Sprintf("echo $?\n%d\n$", code) } - student, studentCode := run("./" + exercise) + student, studentCode := run("./exe") solution, solutionCode := run(exercise + "_prog") if solutionCode == 0 { if studentCode != 0 { diff --git a/js/tests/Dockerfile b/js/tests/Dockerfile index 8a806081..9ac1cd56 100644 --- a/js/tests/Dockerfile +++ b/js/tests/Dockerfile @@ -1,9 +1,5 @@ FROM node:14.7.0-alpine3.12 -ENV GIT_TERMINAL_PROMPT=0 -RUN apk add --no-cache git -COPY --from=mkcert-ca . /usr/local/share/ca-certificates -RUN update-ca-certificates WORKDIR /app COPY . . -ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"] +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/js/tests/entrypoint.sh b/js/tests/entrypoint.sh index f3c85d9f..39a41cfe 100644 --- a/js/tests/entrypoint.sh +++ b/js/tests/entrypoint.sh @@ -1,23 +1,5 @@ #!/bin/sh -set -o noglob -set -o errexit -set -o nounset -IFS=' -' - -mkdir student -cd student - -if test "$REPOSITORY"; then - password=$(cat) - git clone --quiet --depth=1 --shallow-submodules https://root:"${password}"@"$REPOSITORY" . -else - first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1) - mkdir -p "$(dirname "$first_file")" - cat > "$first_file" -fi - -cd +set -e node /app/test.mjs "${EXERCISE}" diff --git a/sh/tests/Dockerfile b/sh/tests/Dockerfile index 6040365e..f7efadb8 100644 --- a/sh/tests/Dockerfile +++ b/sh/tests/Dockerfile @@ -2,7 +2,5 @@ FROM debian:10.5-slim RUN apt-get update RUN apt-get -y install jq curl git -COPY --from=mkcert-ca . /usr/local/share/ca-certificates -RUN update-ca-certificates COPY . /app -ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"] +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/sh/tests/entrypoint.sh b/sh/tests/entrypoint.sh index cf072abd..4c83af67 100755 --- a/sh/tests/entrypoint.sh +++ b/sh/tests/entrypoint.sh @@ -1,28 +1,13 @@ #!/usr/bin/env bash -# Unofficial Bash Strict Mode -set -euo pipefail -IFS=' -' +set -e -mkdir student -cd student - -if test "$REPOSITORY"; then - password=$(cat) - git clone --quiet --depth=1 --shallow-submodules https://root:"${password}"@"$REPOSITORY" . -else - first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1) - mkdir -p "$(dirname "$first_file")" - cat > "$first_file" - chmod +x "$first_file" -fi - -cd -cp -rT /app . +cp -r /app . +cp -a student app +cd app if ! test -f "${EXERCISE}_test.sh"; then - echo No test file found for the exercise : "$EXERCISE" + echo "No test file found for the exercise : $EXERCISE" exit 1 fi