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

Commit b38bb25

Browse files
committed
Cleanup source, documentation and tests
1 parent 38d5a73 commit b38bb25

22 files changed

+442
-386
lines changed

Diff for: README.md

+79-50
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,19 @@ this test always fails
303303

304304
Fail if the given expression evaluates to false.
305305

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+
306310
```bash
307311
@test 'assert()' {
308312
run touch '/var/log/test.log'
309313
assert [ -e '/var/log/test.log' ]
310314
}
311315
```
312316

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.
318319

319320
```
320321
-- assertion failed --
@@ -338,7 +339,7 @@ not equal.
338339
}
339340
```
340341

341-
On failure the expected and actual values are displayed.
342+
On failure, the expected and actual values are displayed.
342343

343344
```
344345
-- values do not equal --
@@ -356,17 +357,17 @@ Fail if `$status` is not 0.
356357

357358
```bash
358359
@test 'assert_success() status only' {
359-
run bash -c "echo 'have'; exit 1"
360+
run bash -c "echo 'Error!'; exit 1"
360361
assert_success
361362
}
362363
```
363364

364-
On failure `$status` and `$output` are displayed.
365+
On failure, `$status` and `$output` are displayed.
365366

366367
```
367368
-- command failed --
368369
status : 1
369-
output : have
370+
output : Error!
370371
--
371372
```
372373

@@ -379,16 +380,16 @@ Fail if `$status` is 0.
379380

380381
```bash
381382
@test 'assert_failure() status only' {
382-
run echo 'have'
383+
run echo 'Success!'
383384
assert_failure
384385
}
385386
```
386387

387-
On failure `$output` is displayed.
388+
On failure, `$output` is displayed.
388389

389390
```
390391
-- command succeeded, but it was expected to fail --
391-
output : have
392+
output : Success!
392393
--
393394
```
394395

@@ -402,18 +403,18 @@ expected status specified by the parameter.
402403

403404
```bash
404405
@test 'assert_failure() with expected status' {
405-
run bash -c "echo 'error'; exit 1"
406+
run bash -c "echo 'Error!'; exit 1"
406407
assert_failure 2
407408
}
408409
```
409410

410-
On failure the expected and actual status, and `$output` are displayed.
411+
On failure, the expected and actual status, and `$output` are displayed.
411412

412413
```
413414
-- command failed as expected, but status differs --
414415
expected : 2
415416
actual : 1
416-
output : error
417+
output : Error!
417418
--
418419
```
419420

@@ -453,14 +454,14 @@ If either value is longer than one line both are displayed in
453454

454455
##### Matching a specific line
455456

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-
460457
When `-l <index>` is used, only the line specified by its `index` in
461458
`${lines[@]}` is matched, and the assertion fails if it does not equal
462459
the expected line.
463460

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+
464465
```bash
465466
@test 'assert_output() specific line' {
466467
run echo $'have-0\nhave-1\nhave-2'
@@ -478,17 +479,17 @@ actual : have-1
478479
--
479480
```
480481

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[@]}`.
482486

483487
***Note:*** *Due to a [bug in Bats][bats-93], empty lines are discarded
484488
from `${lines[@]}`, causing line indices to change and preventing
485489
testing for empty lines.*
486490

487-
When `-l` is used without `<index>`, fail if the expected line is not
488-
found in `${lines[@]}`.
489-
490491
```bash
491-
@test 'assert_output() line found in output' {
492+
@test 'assert_output() looking for line' {
492493
run echo $'have-0\nhave-1\nhave-2'
493494
assert_output -l 'want'
494495
}
@@ -518,12 +519,21 @@ a substring can not be found in the output.
518519
```bash
519520
@test 'assert_output() partial matching' {
520521
run echo 'ERROR: no such file or directory'
521-
assert_output -p 'ERROR'
522+
assert_output -p 'SUCCESS'
522523
}
523524
```
524525

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.
527537

528538
##### Regular expression matching
529539

@@ -533,13 +543,25 @@ extended regular expression does not match the output.
533543

534544
```bash
535545
@test 'assert_output() regular expression matching' {
536-
run echo 'Foobar v0.1.0'
546+
run echo 'Foobar 0.1.0'
537547
assert_output -r '^Foobar v[0-9]+\.[0-9]+\.[0-9]$'
538548
}
539549
```
540550

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.
543565

544566
#### `refute_output`
545567

@@ -563,7 +585,7 @@ it equals the unexpected output.
563585
}
564586
```
565587

566-
On failure, the unexpected output is displayed.
588+
On failure, `$output` is displayed.
567589

568590
```
569591
-- output equals, but it was expected to differ --
@@ -576,14 +598,14 @@ format.
576598

577599
##### Matching a specific line
578600

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+
579605
***Note:*** *Due to a [bug in Bats][bats-93], empty lines are discarded
580606
from `${lines[@]}`, causing line indices to change and preventing
581607
testing for empty lines.*
582608

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-
587609
```bash
588610
@test 'refute_output() specific line' {
589611
run echo $'have-0\nwant-1\nhave-2'
@@ -595,22 +617,22 @@ On failure, the index, and the unexpected line are displayed.
595617

596618
```
597619
-- line should differ --
598-
index : 1
599-
unexpected : want-1
620+
index : 1
621+
line : want-1
600622
--
601623
```
602624

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[@]}`.
604629

605630
***Note:*** *Due to a [bug in Bats][bats-93], empty lines are discarded
606631
from `${lines[@]}`, causing line indices to change and preventing
607632
testing for empty lines.*
608633

609-
When `-l` is used without `<index>`, fail if the unexpected line is
610-
found in `${lines[@]}`.
611-
612634
```bash
613-
@test 'refute_output() line found in output' {
635+
@test 'refute_output() looking for line' {
614636
run echo $'have-0\nwant\nhave-2'
615637
refute_output -l 'want'
616638
}
@@ -636,8 +658,8 @@ If `$output` is not longer than one line, it is displayed in
636658
##### Partial matching
637659

638660
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.
641663

642664
```bash
643665
@test 'refute_output() partial matching' {
@@ -646,7 +668,8 @@ a substring can be found in the output.
646668
}
647669
```
648670

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).
650673

651674
```
652675
-- output should not contain substring --
@@ -655,13 +678,14 @@ output : ERROR: no such file or directory
655678
--
656679
```
657680

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.
659683

660684
##### Regular expression matching
661685

662686
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.
665689

666690
```bash
667691
@test 'refute_output() regular expression matching' {
@@ -670,7 +694,8 @@ extended regular expression does not match the output.
670694
}
671695
```
672696

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).
674699

675700
```
676701
-- regular expression should not match output --
@@ -679,7 +704,11 @@ output : Foobar v0.1.0
679704
--
680705
```
681706

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.
683712

684713
[bats-93]: https://github.com/sstephenson/bats/pull/93
685714

0 commit comments

Comments
 (0)