1
0
mirror of https://github.com/sstephenson/bats.git synced 2025-12-07 17:03:57 +01:00
This commit is contained in:
qneill 2017-11-27 18:21:01 +00:00 committed by GitHub
commit d4c2e93a80
3 changed files with 15 additions and 5 deletions

View File

@ -6,7 +6,9 @@ version() {
}
usage() {
local errmsg="$1"
version
[ -n "$errmsg" ] && echo "Error: $errmsg"
echo "Usage: bats [-c] [-p | -t] <test> [<test> ...]"
}
@ -100,14 +102,14 @@ for option in "${options[@]}"; do
pretty="1"
;;
* )
usage >&2
usage "Bad command line option '-$option'" >&2
exit 1
;;
esac
done
if [ "${#arguments[@]}" -eq 0 ]; then
usage >&2
usage "Must specify at least one <test>" >&2
exit 1
fi

View File

@ -17,7 +17,7 @@ fi
BATS_TEST_FILENAME="$1"
if [ -z "$BATS_TEST_FILENAME" ]; then
echo "usage: bats-exec <filename>" >&2
echo "usage: bats-exec-test <filename>" >&2
exit 1
elif [ ! -f "$BATS_TEST_FILENAME" ]; then
echo "bats: $BATS_TEST_FILENAME does not exist" >&2

View File

@ -3,10 +3,18 @@
load test_helper
fixtures bats
@test "no arguments prints usage instructions" {
@test "no arguments prints message and usage instructions" {
run bats
[ $status -eq 1 ]
[ $(expr "${lines[1]}" : "Usage:") -ne 0 ]
[ $(expr "${lines[1]}" : "Error: Must specify at least one") -ne 0 ]
[ $(expr "${lines[2]}" : "Usage:") -ne 0 ]
}
@test "invalid option prints message and usage instructions" {
run bats --invalid-option
[ $status -eq 1 ]
[ $(expr "${lines[1]}" : "Error: Bad command line option") -ne 0 ]
[ $(expr "${lines[2]}" : "Usage:") -ne 0 ]
}
@test "-v and --version print version number" {