Improve test framework: assertGrep error on bad file

This commit is contained in:
Andrew Bettison 2012-06-22 17:16:43 +09:30
parent aedb31e451
commit cf03033429

View File

@ -725,6 +725,16 @@ _tfw_assert_grep() {
local file="$2"
local pattern="$3"
local message=
if ! [ -e "$file" ]; then
_tfw_error "$file does not exist"
ret=254
elif ! [ -f "$file" ]; then
_tfw_error "$file is not a regular file"
ret=254
elif ! [ -r "$file" ]; then
_tfw_error "$file is not readable"
ret=254
else
local matches=$(( $(grep --regexp="$pattern" "$file" | wc -l) + 0 ))
local done=false
local ret=0
@ -787,6 +797,7 @@ _tfw_assert_grep() {
ret=254
fi
_tfw_shopt_restore
fi
if [ $ret -ne 0 ]; then
_tfw_backtrace
fi