/
runtest.sh
executable file
·129 lines (108 loc) · 2.61 KB
/
runtest.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
#!/bin/sh
# Created by Christian Goetze - http://blog.fortified-bikesheds.com/ - and released under
# the terms of the CC0 1.0 Universal legal code:
#
# http://creativecommons.org/publicdomain/zero/1.0/legalcode
# Usage:
# ./runtest.sh <path-to-test-dir>
# The idea of this script is to give developers a quick and easy way to
# run individual tests or test suites. Note that individual tests can be
# run directly from within their test.sh, which has a line to check for
# "framework_loaded" and re-exec this script.
here="$(cd "$(dirname "$0")" && pwd)"
pwd="$(pwd | sed "s,^$here/,,")"
cd "$here"
export framework_loaded=true
export succeeded=true
export allow_sections=true
export status_unset=true
# These are TeamCity service messages... not sure whether Jenkins supports
# something similar. It produces structured build logs in TeamCity.
echo_service_message()
{
echo "##teamcity[$@]"
}
begin_section()
{
$allow_sections && echo_service_message blockOpened name="'$1'"
}
end_section()
{
$allow_sections && echo_service_message blockClosed name="'$1'"
}
begin_suite()
{
$allow_sections && echo_service_message testSuiteStarted name="'$1'"
}
end_suite()
{
$allow_sections && echo_service_message testSuiteFinished name="'$1'"
allow_sections=true
}
begin_test()
{
echo_service_message testStarted name="'$1'" captureStandardOutput="'${2:-true}'"
allow_sections=false
}
end_test()
{
echo_service_message testFinished name="'$1'"
allow_sections=true
}
fail_test()
{
echo_service_message testFailed name="'$1'" message="'$2'" details="'$3'"
succeeded=false
}
ignore_test()
{
echo_service_message testIgnored name="'$1'" message="'$2'"
}
sorted_normalized_diff()
{
sed -e 's,tests/[0-9][0-9]-[^/]*/[0-9][0-9]-[^/]*/,testdata/,g'\
-e "s,`pwd`,%here%,g"\
"$2" | sort > "$2".normalized
diff -w "$1" "$2".normalized
}
normalized_diff()
{
sed -e 's,tests/[0-9][0-9]-[^/]*/[0-9][0-9]-[^/]*/,testdata/,g'\
-e "s,`pwd`,%here%,g"\
"$2" > "$2".normalized
diff -w "$1" "$2".normalized
}
run_tests()
{
cd "$here"
while [ "$1" ]
do
case "$1" in
*/*/test.sh) tests="'$1'";;
*/*/) tests="'$1'test.sh";;
*/) tests="'$1'*/test.sh";;
*/*) tests="'$1'/test.sh";;
*) tests="'$1'/*/test.sh";;
esac
for test in `eval "ls $tests 2>/dev/null"`
do
test_path=$(dirname "$test")
. "$test" || succeeded=false
done
shift
done
}
if [ "$1" ]
then
run_tests "$@"
elif [ -x "$pwd/test.sh" ]
then
test_path="$pwd"
. "$pwd/test.sh" || succeeded=false
else
run_tests tests
fi
$succeeded\
&& echo "Tests passed."\
|| echo "Some tests failed."
$succeeded