Skip to content

Commit

Permalink
Merge pull request #20848 from edsantiago/safer_defer
Browse files Browse the repository at this point in the history
deferred test failures: handle a corner case
  • Loading branch information
openshift-merge-bot[bot] authored Dec 1, 2023
2 parents b05755b + f95dd21 commit 500da5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 0 additions & 4 deletions test/system/505-networking-pasta.bats
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ function pasta_test_do() {
assert "${output}" = "${expect}" "Mismatch between data sent and received"
}

function teardown() {
rm -f "${XFER_FILE}"
}

### Addresses ##################################################################

@test "IPv4 default address assignment" {
Expand Down
17 changes: 15 additions & 2 deletions test/system/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,20 @@ function basic_setup() {
immediate-assertion-failures
}

# bail-now is how we terminate a test upon assertion failure.
# By default, and the vast majority of the time, it just triggers
# immediate test termination; but see defer-assertion-failures, below.
function bail-now() {
# "false" does not apply to "bail now"! It means "nonzero exit",
# which BATS interprets as "yes, bail immediately".
false
}

# Invoked on teardown: will terminate immediately if there have been
# any deferred test failures; otherwise will reset back to immediate
# test termination on future assertions.
function immediate-assertion-failures() {
function bail-now() {
# "false" does not apply to "bail now"! It means "nonzero exit",
# which BATS interprets as "yes, bail immediately".
false
}

Expand All @@ -225,6 +235,9 @@ function immediate-assertion-failures() {
fi
}

# Used in special test circumstances--typically multi-condition loops--to
# continue going even on assertion failures. The test will fail afterward,
# usually in teardown. This can be useful to show failure patterns.
function defer-assertion-failures() {
function bail-now() {
ASSERTION_FAILURES+="!"
Expand Down

0 comments on commit 500da5e

Please sign in to comment.