-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.sh
executable file
·73 lines (54 loc) · 1.49 KB
/
run_tests.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
#!/bin/bash
# this script runs all tests/test*.sh files using assert.sh (https://github.com/lehmannro/assert.sh)
# and the helper functions bellow
function log_random() {
now=$(gdate +"%Y-%M-%dT%T.%N" 2>/dev/null || date +"%Y-%M-%dT%T.%N")
uuid=$( ( uuidgen 2>/dev/null || python -c 'import uuid; print uuid.uuid1()' ) 2>/dev/null )
echo $uuid > .last_uuid
echo $now > .last_timestamp
echo "$now And this is a UUID just to ensure this line is unique: $uuid"
}
function last_uuid() {
cat .last_uuid
}
function last_timestamp() {
cat .last_timestamp
}
function count_bytes() {
echo $(cat $1 | wc -c | xargs)
}
function count_lines() {
echo $(cat $1 | wc -l | xargs)
}
persistent=$([ "$1" == "-p" ] && echo 1 || echo 0)
set -e
base=$(cd $(dirname $0) && pwd -P)
. $base/tests/assert.sh -v -i
workdir=$(mktemp -d -t forwarder-tests-XXXXXX)
function _cleanup() {
local status=$?
if [ $persistent == 1 ]; then
echo "Leaving working dir intact: $workdir"
exit $tests_suite_status
fi
rm -rf $workdir
if ! [ $tests_suite_status == 0 ]; then
echo "Tests failed, execute this script with -p option to leave working directory intact"
fi
[ $status = "0" ] && exit $tests_suite_status
exit $status
}
trap '_cleanup' EXIT
export PATH=$base:$PATH
function run_tests() {
current_dir=$(pwd)
for test in $(find tests -name 'test*.sh' | sort); do
mkdir -p $workdir/$test
cd $workdir/$test
echo Running tests/$test ...
. $base/$test
assert_end $test
done
cd $current_dir
}
run_tests