Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 292bec9

Browse files
committed
Change flunk to fail
1 parent 643d8d8 commit 292bec9

File tree

5 files changed

+43
-43
lines changed

5 files changed

+43
-43
lines changed

Diff for: README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -272,24 +272,24 @@ information on failure to help debugging. They return `1` on failure and
272272
Assertions about exit code and output operate on the results of the most
273273
recent invocation of `run`.
274274

275-
#### `flunk`
275+
#### `fail`
276276

277277
Display an error message and fail. This function provides a convenient
278278
way to report failure in arbitrary situations. You can use it to
279279
implement your own helpers when the ones available do not meet your
280280
needs. Other functions use it internally as well.
281281

282282
```bash
283-
@test 'flunk()' {
284-
flunk 'this test always fails'
283+
@test 'fail()' {
284+
fail 'this test always fails'
285285
}
286286
```
287287

288288
The message can also be specified on the standard input.
289289

290290
```bash
291-
@test 'flunk() with pipe' {
292-
echo 'this test always fails' | flunk
291+
@test 'fail() with pipe' {
292+
echo 'this test always fails' | fail
293293
}
294294
```
295295

Diff for: lib/bats/batslib.bash

+30-30
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ source "${BATS_LIB}/batslib/output.bash"
3434
# STDIN - [opt = $@] message to display
3535
# Outputs:
3636
# STDERR - error message
37-
flunk() {
37+
fail() {
3838
(( $# == 0 )) && batslib_err || batslib_err "$@"
3939
return 1
4040
}
@@ -68,7 +68,7 @@ assert() {
6868
batslib_print_kv_single "$width" "${single[@]}"
6969
batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}"
7070
} | batslib_decorate 'assertion failed' \
71-
| flunk
71+
| fail
7272
fi
7373
}
7474

@@ -92,7 +92,7 @@ assert_equal() {
9292
'expected' "$1" \
9393
'actual' "$2" \
9494
| batslib_decorate 'values do not equal' \
95-
| flunk
95+
| fail
9696
fi
9797
}
9898

@@ -159,14 +159,14 @@ assert_output() {
159159
if (( is_match_line )) && (( is_match_contained )); then
160160
echo "\`-l' and \`-l <index>' are mutually exclusive" \
161161
| batslib_decorate 'ERROR: assert_output' \
162-
| flunk
162+
| fail
163163
return $?
164164
fi
165165

166166
if (( is_mode_partial )) && (( is_mode_regex )); then
167167
echo "\`-p' and \`-r' are mutually exclusive" \
168168
| batslib_decorate 'ERROR: assert_output' \
169-
| flunk
169+
| fail
170170
return $?
171171
fi
172172

@@ -176,7 +176,7 @@ assert_output() {
176176
if (( is_mode_regex == 1 )) && [[ '' =~ $expected ]] || (( $? == 2 )); then
177177
echo "Invalid extended regular expression: \`$expected'" \
178178
| batslib_decorate 'ERROR: assert_output' \
179-
| flunk
179+
| fail
180180
return $?
181181
fi
182182

@@ -199,7 +199,7 @@ assert_output() {
199199
batslib_print_kv_single "$width" "${single[@]}"
200200
batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}"
201201
} | batslib_decorate 'no output line matches regular expression' \
202-
| flunk
202+
| fail
203203
elif (( is_mode_partial )); then
204204
local -i idx
205205
for (( idx = 0; idx < ${#lines[@]}; ++idx )); do
@@ -216,7 +216,7 @@ assert_output() {
216216
batslib_print_kv_single "$width" "${single[@]}"
217217
batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}"
218218
} | batslib_decorate 'no output line contains substring' \
219-
| flunk
219+
| fail
220220
else
221221
local -i idx
222222
for (( idx = 0; idx < ${#lines[@]}; ++idx )); do
@@ -233,7 +233,7 @@ assert_output() {
233233
batslib_print_kv_single "$width" "${single[@]}"
234234
batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}"
235235
} | batslib_decorate 'output does not contain line' \
236-
| flunk
236+
| fail
237237
fi
238238
elif (( is_match_line )); then
239239
# Specific line.
@@ -244,7 +244,7 @@ assert_output() {
244244
'regex' "$expected" \
245245
'line' "${lines[$idx]}" \
246246
| batslib_decorate 'regular expression does not match line' \
247-
| flunk
247+
| fail
248248
fi
249249
elif (( is_mode_partial )); then
250250
if [[ ${lines[$idx]} != *"$expected"* ]]; then
@@ -253,7 +253,7 @@ assert_output() {
253253
'substring' "$expected" \
254254
'line' "${lines[$idx]}" \
255255
| batslib_decorate 'line does not contain substring' \
256-
| flunk
256+
| fail
257257
fi
258258
else
259259
if [[ ${lines[$idx]} != "$expected" ]]; then
@@ -262,7 +262,7 @@ assert_output() {
262262
'expected' "$expected" \
263263
'actual' "${lines[$idx]}" \
264264
| batslib_decorate 'line differs' \
265-
| flunk
265+
| fail
266266
fi
267267
fi
268268
else
@@ -273,23 +273,23 @@ assert_output() {
273273
'regex' "$expected" \
274274
'output' "$output" \
275275
| batslib_decorate 'regular expression does not match output' \
276-
| flunk
276+
| fail
277277
fi
278278
elif (( is_mode_partial )); then
279279
if [[ $output != *"$expected"* ]]; then
280280
batslib_print_kv_single_or_multi 9 \
281281
'substring' "$expected" \
282282
'output' "$output" \
283283
| batslib_decorate 'output does not contain substring' \
284-
| flunk
284+
| fail
285285
fi
286286
else
287287
if [[ $output != "$expected" ]]; then
288288
batslib_print_kv_single_or_multi 8 \
289289
'expected' "$expected" \
290290
'actual' "$output" \
291291
| batslib_decorate 'output differs' \
292-
| flunk
292+
| fail
293293
fi
294294
fi
295295
fi
@@ -360,14 +360,14 @@ refute_output() {
360360
if (( is_match_line )) && (( is_match_contained )); then
361361
echo "\`-l' and \`-l <index>' are mutually exclusive" \
362362
| batslib_decorate 'ERROR: refute_output' \
363-
| flunk
363+
| fail
364364
return $?
365365
fi
366366

367367
if (( is_mode_partial )) && (( is_mode_regex )); then
368368
echo "\`-p' and \`-r' are mutually exclusive" \
369369
| batslib_decorate 'ERROR: refute_output' \
370-
| flunk
370+
| fail
371371
return $?
372372
fi
373373

@@ -377,7 +377,7 @@ refute_output() {
377377
if (( is_mode_regex == 1 )) && [[ '' =~ $unexpected ]] || (( $? == 2 )); then
378378
echo "Invalid extended regular expression: \`$unexpected'" \
379379
| batslib_decorate 'ERROR: refute_output' \
380-
| flunk
380+
| fail
381381
return $?
382382
fi
383383

@@ -407,7 +407,7 @@ refute_output() {
407407
batslib_print_kv_multi "${may_be_multi[@]}"
408408
fi
409409
} | batslib_decorate 'no line should match the regular expression' \
410-
| flunk
410+
| fail
411411
return $?
412412
fi
413413
done
@@ -434,7 +434,7 @@ refute_output() {
434434
batslib_print_kv_multi "${may_be_multi[@]}"
435435
fi
436436
} | batslib_decorate 'no line should contain substring' \
437-
| flunk
437+
| fail
438438
return $?
439439
fi
440440
done
@@ -461,7 +461,7 @@ refute_output() {
461461
batslib_print_kv_multi "${may_be_multi[@]}"
462462
fi
463463
} | batslib_decorate 'line should not be in output' \
464-
| flunk
464+
| fail
465465
return $?
466466
fi
467467
done
@@ -475,7 +475,7 @@ refute_output() {
475475
'regex' "$unexpected" \
476476
'line' "${lines[$idx]}" \
477477
| batslib_decorate 'regular expression should not match line' \
478-
| flunk
478+
| fail
479479
fi
480480
elif (( is_mode_partial )); then
481481
if [[ ${lines[$idx]} == *"$unexpected"* ]]; then
@@ -484,15 +484,15 @@ refute_output() {
484484
'substring' "$unexpected" \
485485
'line' "${lines[$idx]}" \
486486
| batslib_decorate 'line should not contain substring' \
487-
| flunk
487+
| fail
488488
fi
489489
else
490490
if [[ ${lines[$idx]} == "$unexpected" ]]; then
491491
batslib_print_kv_single 10 \
492492
'index' "$idx" \
493493
'unexpected' "$unexpected" \
494494
| batslib_decorate 'line should differ' \
495-
| flunk
495+
| fail
496496
fi
497497
fi
498498
else
@@ -503,22 +503,22 @@ refute_output() {
503503
'regex' "$unexpected" \
504504
'output' "$output" \
505505
| batslib_decorate 'regular expression should not match output' \
506-
| flunk
506+
| fail
507507
fi
508508
elif (( is_mode_partial )); then
509509
if [[ $output == *"$unexpected"* ]]; then
510510
batslib_print_kv_single_or_multi 9 \
511511
'substring' "$unexpected" \
512512
'output' "$output" \
513513
| batslib_decorate 'output should not contain substring' \
514-
| flunk
514+
| fail
515515
fi
516516
else
517517
if [[ $output == "$unexpected" ]]; then
518518
batslib_print_kv_single_or_multi 6 \
519519
'output' "$output" \
520520
| batslib_decorate 'output equals, but it was expected to differ' \
521-
| flunk
521+
| fail
522522
fi
523523
fi
524524
fi
@@ -543,7 +543,7 @@ assert_success() {
543543
batslib_print_kv_single "$width" 'status' "$status"
544544
batslib_print_kv_single_or_multi "$width" 'output' "$output"
545545
} | batslib_decorate 'command failed' \
546-
| flunk
546+
| fail
547547
fi
548548
}
549549

@@ -569,7 +569,7 @@ assert_failure() {
569569
if (( status == 0 )); then
570570
batslib_print_kv_single_or_multi 6 'output' "$output" \
571571
| batslib_decorate 'command succeeded, but it was expected to fail' \
572-
| flunk
572+
| fail
573573
elif (( $# > 0 )) && (( status != expected )); then
574574
{ local -ir width=8
575575
batslib_print_kv_single "$width" \
@@ -578,6 +578,6 @@ assert_failure() {
578578
batslib_print_kv_single_or_multi "$width" \
579579
'output' "$output"
580580
} | batslib_decorate 'command failed as expected, but status differs' \
581-
| flunk
581+
| fail
582582
fi
583583
}

Diff for: man/batslib.7

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Assertions are functions that perform a test and output relevant information on
7272
Assertions about exit code and output operate on the results of the most recent invocation of \fBrun\fR\.
7373
.
7474
.TP
75-
\fBflunk\fR [\fIMESSAGE\fR]
75+
\fBfail\fR [\fIMESSAGE\fR]
7676
Display \fIMESSAGE\fR and fail\. This function provides a convenient way to report various failures\. Other test helpers also use it to display output on failure\. When no parameters are specified, \fIMESSAGE\fR is read from the standard input\.
7777
.
7878
.TP

Diff for: man/batslib.7.ronn

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ otherwise.
6363
Assertions about exit code and output operate on the results of the most
6464
recent invocation of `run`.
6565

66-
* `flunk` [<MESSAGE>]:
66+
* `fail` [<MESSAGE>]:
6767
Display <MESSAGE> and fail. This function provides a convenient way to
6868
report various failures. Other test helpers also use it to display
6969
output on failure. When no parameters are specified, <MESSAGE> is read

Diff for: test/60-lib-assertion-10-flunk.bats

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
load test_helper
44

5-
@test 'flunk() returns 1' {
6-
run flunk ''
5+
@test 'fail() returns 1' {
6+
run fail ''
77
[ "$status" -eq 1 ]
88
}
99

10-
@test 'flunk() prints positional parameters' {
11-
run flunk 'message'
10+
@test 'fail() prints positional parameters' {
11+
run fail 'message'
1212
[ "$status" -eq 1 ]
1313
[ "$output" == 'message' ]
1414
}
1515

16-
@test 'flunk() prints STDIN if no positional parameters are specified' {
17-
run bash -c "source '${BATS_LIB}/batslib.bash'; echo 'message' | flunk"
16+
@test 'fail() prints STDIN if no positional parameters are specified' {
17+
run bash -c "source '${BATS_LIB}/batslib.bash'; echo 'message' | fail"
1818
[ "$status" -eq 1 ]
1919
[ "$output" == 'message' ]
2020
}

0 commit comments

Comments
 (0)