mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 03:32:27 +01:00
Add bad command line option errors
This commit is contained in:
parent
03608115df
commit
dc0c645723
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" {
|
||||
|
|
Loading…
Reference in New Issue
Block a user