File: test-unit

package info (click to toggle)
golang-github-vdemeester-shakers 0.0~git20160210.0.24d7f1d-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 192 kB
  • ctags: 158
  • sloc: sh: 159; makefile: 25
file content (52 lines) | stat: -rwxr-xr-x 1,299 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
set -e

RED=$'\033[31m'
GREEN=$'\033[32m'
TEXTRESET=$'\033[0m' # reset the foreground colour

# This helper function walks the current directory looking for directories
# holding certain files ($1 parameter), and prints their paths on standard
# output, one per line.
find_dirs() {
    find . -not \( \
         \( \
         -path './integration/*' \
         -o -path './vendor/*' \
         -o -path './.git/*' \
         \) \
         -prune \
         \) -name "$1" -print0 | xargs -0n1 dirname | sort -u
}

TESTFLAGS="-cover -coverprofile=cover.out ${TESTFLAGS}"

if [ -z "$TESTDIRS" ]; then
    TESTDIRS=$(find_dirs '*_test.go')
fi

TESTS_FAILED=()

for dir in $TESTDIRS; do
    echo '+ go test' $TESTFLAGS "${dir}"
    go test ${TESTFLAGS} ${dir}
    if [ $? != 0 ]; then
        TESTS_FAILED+=("$dir")
        echo
        echo "${RED}Tests failed: $dir${TEXTRESET}"
        sleep 1 # give it a second, so observers watching can take note
    fi
done
echo

# if some tests fail, we want the bundlescript to fail, but we want to
# try running ALL the tests first, hence TESTS_FAILED
if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then
    echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}"
    echo
    false
else
    echo "${GREEN}Test success${TEXTRESET}"
    echo
    true
fi