-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·157 lines (129 loc) · 3.06 KB
/
test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/sh -e
# Easily run Ansible tests.
process_args() {
if [ $# -eq 0 ]; then help=1; fi
if [ "${ANSIBLE_HOME}" = "" ]; then setup=1; fi
quiet=""
while [ "$1" ]; do
case "$1" in
"-s" | "--setup")
setup=1
;;
"-d" | "--dir")
shift
dir="$1"
;;
"-T" | "--tests")
tests=1
;;
"-i" | "--integration")
shift
target="$1"
;;
"-t" | "--tag")
shift
tags="${tags}${tags:+,}$1"
;;
"-q" | "--quiet")
if [ ${quiet} ]; then
silent=1
fi
quiet=1
;;
"-h" | "--help")
help=1
;;
*)
echo "Unknown argument: $1"
exit 1
esac
shift
done
}
detect_make() {
if gmake --version > /dev/null 2>&1; then
make="gmake"
else
make="make"
fi
}
show_help() {
if [ ! ${help} ]; then return; fi
cat <<- 'EOF'
Usage: test.sh [option ...]
Options:
-s, --setup Run "env-setup" even if "$ANSIBLE_HOME" is set.
-d, --dir Use dir as the Ansible home directory.
Otherwise try "$PWD" and "$PWD/ansible".
-T, --tests Run "make tests" from the Ansible directory.
-i, --integration target Run the specified Ansible integration test target.
-t, --tag tag Comma separated list of integration test tags.
If omitted, all tags for the test target will run.
May be specified multiple times to add more tags.
-q, --quiet Do not include additional log messages.
Specify more than once to silence "env-setup".
-h, --help Show this help message and exit.
EOF
exit 0
}
run_setup() {
if [ ! ${setup} ]; then return; fi
for src in "${dir}" "${PWD}" "${PWD}/ansible" "${ANSIBLE_HOME}"; do
if [ -f "${src}/hacking/env-setup" ]; then
log "Setting up Ansible environment..."
cd "${src}"
if [ ${silent} ]; then
. "hacking/env-setup" > /dev/null 2>&1
else
. "hacking/env-setup"
fi
setup=""
break
fi
done
if [ ${setup} ]; then
cat <<- 'EOF'
Unable to find a valid Ansible home directory.
Do you need to use the --dir option? See --help for details.
EOF
exit 1
fi
}
run_tests() {
if [ ! ${tests} ]; then return; fi
log "Running Ansible tests..."
(
cd "${ANSIBLE_HOME}"
${make} tests
)
log "Completed Ansible tests."
}
run_integration() {
if [ "${target}" = "" ]; then return; fi
log "Running Ansible integration test target '${target}'..."
if [ "${tags}" = "" ]; then
log "No tags were specified."
else
log "Tags: ${tags}"
test_flags="--tags ${tags}"
fi
(
cd "${ANSIBLE_HOME}/test/integration"
TEST_FLAGS="${test_flags}" ${make} "${target}"
)
log "Completed Ansible integration tests."
}
log() {
if [ ${quiet} ]; then return; fi
echo "$@"
}
main() {
process_args "$@"
detect_make
show_help
run_setup
run_tests
run_integration
}
main "$@"
exit 0