Skip to content

Commit

Permalink
Merge pull request #670 from martin-schulze-vireso/fix/issue-660-non-…
Browse files Browse the repository at this point in the history
…zero-exit-code-on-successful-retry

Fix non zero exit code on successful retry
  • Loading branch information
martin-schulze-vireso committed Oct 19, 2022
2 parents 27807ae + 72beb85 commit 8c679c7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Expand Up @@ -8,6 +8,12 @@ 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]

### Fixed

* fix non zero return code on successful retried tests (#670)

## [1.8.1] - 2022-10-19

### Fixed
Expand Down
1 change: 1 addition & 0 deletions libexec/bats-core/bats-exec-file
Expand Up @@ -221,6 +221,7 @@ bats_run_test_with_retries() { # <args>
status=$?
if ((status == BATS_RETRY_RETURN_CODE)); then
should_try_again=1
status=0 # this is not the last try -> reset status
else
should_try_again=0
bats_exec_file_status=$status
Expand Down
11 changes: 11 additions & 0 deletions test/bats.bats
Expand Up @@ -1433,6 +1433,7 @@ enforce_own_process_group() {
}

@test "BATS_TEST_RETRIES allows for retrying tests" {
# shellcheck disable=SC2030
export LOG="$BATS_TEST_TMPDIR/call.log"
bats_require_minimum_version 1.5.0
reentrant_run ! bats "$FIXTURE_ROOT/retry.bats"
Expand Down Expand Up @@ -1480,3 +1481,13 @@ enforce_own_process_group() {
[ "${#lines[@]}" -eq 6 ]

}

@test "Exit code is zero after successful retry (see #660)" {
# shellcheck disable=SC2031
export LOG="$BATS_TEST_TMPDIR/call.log"
bats_require_minimum_version 1.5.0
reentrant_run -0 bats "$FIXTURE_ROOT/retry_success.bats"
[ "${lines[0]}" == '1..1' ]
[ "${lines[1]}" == 'ok 1 Fail once' ]
[ ${#lines[@]} == 2 ]
}
6 changes: 6 additions & 0 deletions test/fixtures/bats/retry_success.bats
@@ -0,0 +1,6 @@
# shellcheck disable=SC2034
BATS_TEST_RETRIES=2 # means three tries per test

@test "Fail once" {
((BATS_TEST_TRY_NUMBER > 1)) || false
}

0 comments on commit 8c679c7

Please sign in to comment.