-
Notifications
You must be signed in to change notification settings - Fork 5
/
run_tests
executable file
·119 lines (100 loc) · 2.21 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
#!/usr/bin/env bash
# This file is a copied from 'tmux-test' plugin.
# https://github.com/tmux-plugins/tmux-test/blob/master/run_tests
# 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 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
-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
}
register_failing_tests() {
EXIT_VALUE=1
}
run_vagrant() {
local box="$1"
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 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 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
}
main() {
parse_arguments "$@"
run_tests_on_vm "ubuntu_fuzzback"
exit_message "$EXIT_VALUE"
exit "$EXIT_VALUE"
}
main "$@"