Skip to content

Commit

Permalink
Merge pull request #593 from rico-chet/update-negation-recommendation
Browse files Browse the repository at this point in the history
docs/gotchas: Update recommendation for negative statements
  • Loading branch information
martin-schulze-vireso committed May 19, 2022
2 parents 410dd22 + c7f7772 commit dc71ae6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
[kac]: https://keepachangelog.com/en/1.0.0/
[semver]: https://semver.org/

## [Unreleased]

### Added

#### Documentation

* update gotcha about negated statements: Recommend using `run !` on Bats
versions >=1.5.0 (#593)

## [1.7.0] - 2022-05-14

### Added
Expand Down
5 changes: 3 additions & 2 deletions docs/source/gotchas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ Please adhere to this idiom while using bats, or you will constantly work agains
My negated statement (e.g. ! true) does not fail the test, even when it should.
-------------------------------------------------------------------------------

Bash deliberately excludes negated return values from causing a pipeline to exit (see bash's `-e` option). You'll need to use the form `! x || false` or (recommended) use `run` and check for `[ $status != 0 ]`.
Bash deliberately excludes negated return values from causing a pipeline to exit (see bash's `-e` option).
Use `run !` on Bats 1.5.0 and above. For older bats versions, use one of `! x || false` or `run` with `[ $status != 0 ]`.

If the negated command is the final statement in a test, that final statement's (negated) exit status will propagate through to the test's return code as usual.
Negated statements of the form `! x || false` will explicitly fail the test when the pipeline returns true, regardless of where they occur in the test.
Negated statements of one of the correct forms mentioned above will explicitly fail the test when the pipeline returns true, regardless of where they occur in the test.

I cannot register a test multiple times via for loop.
-----------------------------------------------------
Expand Down

0 comments on commit dc71ae6

Please sign in to comment.