-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun_tests
executable file
·145 lines (124 loc) · 2.7 KB
/
run_tests
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
#!/usr/bin/env bash
# This file is a symlink from 'tmux-test' plugin.
# You probably don't want to edit it.
# Run this script when running a test suite.
# For each virtual machine where tests run, this script performs the following:
# - starts VM
# - starts the test suite witin a VM
# - stops the VM after the test suite is done
export BOXES=""
export FILES=""
export KEEP_RUNNING=""
# global variable for script exit value
export EXIT_VALUE=0
display_help() {
echo "Usage:"
echo " ./run_tests # runs tests on default VM ubuntu"
echo " ./run_tests -m ubuntu # runs tests on ubuntu VM"
echo " ./run_tests -m ubuntu -m centos # runs tests on ubuntu and cents VMs"
echo " ./run_tests tests/some_test # run a single test file"
echo " ./run_tests --keep-running # don't stop vagrant after the tests are done"
}
parse_arguments() {
while :
do
case "$1" in
-m | --machine)
local machine="$2"
if [ "$machine" == "ubuntu" ] || [ "$machine" == "centos" ]; then
BOXES="$BOXES $machine"
else
echo "Unknown machine '$machine'"
echo ""
display_help
exit 1
fi
shift 2
;;
-k | --keep-running)
KEEP_RUNNING="true"
shift
;;
-h | --help)
display_help
exit 0
;;
--) # End of all options
shift
FILES="$*"
break
;;
-* )
echo "Error: Unknown option: $1" >&2
echo ""
display_help
exit 1
;;
*) # No more options
FILES="$*"
break
;;
esac
done
# default options
if [ -z "$BOXES" ]; then
BOXES="ubuntu"
fi
}
register_failing_tests() {
EXIT_VALUE=1
}
run_vagrant() {
local box="$1"
VAGRANT_CWD=lib/tmux-test/ vagrant up "$box"
}
# Halt vagrant after tests are done running, unless `--keep-running`
# option is given
stop_vagrant() {
local box="$1"
if [ -z "$KEEP_RUNNING" ]; then
VAGRANT_CWD=lib/tmux-test/ vagrant halt "$box"
else
echo
echo "--keep-running option set, Vagrant not halted"
fi
}
run_tests() {
local box="$1"
local test_file="/vagrant/tests/run_tests_in_isolation"
echo "Running test suite on $box from: $test_file"
echo
VAGRANT_CWD=lib/tmux-test/ vagrant ssh "$box" -c "cd /vagrant; $test_file $FILES"
}
exit_message() {
local exit_val="$1"
echo
if [ "$exit_val" == 0 ]; then
echo "Success, tests pass!"
else
echo "Tests failed!" 1>&2
fi
}
run_tests_on_vm() {
local vm="$1"
run_vagrant "$vm"
run_tests "$vm"
local tests_exit_value="$?"
stop_vagrant "$vm"
if [ "$tests_exit_value" -gt 0 ]; then
register_failing_tests
fi
}
run_tests_on_virtual_machines() {
local box
for box in $BOXES; do
run_tests_on_vm "$box"
done
}
main() {
parse_arguments "$@"
run_tests_on_virtual_machines
exit_message "$EXIT_VALUE"
exit "$EXIT_VALUE"
}
main "$@"