@@ -42,7 +42,7 @@ fail() {
42
42
[[ ! -z $stdout ]] && [ -s $stdout ] && cat $stdout | notify_stdout
43
43
[[ ! -z $stderr ]] && [ -s $stderr ] && cat $stderr | notify_stderr
44
44
45
- print_stack | grep -v ^ $BASH_SOURCE | notify_stack
45
+ stacktrace | notify_stack
46
46
exit 1
47
47
}
48
48
@@ -129,6 +129,15 @@ fake() {
129
129
export -f $command
130
130
}
131
131
132
+ stacktrace () {
133
+ local i=1
134
+ while ! [ -z ${BASH_SOURCE[$i]} ]
135
+ do
136
+ echo ${BASH_SOURCE[$i]} :${BASH_LINENO[$((i-1))]} :${FUNCNAME[$i]} \(\)
137
+ i=$(( $i + 1 ))
138
+ done | grep -v ^$BASH_SOURCE
139
+ }
140
+
132
141
run_test_suite () {
133
142
local failure=0
134
143
for test in $( set | grep -E ' ^test.* ()' | grep -E " $test_pattern " | sed -e ' s: .*::' )
@@ -163,16 +172,7 @@ usage() {
163
172
164
173
# Formating
165
174
166
- print_stack () {
167
- local i=1
168
- while ! [ -z ${BASH_SOURCE[$i]} ]
169
- do
170
- echo ${BASH_SOURCE[$i]} :${BASH_LINENO[$((i-1))]} :${FUNCNAME[$i]} \(\)
171
- i=$(( $i + 1 ))
172
- done
173
- }
174
-
175
- format () {
175
+ color () {
176
176
local color=$1
177
177
shift
178
178
if [ -t 1 ] ; then echo -en " $color " ; fi
@@ -185,76 +185,68 @@ format() {
185
185
if [ -t 1 ] ; then echo -en " $NOCOLOR " ; fi
186
186
}
187
187
188
- notify_suite_starting () {
189
- test_file=" $1 "
190
- echo " Running tests in $test_file " >& $LOG
191
- }
192
-
193
- notify_test_starting () {
194
- local test=" $1 "
195
- echo -n " Running $test ... " | format " $BLUE " >& $LOG
196
- }
197
-
198
- notify_test_succeeded () {
199
- format " $GREEN " " SUCCESS" >& $LOG
200
- }
201
-
202
- notify_test_failed () {
203
- local message=" $2 "
204
- format " $RED " " FAILURE" >& $LOG
205
- [[ -z $message ]] || printf -- " $message \n" >& $LOG
206
- }
207
-
208
- notify_stdout () {
209
- sed ' s:^:out> :' | format $GREEN >& $OUT
210
- }
211
-
212
- notify_stderr () {
213
- sed ' s:^:err> :' | format $RED >& $ERR
214
- }
215
-
216
- notify_stack () {
217
- format " $YELLOW " >& $STACK
218
- }
219
-
220
- tap_notify_suite_starting () {
221
- test_file=" $1 "
222
- echo " # Running tests in $test_file " >& $LOG
223
- }
224
-
225
- tap_notify_test_starting () {
226
- echo -n
227
- }
228
-
229
- tap_notify_test_succeeded () {
230
- local test=" $1 "
231
- echo -n " ok" | format " $GREEN " >& $LOG
232
- echo -n ' - ' >& $LOG
233
- echo " $test " | format " $BLUE " >& $LOG
234
- }
235
-
236
- tap_notify_test_failed () {
237
- local test=" $1 "
238
- local message=" $2 "
239
- echo -n " not ok" | format " $RED " >& $LOG
240
- echo -n " - " >& $LOG
241
- echo " $test " >& $LOG
242
- [[ -z $message ]] || printf -- " $message \n" | sed -u -e ' s/^/# /' >& $LOG
243
- }
244
-
245
- tap_notify_stdout () {
246
- sed ' s:^:# out> :' | format $GREEN >& $OUT
247
- }
248
-
249
- tap_notify_stderr () {
250
- sed ' s:^:# err> :' | format $RED >& $ERR
188
+ text_format () {
189
+ notify_suite_starting () {
190
+ test_file=" $1 "
191
+ echo " Running tests in $test_file " >& $LOG
192
+ }
193
+ notify_test_starting () {
194
+ local test=" $1 "
195
+ echo -n " Running $test ... " | color " $BLUE " >& $LOG
196
+ }
197
+ notify_test_succeeded () {
198
+ color " $GREEN " " SUCCESS" >& $LOG
199
+ }
200
+ notify_test_failed () {
201
+ local message=" $2 "
202
+ color " $RED " " FAILURE" >& $LOG
203
+ [[ -z $message ]] || printf -- " $message \n" >& $LOG
204
+ }
205
+ notify_stdout () {
206
+ sed ' s:^:out> :' | color $GREEN >& $OUT
207
+ }
208
+ notify_stderr () {
209
+ sed ' s:^:err> :' | color $RED >& $ERR
210
+ }
211
+ notify_stack () {
212
+ color " $YELLOW " >& $STACK
213
+ }
251
214
}
252
215
253
- tap_notify_stack () {
254
- sed ' s:^:# :' | format " $YELLOW " >& $STACK
216
+ tap_format () {
217
+ notify_suite_starting () {
218
+ test_file=" $1 "
219
+ echo " # Running tests in $test_file " >& $LOG
220
+ }
221
+ notify_test_starting () {
222
+ echo -n
223
+ }
224
+ notify_test_succeeded () {
225
+ local test=" $1 "
226
+ echo -n " ok" | color " $GREEN " >& $LOG
227
+ echo -n ' - ' >& $LOG
228
+ echo " $test " | color " $BLUE " >& $LOG
229
+ }
230
+ notify_test_failed () {
231
+ local test=" $1 "
232
+ local message=" $2 "
233
+ echo -n " not ok" | color " $RED " >& $LOG
234
+ echo -n " - " >& $LOG
235
+ echo " $test " >& $LOG
236
+ [[ -z $message ]] || printf -- " $message \n" | sed -u -e ' s/^/# /' >& $LOG
237
+ }
238
+ notify_stdout () {
239
+ sed ' s:^:# out> :' | color $GREEN >& $OUT
240
+ }
241
+ notify_stderr () {
242
+ sed ' s:^:# err> :' | color $RED >& $ERR
243
+ }
244
+ notify_stack () {
245
+ sed ' s:^:# :' | color " $YELLOW " >& $STACK
246
+ }
255
247
}
256
248
257
- output_format=default
249
+ output_format=text
258
250
test_pattern=" "
259
251
separator=" "
260
252
while getopts " p:f:" option
274
266
done
275
267
shift $(( OPTIND- 1 ))
276
268
277
- # check test files exist and is readable
278
269
for test_file in " $@ "
279
270
do
280
271
test -e $test_file || usage " file does not exist: $test_file "
281
272
test -r $test_file || usage " can not read file: $test_file "
282
273
done
283
274
284
- # set output format
285
275
case " $output_format " in
286
- default)
276
+ text)
277
+ text_format
287
278
;;
288
279
tap)
289
- notify_suite_starting () { tap_notify_suite_starting " $@ " ; }
290
- notify_test_starting () { tap_notify_test_starting " $@ " ; }
291
- notify_test_succeeded () { tap_notify_test_succeeded " $@ " ; }
292
- notify_test_failed () { tap_notify_test_failed " $@ " ; }
293
- notify_stdout () { tap_notify_stdout " $@ " ; }
294
- notify_stderr () { tap_notify_stderr " $@ " ; }
295
- notify_stack () { tap_notify_stack " $@ " ; }
280
+ tap_format
296
281
;;
297
282
* )
298
283
usage " unsupproted output format: $output_format "
0 commit comments