Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non zero exit code on successful retry #670

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
}