Last active
May 16, 2023 11:07
-
-
Save tkuchiki/041a401041530c05f73a to your computer and use it in GitHub Desktop.
Example Bats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### setup start | |
BATS_TEST_NAME: test_example_status_and_output-2c_lines | |
BATS_TEST_FILENAME: /home/bats/test.bats | |
BATS_TEST_DIRNAME: /home/bats | |
BATS_TEST_NAMES: test_example_status_and_output-2c_lines | |
BATS_TEST_DESCRIPTION: example status and output, lines | |
BATS_TEST_NUMBER: 1 | |
BATS_TMPDIR: /tmp | |
##### setup end | |
example 1 | |
##### teardown test_example_status_and_output-2c_lines | |
##### setup start | |
BATS_TEST_NAME: test_example_skip | |
BATS_TEST_FILENAME: /home/bats/test.bats | |
BATS_TEST_DIRNAME: /home/bats | |
BATS_TEST_NAMES: test_example_skip | |
BATS_TEST_DESCRIPTION: example skip | |
BATS_TEST_NUMBER: 2 | |
BATS_TMPDIR: /tmp | |
##### setup end | |
example 2 | |
##### teardown test_example_skip | |
##### setup start | |
BATS_TEST_NAME: test_example_load | |
BATS_TEST_FILENAME: /home/bats/gist.bats | |
BATS_TEST_DIRNAME: /home/bats | |
BATS_TEST_NAMES: test_example_load | |
BATS_TEST_DESCRIPTION: example load | |
BATS_TEST_NUMBER: 3 | |
BATS_TMPDIR: /tmp | |
##### setup end | |
example 3 | |
##### teardown test_example_load |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
assert_equal() { | |
if [ "${1}" != "${2}" ]; then | |
echo "${1} != ${2}" | |
return 1 | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bats test.bats | |
✓ example status and output, lines | |
- example skip (skipped: skipped test) | |
✓ example load | |
3 tests, 0 failures, 1 skipped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "foobar" | |
exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bats | |
setup() { | |
INDEX=$((${BATS_TEST_NUMBER} - 1)) | |
echo "##### setup start" >> ./bats.log | |
echo "BATS_TEST_NAME: ${BATS_TEST_NAME}" >> ./bats.log | |
echo "BATS_TEST_FILENAME: ${BATS_TEST_FILENAME}" >> ./bats.log | |
echo "BATS_TEST_DIRNAME: ${BATS_TEST_DIRNAME}" >> ./bats.log | |
echo "BATS_TEST_NAMES: ${BATS_TEST_NAMES[$INDEX]}" >> ./bats.log | |
echo "BATS_TEST_DESCRIPTION: ${BATS_TEST_DESCRIPTION}" >> ./bats.log | |
echo "BATS_TEST_NUMBER: ${BATS_TEST_NUMBER}" >> ./bats.log | |
echo "BATS_TMPDIR: ${BATS_TMPDIR}" >> ./bats.log | |
echo "##### setup end" >> ./bats.log | |
} | |
teardown() { | |
echo -e "##### teardown ${BATS_TEST_NAME}\n" >> ./bats.log | |
} | |
@test "example status and output, lines" { | |
echo " example 1" >> ./bats.log | |
run ./status.sh | |
[ "${status}" -eq 1 ] | |
[ "${output}" = "foobar" ] | |
[ "${lines[0]}" = "foobar" ] | |
} | |
@test "example skip" { | |
echo " example 2" >> ./bats.log | |
skip "skipped test" | |
} | |
@test "example load" { | |
echo " example 3" >> ./bats.log | |
load helper | |
assert_equal 1 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment