_bail will now default to current spec caller

stderr
Mike Gerwitz 2014-05-09 02:14:11 -04:00
parent 61ecb6ad82
commit 08e1d9c889
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
1 changed files with 10 additions and 2 deletions

View File

@ -202,14 +202,22 @@ fail()
# #
# This should only be used in the case of a specification parsing error or # This should only be used in the case of a specification parsing error or
# other fatal errors; it should not be used for failing expectations. # other fatal errors; it should not be used for failing expectations.
#
# If no file and line number are provided, this will default to the current
# spec caller, if any.
_bail() _bail()
{ {
local msg="$1" local -r msg="$1"
local line="$2" local line="$2"
local file="$3" local file="$3"
# default to current caller if no line/file was provided
if [ -z "$file" -a -n "$__spec_caller" ]; then
read line file <<< "$__spec_caller"
fi
echo -n "error: $1" >&2 echo -n "error: $1" >&2
[ $# -gt 1 ] && echo -n " at $file:$line" >&2 [ -n "$file" ] && echo -n " at $file:$line" >&2
echo echo
exit 1 exit 1