forked from tstack/lnav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TESTS_ENVIRONMENT.in
161 lines (135 loc) · 3.32 KB
/
TESTS_ENVIRONMENT.in
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
158
159
160
161
#! /bin/bash
top_srcdir="@abssrcdir@"
export top_srcdir
srcdir="@abssrcdir@/test"
export srcdir
# The top build directory, derived from the path to this script.
top_builddir=`dirname $0`
export top_builddir
test_dir="@abssrcdir@/test"
export test_dir
# Let the tests know whether bzip is supported or not.
BZIP2_SUPPORT="@BZIP2_SUPPORT@"
export BZIP2_SUPPORT
BZIP2_CMD="@BZIP2_CMD@"
export BZIP2_CMD
HOME="${top_builddir}/test"
export HOME
# The full path of the test case
test_file=$1
# The base name of the test case
test_file_base=`basename $1`
# The current test number for shell based tests.
test_num=0
lnav_test="${top_builddir}/src/lnav-test"
export lnav_test
lnav="${top_builddir}/src/lnav"
export lnav
LNAV_LOG_PATH="${top_builddir}/test/test.log"
export LNAV_LOG_PATH
SFTP_TEST_URL="@SFTP_TEST_URL@"
export SFTP_TEST_URL
HAVE_SQLITE3_VALUE_SUBTYPE="@HAVE_SQLITE3_VALUE_SUBTYPE@"
export HAVE_SQLITE3_VALUE_SUBTYPE
## BEGIN Functions
LAST_TEST=""
#
# Run a test case and capture its standard out and standard err.
#
# Usage: run_test <utility> [<argument> ...]
#
# Example:
#
# To run rktimes and capture all of its stdio output:
#
# run_test rktimes -V
#
run_test() {
LAST_TEST="test: $@"
"$@" > ${test_file_base}_${test_num}.tmp 2> ${test_file_base}_${test_num}.err
}
#
# Check the output generated by a run_test() call.
#
# Usage: check_output <fail message> {Expected output on stdin}
#
# Example:
#
# To check the output of 'rktimes -V' and print out 'Unable to get version?'
# if the output doesn't match:
#
# run_test rktimes -V
# check_output "Unable to get version?" <<EOF
# 0.5
# EOF
#
check_output() {
diff -w -u - ${test_file_base}_${test_num}.tmp > ${test_file_base}_${test_num}.diff
if test $? -ne 0; then
echo $LAST_TEST
echo $1
cat ${test_file_base}_${test_num}.diff
exit 1
fi
test_num=`expr ${test_num} \+ 1`
}
check_output_ws() {
diff -u - ${test_file_base}_${test_num}.tmp > ${test_file_base}_${test_num}.diff
if test $? -ne 0; then
echo $LAST_TEST
echo $1
cat ${test_file_base}_${test_num}.diff
exit 1
fi
test_num=`expr ${test_num} \+ 1`
}
test_err_filename() {
echo ${test_file_base}_${test_num}.err
}
check_error_output() {
diff -w -u - ${test_file_base}_${test_num}.err \
> ${test_file_base}_${test_num}.err.diff
if test $? -ne 0; then
echo $LAST_TEST
echo $1
cat ${test_file_base}_${test_num}.err.diff
exit 1
fi
}
#
# Grep for a string in the output generated by a run_test() call.
#
# Usage: grep_output_for <string> <fail maessage>
#
# Example:
#
# To check the output of 'cbhey -l' for 'IDL:Foobar:1.0' and print out
# 'Unable to list supported interfaces?' if it is not found:
#
# run_test cbhey -l
# grep_output_for "IDL:Foobar:1.0" "Unable to list supported interface?"
#
grep_output_for() {
if grep -q $1 ${test_file_base}_${test_num}.tmp > /dev/null 2>&1; then
:
else
echo "${test_file_base}_${test_num}.tmp: $2"
exit 1
fi
test_num=`expr ${test_num} \+ 1`
}
on_error_fail_with() {
if test $? -ne 0; then
echo $1 > /dev/stderr
exit 1
fi
}
## END Functions
# Finally, run the test...
if test -x $1 && test `basename $1 .sh` == `basename $1`; then
exec $*
else
# Shell script
shift
. ${test_file}
fi