2020-12-30 18:26:25 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-02-21 17:07:12 +03:00
|
|
|
# This comment is used to simplify checking local copies of the script. Bump
|
|
|
|
# this number every time a significant change is made to this script.
|
|
|
|
#
|
2024-11-08 17:18:16 +03:00
|
|
|
# AdGuard-Project-Version: 6
|
2023-02-21 17:07:12 +03:00
|
|
|
|
2020-12-30 18:26:25 +03:00
|
|
|
verbose="${VERBOSE:-0}"
|
2021-05-19 20:31:20 +03:00
|
|
|
readonly verbose
|
2020-12-30 18:26:25 +03:00
|
|
|
|
|
|
|
# Verbosity levels:
|
|
|
|
# 0 = Don't print anything except for errors.
|
|
|
|
# 1 = Print commands, but not nested commands.
|
|
|
|
# 2 = Print everything.
|
2024-11-08 17:18:16 +03:00
|
|
|
if [ "$verbose" -gt '1' ]; then
|
2020-12-30 18:26:25 +03:00
|
|
|
set -x
|
2021-06-10 20:09:00 +03:00
|
|
|
v_flags='-v=1'
|
|
|
|
x_flags='-x=1'
|
2024-11-08 17:18:16 +03:00
|
|
|
elif [ "$verbose" -gt '0' ]; then
|
2020-12-30 18:26:25 +03:00
|
|
|
set -x
|
2021-06-10 20:09:00 +03:00
|
|
|
v_flags='-v=1'
|
|
|
|
x_flags='-x=0'
|
2020-12-30 18:26:25 +03:00
|
|
|
else
|
|
|
|
set +x
|
2021-06-10 20:09:00 +03:00
|
|
|
v_flags='-v=0'
|
|
|
|
x_flags='-x=0'
|
2020-12-30 18:26:25 +03:00
|
|
|
fi
|
2021-05-19 20:31:20 +03:00
|
|
|
readonly v_flags x_flags
|
2020-12-30 18:26:25 +03:00
|
|
|
|
|
|
|
set -e -f -u
|
|
|
|
|
2024-11-08 17:18:16 +03:00
|
|
|
if [ "${RACE:-1}" -eq '0' ]; then
|
2021-06-10 20:09:00 +03:00
|
|
|
race_flags='--race=0'
|
2020-12-30 18:26:25 +03:00
|
|
|
else
|
2021-06-10 20:09:00 +03:00
|
|
|
race_flags='--race=1'
|
2020-12-30 18:26:25 +03:00
|
|
|
fi
|
2021-05-19 20:31:20 +03:00
|
|
|
readonly race_flags
|
2020-12-30 18:26:25 +03:00
|
|
|
|
2024-11-08 17:18:16 +03:00
|
|
|
count_flags='--count=2'
|
|
|
|
cover_flags='--coverprofile=./cover.out'
|
2021-05-19 20:31:20 +03:00
|
|
|
go="${GO:-go}"
|
2021-12-22 16:34:51 +03:00
|
|
|
shuffle_flags='--shuffle=on'
|
2023-02-15 19:23:15 +03:00
|
|
|
timeout_flags="${TIMEOUT_FLAGS:---timeout=90s}"
|
2024-11-08 17:18:16 +03:00
|
|
|
readonly count_flags cover_flags go shuffle_flags timeout_flags
|
|
|
|
|
|
|
|
go_test() {
|
|
|
|
"$go" test \
|
|
|
|
"$count_flags" \
|
|
|
|
"$cover_flags" \
|
|
|
|
"$race_flags" \
|
|
|
|
"$shuffle_flags" \
|
|
|
|
"$timeout_flags" \
|
|
|
|
"$v_flags" \
|
|
|
|
"$x_flags" \
|
|
|
|
./...
|
|
|
|
}
|
|
|
|
|
|
|
|
test_reports_dir="${TEST_REPORTS_DIR:-}"
|
|
|
|
readonly test_reports_dir
|
|
|
|
|
|
|
|
if [ "$test_reports_dir" = '' ]; then
|
|
|
|
go_test
|
|
|
|
|
|
|
|
exit "$?"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "$test_reports_dir"
|
|
|
|
|
|
|
|
# NOTE: The pipe ignoring the exit code here is intentional, as go-junit-report
|
|
|
|
# will set the exit code to be saved.
|
|
|
|
go_test 2>&1 \
|
|
|
|
| tee "${test_reports_dir}/test-output.txt"
|
|
|
|
|
|
|
|
# Don't fail on errors in exporting, because TEST_REPORTS_DIR is generally only
|
|
|
|
# not empty in CI, and so the exit code must be preserved to exit with it later.
|
|
|
|
set +e
|
|
|
|
go-junit-report \
|
|
|
|
--in "${test_reports_dir}/test-output.txt" \
|
|
|
|
--set-exit-code \
|
|
|
|
>"${test_reports_dir}/test-report.xml"
|
|
|
|
printf '%s\n' "$?" \
|
|
|
|
>"${test_reports_dir}/test-exit-code.txt"
|