Skip to content

Instantly share code, notes, and snippets.

@tilacog
Last active April 19, 2018 01:49
# This function will be called before each test case.
setup () {
# This block will run only for the first test in this file.
# Usefull for setting up resources that should last for all tests.
if [[ "$BATS_TEST_NUMBER" -eq 1 ]]; then
:
fi
:
}
# This function will be called after each test case.
teardown () {
# This block will run only for the last test case in this file.
# Usefull for tearing down global resources.
if [[ "${#BATS_TEST_NAMES[@]}" -eq "$BATS_TEST_NUMBER" ]]; then
:
fi
:
}
@test "hello, world" {
run echo "Hello, bats!"
[ "$status" -eq 0 ]
[ "$output" = "Hello, bats!" ]
}
@test "can handle failing commands" {
run rm inexistent_file # should return 1
[ "$status" -eq 1 ]
run grep "." inexistent_file # should return 2
[ "$status" -eq 2 ]
}
@tilacog
Copy link
Author

tilacog commented Apr 19, 2018

Run with

$ bats overview.bats

Expected output:

 ✓ hello, world
 ✓ can handle failing commands

2 tests, 0 failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment