@@ -303,18 +303,19 @@ this test always fails
303
303
304
304
Fail if the given expression evaluates to false.
305
305
306
+ *** Note:*** * The expression must be a simple command. [ Compound
307
+ commands] ( https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands ) ,
308
+ such as ` [[ ` , can be used only when executed with ` bash -c ` .
309
+
306
310
``` bash
307
311
@test ' assert()' {
308
312
run touch ' /var/log/test.log'
309
313
assert [ -e ' /var/log/test.log' ]
310
314
}
311
315
```
312
316
313
- *** Note:*** * The expression must be a simple command. [ Compound
314
- commands] ( https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands ) ,
315
- such as ` [[ ` , can be used only when executed with ` bash -c ` .
316
-
317
- On failure the failed expression, ` $status ` and ` $output ` are displayed.
317
+ On failure, the failed expression, ` $status ` and ` $output ` are
318
+ displayed.
318
319
319
320
```
320
321
-- assertion failed --
@@ -338,7 +339,7 @@ not equal.
338
339
}
339
340
```
340
341
341
- On failure the expected and actual values are displayed.
342
+ On failure, the expected and actual values are displayed.
342
343
343
344
```
344
345
-- values do not equal --
@@ -356,17 +357,17 @@ Fail if `$status` is not 0.
356
357
357
358
``` bash
358
359
@test ' assert_success() status only' {
359
- run bash -c " echo 'have '; exit 1"
360
+ run bash -c " echo 'Error! '; exit 1"
360
361
assert_success
361
362
}
362
363
```
363
364
364
- On failure ` $status ` and ` $output ` are displayed.
365
+ On failure, ` $status ` and ` $output ` are displayed.
365
366
366
367
```
367
368
-- command failed --
368
369
status : 1
369
- output : have
370
+ output : Error!
370
371
--
371
372
```
372
373
@@ -379,16 +380,16 @@ Fail if `$status` is 0.
379
380
380
381
``` bash
381
382
@test ' assert_failure() status only' {
382
- run echo ' have '
383
+ run echo ' Success! '
383
384
assert_failure
384
385
}
385
386
```
386
387
387
- On failure ` $output ` is displayed.
388
+ On failure, ` $output ` is displayed.
388
389
389
390
```
390
391
-- command succeeded, but it was expected to fail --
391
- output : have
392
+ output : Success!
392
393
--
393
394
```
394
395
@@ -402,18 +403,18 @@ expected status specified by the parameter.
402
403
403
404
``` bash
404
405
@test ' assert_failure() with expected status' {
405
- run bash -c " echo 'error '; exit 1"
406
+ run bash -c " echo 'Error! '; exit 1"
406
407
assert_failure 2
407
408
}
408
409
```
409
410
410
- On failure the expected and actual status, and ` $output ` are displayed.
411
+ On failure, the expected and actual status, and ` $output ` are displayed.
411
412
412
413
```
413
414
-- command failed as expected, but status differs --
414
415
expected : 2
415
416
actual : 1
416
- output : error
417
+ output : Error!
417
418
--
418
419
```
419
420
@@ -453,14 +454,14 @@ If either value is longer than one line both are displayed in
453
454
454
455
##### Matching a specific line
455
456
456
- *** Note:*** * Due to a [ bug in Bats] [ bats-93 ] , empty lines are discarded
457
- from ` ${lines[@]} ` , causing line indices to change and preventing
458
- testing for empty lines.*
459
-
460
457
When ` -l <index> ` is used, only the line specified by its ` index ` in
461
458
` ${lines[@]} ` is matched, and the assertion fails if it does not equal
462
459
the expected line.
463
460
461
+ *** Note:*** * Due to a [ bug in Bats] [ bats-93 ] , empty lines are discarded
462
+ from ` ${lines[@]} ` , causing line indices to change and preventing
463
+ testing for empty lines.*
464
+
464
465
``` bash
465
466
@test ' assert_output() specific line' {
466
467
run echo $' have-0\n have-1\n have-2'
@@ -478,17 +479,17 @@ actual : have-1
478
479
--
479
480
```
480
481
481
- ##### Line found in output
482
+ ##### Looking for line in output
483
+
484
+ When ` -l ` is used without the ` <index> ` argument, fail if the expected
485
+ line is not found in ` ${lines[@]} ` .
482
486
483
487
*** Note:*** * Due to a [ bug in Bats] [ bats-93 ] , empty lines are discarded
484
488
from ` ${lines[@]} ` , causing line indices to change and preventing
485
489
testing for empty lines.*
486
490
487
- When ` -l ` is used without ` <index> ` , fail if the expected line is not
488
- found in ` ${lines[@]} ` .
489
-
490
491
``` bash
491
- @test ' assert_output() line found in output ' {
492
+ @test ' assert_output() looking for line ' {
492
493
run echo $' have-0\n have-1\n have-2'
493
494
assert_output -l ' want'
494
495
}
@@ -518,12 +519,21 @@ a substring can not be found in the output.
518
519
``` bash
519
520
@test ' assert_output() partial matching' {
520
521
run echo ' ERROR: no such file or directory'
521
- assert_output -p ' ERROR '
522
+ assert_output -p ' SUCCESS '
522
523
}
523
524
```
524
525
525
- This option can be used with ` -l ` as well, and does not change the set
526
- of information displayed on failure.
526
+ This option does not change the set if information displayed on failure.
527
+
528
+ ```
529
+ -- output does not contain substring --
530
+ substring : SUCCESS
531
+ output : ERROR: no such file or directory
532
+ --
533
+ ```
534
+
535
+ This option is mutually exclusive with regular expression matching (` -r ` ).
536
+ When used simultaneously, an error is displayed.
527
537
528
538
##### Regular expression matching
529
539
@@ -533,13 +543,25 @@ extended regular expression does not match the output.
533
543
534
544
``` bash
535
545
@test ' assert_output() regular expression matching' {
536
- run echo ' Foobar v0 .1.0'
546
+ run echo ' Foobar 0 .1.0'
537
547
assert_output -r ' ^Foobar v[0-9]+\.[0-9]+\.[0-9]$'
538
548
}
539
549
```
540
550
541
- This option can be used with ` -l ` as well, and does not change the set
542
- of information displayed on failure.
551
+ This option does not change the set if information displayed on failure.
552
+
553
+ ```
554
+ -- regular expression does not match output --
555
+ regex : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$
556
+ output : Foobar 0.1.0
557
+ --
558
+ ```
559
+
560
+ When the specified extended regular expression is invalid, an error is
561
+ displayed.
562
+
563
+ This option is mutually exclusive with partial matching (` -p ` ). When
564
+ used simultaneously, an error is displayed.
543
565
544
566
#### ` refute_output `
545
567
@@ -563,7 +585,7 @@ it equals the unexpected output.
563
585
}
564
586
```
565
587
566
- On failure, the unexpected output is displayed.
588
+ On failure, ` $ output` is displayed.
567
589
568
590
```
569
591
-- output equals, but it was expected to differ --
@@ -576,14 +598,14 @@ format.
576
598
577
599
##### Matching a specific line
578
600
601
+ When ` -l <index> ` is used, only the line specified by its ` index ` in
602
+ ` ${lines[@]} ` is matched, and the assertion fails if it equals the
603
+ unexpected line.
604
+
579
605
*** Note:*** * Due to a [ bug in Bats] [ bats-93 ] , empty lines are discarded
580
606
from ` ${lines[@]} ` , causing line indices to change and preventing
581
607
testing for empty lines.*
582
608
583
- When ` -l <index> ` is used, only the line specified by its ` index ` in
584
- ` ${lines[@]} ` is matched, and the assertion fails if it equals the
585
- expected line.
586
-
587
609
``` bash
588
610
@test ' refute_output() specific line' {
589
611
run echo $' have-0\n want-1\n have-2'
@@ -595,22 +617,22 @@ On failure, the index, and the unexpected line are displayed.
595
617
596
618
```
597
619
-- line should differ --
598
- index : 1
599
- unexpected : want-1
620
+ index : 1
621
+ line : want-1
600
622
--
601
623
```
602
624
603
- ##### Line found in output
625
+ ##### Looking for line in output
626
+
627
+ When ` -l ` is used without the ` <index> ` argument, fail if the unexpected
628
+ line is found in ` ${lines[@]} ` .
604
629
605
630
*** Note:*** * Due to a [ bug in Bats] [ bats-93 ] , empty lines are discarded
606
631
from ` ${lines[@]} ` , causing line indices to change and preventing
607
632
testing for empty lines.*
608
633
609
- When ` -l ` is used without ` <index> ` , fail if the unexpected line is
610
- found in ` ${lines[@]} ` .
611
-
612
634
``` bash
613
- @test ' refute_output() line found in output ' {
635
+ @test ' refute_output() looking for line ' {
614
636
run echo $' have-0\n want\n have-2'
615
637
refute_output -l ' want'
616
638
}
@@ -636,8 +658,8 @@ If `$output` is not longer than one line, it is displayed in
636
658
##### Partial matching
637
659
638
660
Partial matching, enabled using ` -p ` , provides more flexibility than the
639
- default literal matching. The assertion fails if the unexpected output as
640
- a substring can be found in the output.
661
+ default literal matching. The assertion fails if the unexpected output
662
+ as a substring can be found in the output.
641
663
642
664
``` bash
643
665
@test ' refute_output() partial matching' {
@@ -646,7 +668,8 @@ a substring can be found in the output.
646
668
}
647
669
```
648
670
649
- On failure, this option displays the substring in addition.
671
+ On failure, the substring is displayed in addition (if not already
672
+ displayed by other options).
650
673
651
674
```
652
675
-- output should not contain substring --
@@ -655,13 +678,14 @@ output : ERROR: no such file or directory
655
678
--
656
679
```
657
680
658
- This option can be used with ` -l ` as well.
681
+ This option is mutually exclusive with regular expression matching (` -r ` ).
682
+ When used simultaneously, an error is displayed.
659
683
660
684
##### Regular expression matching
661
685
662
686
Regular expression matching, enabled using ` -r ` , provides the most
663
- flexibility. The assertion fails if the expected output specified as an
664
- extended regular expression does not match the output.
687
+ flexibility. The assertion fails if the unexpected output specified as
688
+ an extended regular expression matches the output.
665
689
666
690
``` bash
667
691
@test ' refute_output() regular expression matching' {
@@ -670,7 +694,8 @@ extended regular expression does not match the output.
670
694
}
671
695
```
672
696
673
- On failure, this option displays the regular expression in addition.
697
+ On failure, the regular expression is displayed in addition (if not
698
+ already displayed by other options).
674
699
675
700
```
676
701
-- regular expression should not match output --
@@ -679,7 +704,11 @@ output : Foobar v0.1.0
679
704
--
680
705
```
681
706
682
- This option can be used with ` -l ` as well.
707
+ When the specified extended regular expression is invalid, an error is
708
+ displayed.
709
+
710
+ This option is mutually exclusive with partial matching (` -p ` ). When
711
+ used simultaneously, an error is displayed.
683
712
684
713
[ bats-93 ] : https://github.com/sstephenson/bats/pull/93
685
714
0 commit comments