Skip to content

Instantly share code, notes, and snippets.

@carlosonunez
Created December 14, 2018 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosonunez/597ede29762285d5a3a46a6b3fc41d76 to your computer and use it in GitHub Desktop.
Save carlosonunez/597ede29762285d5a3a46a6b3fc41d76 to your computer and use it in GitHub Desktop.
How to cause BATS to fail after the first failing test

Big thanks to @vincentbernat for this one!

Source: sstephenson/bats#135 (comment)

failing_tests.bats

#!bats
load fail_fast

setup() {
  fail_fast
}

teardown() {
  mark_test_as_completed
}

# put your tests below

fail_fast.bash

#!/usr/bin/env bash

fail_fast() {
  [ ! -f "${BATS_PARENT_TMPNAME}.skip" ] || skip "skipping; fail-fast is enabled"
}

mark_test_as_complete() {
  [ -n "$BATS_TEST_COMPLETED" ] || touch ${BATS_PARENT_TMPNAME}.skip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment