forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.sh
executable file
·74 lines (65 loc) · 2.07 KB
/
validate.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/bash
set -e
RACE=0
AUTOFMT=true
COVERAGE=false
VET=true
while true; do
case "$1" in
--nofmt ) AUTOFMT=false; shift ;;
--race ) RACE=$2; shift; shift; ;;
--cov ) COVERAGE=true; shift ;;
--novet ) VET=false; shift ;;
* ) break ;;
esac
done
die() { echo -e "$@" 1>&2 ; exit 1; }
# Build a list of all the top-level directories in the project.
for DIRECTORY in */ ; do
GOGLOB="$GOGLOB ${DIRECTORY%/}"
done
GOGLOB="${GOGLOB/ docs/}"
GOGLOB="${GOGLOB/ vendor/}"
# Check that there are no formatting issues
GOFMT_LINES=`gofmt -s -l $GOGLOB | wc -l | xargs`
if $AUTOFMT; then
# if there are files with formatting issues, they will be automatically corrected using the gofmt -w <file> command
if [[ $GOFMT_LINES -ne 0 ]]; then
FMT_FILES=`gofmt -s -l $GOGLOB | xargs`
for FILE in $FMT_FILES; do
echo "Running: gofmt -s -w $FILE"
`gofmt -s -w $FILE`
done
fi
else
test $GOFMT_LINES -eq 0 || die "gofmt needs to be run, ${GOFMT_LINES} files have issues. Below is a list of files to review:\n`gofmt -s -l $GOGLOB`"
fi
# Run the actual tests. Make sure there's enough coverage too, if the flags call for it.
if $COVERAGE; then
./scripts/check_coverage.sh
else
go test -timeout 120s $(go list ./... | grep -v /vendor/)
fi
# Then run the race condition tests. These only run on tests named TestRace.* for two reasons.
#
# 1. To speed things up (for large -count values)
# 2. Because some tests open up files on the filesystem, and some operating systems limit the number of open files for a single proecss.
if [ "$RACE" -ne "0" ]; then
go test -race $(go list ./... | grep -v /vendor/) -run ^TestRace.*$ -count $RACE
fi
if $VET; then
# Fix for the go 1.10 vet bug (https://github.com/w0rp/ale/issues/1358)
COMMAND="go tool vet -source *.go"
echo "Running: $COMMAND"
`$COMMAND`
for SOURCE in $GOGLOB ; do
# default call for wildcards and directories
COMMAND="go tool vet -source $SOURCE"
if [ -f $SOURCE ]; then
# file
COMMAND="go vet -source $SOURCE"
fi
echo "Running: $COMMAND"
`$COMMAND`
done
fi