forked from 01-edu/go-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·74 lines (62 loc) · 1.76 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
set -e
# ! support both variables CODE_EDITOR_RUN_ONLY and EXAM_RUN_ONLY
CODE_EDITOR_RUN_ONLY="${CODE_EDITOR_RUN_ONLY:-$EXAM_RUN_ONLY}"
# ! support both variables CODE_EDITOR_MODE and EXAM_MODE
CODE_EDITOR_MODE="${CODE_EDITOR_MODE:-$EXAM_MODE}"
cp -r student piscine-go
cd piscine-go
if test "$CODE_EDITOR_MODE"; then
go mod init piscine 2>/dev/null
GOSUMDB=off go get github.com/01-edu/[email protected] 2>/dev/null
fi
if test "$CODE_EDITOR_RUN_ONLY" = true; then
# ! to support both the old and the new version of the runner we
# ! need to check the files in the code editor
# if the files in the editor contain the "main.go" we are running a program
if echo "$EDITOR_FILES" | tr ',' '\n' | grep -q '/main.go' || command -v "${EXERCISE}_test" >/dev/null 2>&1; then
go run "./$EXERCISE" "$@"
else
# The exercise is a function
go run . "$@"
fi
exit
fi
if ! test "$CODE_EDITOR_MODE"; then
s=$(gofumpt -d .)
if test "$s"; then
echo 'Your Go files are not correctly formatted :'
echo
echo '$ gofumpt -d .'
echo "$s"
exit 1
fi
fi
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 '\bprint(ln)?\s*\(' {} +; then
echo "Your Go files cannot use print & println builtins"
exit 1
fi
# Check restrictions
if test "$ALLOWED_FUNCTIONS" && test "$FILE"; then
# shellcheck disable=SC2086
rc "$FILE" $ALLOWED_FUNCTIONS
fi
if ! test -e go.mod ; then
echo "Cannot find go.mod file, create your module with:"
echo " go mod init piscine"
exit 1
fi
cp -r /go-tests ~
cd ~/go-tests
# Compile and run test
if command -v "${EXERCISE}_test" >/dev/null 2>&1; then
# The exercise is a program
"${EXERCISE}_test"
else
# The exercise is a function
go run "./tests/${EXERCISE}_test"
fi