@@ -148,10 +148,22 @@ run_test_suite() {
148
148
run_test () {
149
149
set -e
150
150
local TEST=$1
151
- echo -n " Running $TEST ... " | format " $BLUE "
152
- $TEST && format " $GREEN " " SUCCESS "
151
+ notify_test_starting " $TEST "
152
+ $TEST && notify_test_succeeded " $TEST " >& $LOG
153
153
}
154
154
155
+ usage () {
156
+ echo " $1 " >&2
157
+ echo " $0 [-f <output format<] [-p <pattern1>] [-p <pattern2>]... <test_file1> <test_file2>..." >&2
158
+ echo >&2
159
+ echo " Runs tests in test files that match <pattern>s" >&2
160
+ echo " <output format> is optionnal only supported value is tap" >&2
161
+ echo " See https://github.com/pgrange/bash_unit" >&2
162
+ exit 1
163
+ }
164
+
165
+ # Formating
166
+
155
167
print_stack () {
156
168
local i=1
157
169
while ! [ -z ${BASH_SOURCE[$i]} ]
@@ -174,24 +186,50 @@ format() {
174
186
if [ -t 1 ] ; then echo -en " $NOCOLOR " ; fi
175
187
}
176
188
177
- usage () {
178
- echo " $1 " >&2
179
- echo " $0 [-p <pattern1>] [-p <pattern2>]... <test_file1> <test_file2>..." >&2
180
- echo >&2
181
- echo " Runs tests in test files that match patterns" >&2
182
- echo " See https://github.com/pgrange/bash_unit" >&2
183
- exit 1
189
+ notify_suite_starting () {
190
+ test_file=" $1 "
191
+ echo " Running tests in $test_file " >& $LOG
184
192
}
185
193
194
+ notify_test_starting () {
195
+ local test=" $1 "
196
+ echo -n " Running $test ... " | format " $BLUE " >& $LOG
197
+ }
198
+
199
+ notify_test_succeeded () {
200
+ local test=" $1 "
201
+ format " $GREEN " " SUCCESS" >& $LOG
202
+ }
203
+
204
+ tap_notify_suite_starting () {
205
+ test_file=" $1 "
206
+ echo " # Running tests in $test_file " >& $LOG
207
+ }
208
+
209
+ tap_notify_test_starting () {
210
+ echo -n
211
+ }
212
+
213
+ tap_notify_test_succeeded () {
214
+ local test=" $1 "
215
+ echo -n " ok" | format " $GREEN " >& $LOG
216
+ echo -n " " >& $LOG
217
+ echo " $test " >& $LOG
218
+ }
219
+
220
+ output_format=default
186
221
test_pattern=" "
187
222
separator=" "
188
- while getopts " p:" option
223
+ while getopts " p:f: " option
189
224
do
190
225
case " $option " in
191
226
p)
192
227
test_pattern=" ${test_pattern}${separator}${OPTARG} "
193
228
separator=" |"
194
229
;;
230
+ f)
231
+ output_format=" ${OPTARG} "
232
+ ;;
195
233
? |:)
196
234
usage
197
235
;;
206
244
test -r $test_file || usage " can not read file: $test_file "
207
245
done
208
246
247
+ # set output format
248
+ case " $output_format " in
249
+ default)
250
+ ;;
251
+ tap)
252
+ notify_suite_starting () { tap_notify_suite_starting " $@ " ; }
253
+ notify_test_starting () { tap_notify_test_starting " $@ " ; }
254
+ notify_test_succeeded () { tap_notify_test_succeeded " $@ " ; }
255
+ ;;
256
+ * )
257
+ usage " unsupproted output format: $output_format "
258
+ ;;
259
+ esac
260
+
209
261
# run tests received as parameters
210
262
failure=0
211
263
for test_file in " $@ "
212
264
do
213
- echo " Running tests in $test_file "
265
+ notify_suite_starting " $test_file "
214
266
(
215
267
source " $test_file "
216
268
cd $( dirname " $test_file " )
0 commit comments