-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest
executable file
·83 lines (74 loc) · 2.19 KB
/
test
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
75
76
77
78
79
80
81
82
83
#! /bin/bash
#
# Run automated tests
#
# Usage:
# {{go}} {{cmd}} [--coverage|--edit|--list] [<glob>...]
#
# Options:
# --coverage Collect test coverage data using kcov (Linux only)
# --edit Open matching test files using `{{go}} edit`
# --list List test suite names without executing them
#
# Without <glob> arguments, runs (or edits, or lists) all tests. With one or
# more <glob> arguments, only runs tests matching 'tests/<glob>.bats'.
#
# If a <glob> doesn't match any test files, the command will return an error
# without running any tests. See `{{go}} help glob` for details.
#
# NOTE: If the <glob> produces errors, or generally doesn't do as you expect,
# you may need to include it in quotes so it isn't expanded by the shell
# _before_ executing the {{cmd}} command.
declare -r __GO_TEST_GLOB_ARGS=('--ignore' 'bats/*' 'tests' '.bats')
_test_tab_completion() {
local word_index="$1"
shift
if [[ "$word_index" -eq '0' ]]; then
compgen -W '--coverage --edit --list' -- "$1"
if [[ "${1:0:1}" == '-' ]]; then
return
fi
fi
@go 'glob' '--complete' "$((word_index + ${#__GO_TEST_GLOB_ARGS[@]}))" \
"${__GO_TEST_GLOB_ARGS[@]}" "$@"
}
_test_coverage() {
. 'scripts/lib/kcov'
run_kcov "tests/kcov" "tests/coverage" \
'go,go-core.bash,lib/,libexec/,scripts/' \
'/tmp,tests/bats/' \
'https://coveralls.io/github/mbland/go-script-bash' \
"$@"
}
_test() {
if [[ "$1" == '--complete' ]]; then
# Tab completions
shift
_test_tab_completion "$@"
return
fi
local bats_path='tests/bats/libexec/bats'
if [[ ! -f "$bats_path" ]]; then
git submodule update --init tests/bats
fi
if [[ "$1" == '--coverage' ]]; then
shift
_test_coverage "$@"
elif [[ "$1" == '--list' ]]; then
shift
@go 'glob' '--trim' "${__GO_TEST_GLOB_ARGS[@]}" "$@"
elif [[ "$1" == '--edit' ]]; then
shift
local tests=($(@go 'glob' "${__GO_TEST_GLOB_ARGS[@]}" "$@"))
@go 'edit' "${tests[@]}"
else
local tests=($(@go 'glob' "${__GO_TEST_GLOB_ARGS[@]}" "$@"))
"$BASH" "$bats_path" "${tests[@]}"
if [[ "$?" -eq 0 && "$TRAVIS_OS_NAME" == 'linux' ]]; then
_test_coverage "$@"
else
return "$?"
fi
fi
}
_test "$@"