Skip to content

Instantly share code, notes, and snippets.

@jpluscplusm
Last active July 22, 2017 01:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save jpluscplusm/0c164b95cc83de1f87b616360e7f375b to your computer and use it in GitHub Desktop.
Save jpluscplusm/0c164b95cc83de1f87b616360e7f375b to your computer and use it in GitHub Desktop.
Per-file setup/teardown support for BATS
setup() {
# Global setup
if [ $BATS_TEST_NUMBER -eq 1 ]; then
{
echo export FOO=bar
} >${BATS_TMPDIR}/bats.import.$PPID
fi
. ${BATS_TMPDIR}/bats.import.$PPID
# Per-test setup as per documentation
}
teardown() {
# Global teardown
if [ "$BATS_TEST_NAME" = "${BATS_TEST_NAMES[((${#BATS_TEST_NAMES[*]}-1))]}" ]; then
rm -f ${BATS_TMPDIR}/bats.import.$PPID
fi
# Per-test teardown as per documentation
}
@test "foo" {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment