mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
#!/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 |
|
|
|
# Check formatting |
|
s=$(goimports -d .) |
|
if test "$s"; then |
|
echo '$ goimports -d .' |
|
echo "$s" |
|
exit 1 |
|
fi |
|
|
|
if find . -type f -name '*.go' -exec grep -qE '\tprint(ln)?\(' {} +; then |
|
echo "print & println builtins are forbidden" |
|
exit 1 |
|
fi |
|
|
|
# Check restrictions |
|
if test "$ALLOWED_FUNCTIONS" && test "$EXPECTED_FILES"; then |
|
IFS=' ' |
|
first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1) |
|
# shellcheck disable=SC2086 |
|
rc "$first_file" $ALLOWED_FUNCTIONS |
|
fi |
|
IFS=' |
|
' |
|
# Compile and run test |
|
cd |
|
GOPATH=$HOME:$GOPATH |
|
if command -v "${EXERCISE}_test" >/dev/null 2>&1; then |
|
# The exercise is a program |
|
go build "./src/student/$EXERCISE" |
|
"${EXERCISE}_test" |
|
else |
|
# The exercise is a function |
|
go build "func/${EXERCISE}_test" |
|
"./${EXERCISE}_test" |
|
fi
|
|
|