forked from sstephenson/bats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sstephenson#243 from amilkh/add-examples
docs: add /docs/examples with a sample .bats test
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Examples | ||
|
||
This directory contains example .bats files. | ||
See the [bats-core wiki][examples] for more details. | ||
|
||
[examples]: (/bats-core/bats-core/wiki/Examples) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
# "unofficial" bash strict mode | ||
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode | ||
set -o errexit # Exit when simple command fails 'set -e' | ||
set -o errtrace # Exit on error inside any functions or subshells. | ||
set -o nounset # Trigger error when expanding unset variables 'set -u' | ||
set -o pipefail # Do not hide errors within pipes 'set -o pipefail' | ||
set -o xtrace # Display expanded command and arguments 'set -x' | ||
IFS=$'\n\t' # Split words on \n\t rather than spaces | ||
|
||
main() { | ||
tar -czf "$dst_tarball" -C "$src_dir" . | ||
} | ||
|
||
main "$@" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bats | ||
|
||
setup() { | ||
export dst_tarball="${BATS_TMPDIR}/dst.tar.gz" | ||
export src_dir="${BATS_TMPDIR}/src_dir" | ||
|
||
rm -rf "${dst_tarball}" "${src_dir}" | ||
mkdir "${src_dir}" | ||
touch "${src_dir}"/{a,b,c} | ||
} | ||
|
||
main() { | ||
bash "${BATS_TEST_DIRNAME}"/package-tarball | ||
} | ||
|
||
@test 'fail when \$src_dir and \$dst_tarball are unbound' { | ||
unset src_dir dst_tarball | ||
|
||
run main | ||
[ "${status}" -ne 0 ] | ||
} | ||
|
||
@test 'fail when \$src_dir is a non-existent directory' { | ||
src_dir='not-a-dir' | ||
|
||
run main | ||
[ "${status}" -ne 0 ] | ||
} | ||
|
||
@test 'pass when \$src_dir directory is empty' { | ||
rm -rf "${src_dir:?}/*" | ||
|
||
run main | ||
echo "$output" | ||
[ "${status}" -eq 0 ] | ||
} | ||
|
||
@test 'files in \$src_dir are added to tar archive' { | ||
run main | ||
[ "${status}" -eq 0 ] | ||
|
||
run tar tf "$dst_tarball" | ||
[ "${status}" -eq 0 ] | ||
[[ "${output}" =~ a ]] | ||
[[ "${output}" =~ b ]] | ||
[[ "${output}" =~ c ]] | ||
} |