Skip to content

Commit 8c679c7

Browse files
Merge pull request #670 from martin-schulze-vireso/fix/issue-660-non-zero-exit-code-on-successful-retry
Fix non zero exit code on successful retry
2 parents 27807ae + 72beb85 commit 8c679c7

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
88
[kac]: https://keepachangelog.com/en/1.0.0/
99
[semver]: https://semver.org/
1010

11+
## [Unreleased]
12+
13+
### Fixed
14+
15+
* fix non zero return code on successful retried tests (#670)
16+
1117
## [1.8.1] - 2022-10-19
1218

1319
### Fixed

libexec/bats-core/bats-exec-file

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ bats_run_test_with_retries() { # <args>
221221
status=$?
222222
if ((status == BATS_RETRY_RETURN_CODE)); then
223223
should_try_again=1
224+
status=0 # this is not the last try -> reset status
224225
else
225226
should_try_again=0
226227
bats_exec_file_status=$status

test/bats.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ enforce_own_process_group() {
14331433
}
14341434

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

14821483
}
1484+
1485+
@test "Exit code is zero after successful retry (see #660)" {
1486+
# shellcheck disable=SC2031
1487+
export LOG="$BATS_TEST_TMPDIR/call.log"
1488+
bats_require_minimum_version 1.5.0
1489+
reentrant_run -0 bats "$FIXTURE_ROOT/retry_success.bats"
1490+
[ "${lines[0]}" == '1..1' ]
1491+
[ "${lines[1]}" == 'ok 1 Fail once' ]
1492+
[ ${#lines[@]} == 2 ]
1493+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# shellcheck disable=SC2034
2+
BATS_TEST_RETRIES=2 # means three tries per test
3+
4+
@test "Fail once" {
5+
((BATS_TEST_TRY_NUMBER > 1)) || false
6+
}

0 commit comments

Comments
 (0)