btrfs-progs: tests: catch bad usage of run_mustfail

This function has an extra argument and can get forgotten, add a sanity
check so the bad usage can be caught during development.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2017-08-23 19:26:42 +02:00
parent f0c7703671
commit d7dd9d00e9

View file

@ -21,6 +21,26 @@ _assert_path()
exit 1
}
# $1: this string gets matched to files, absolute or relative path, or a
# systemwide command available via $PATH
_is_file_or_command()
{
local msg
msg="$1"
if [ -z "$msg" ]; then
return 1
fi
if [ -f "$msg" -o -d "$msg" -o -b "$msg" ]; then
return 0
fi
if [ -f $(type -p "$msg") ]; then
return 0
fi
return 1
}
_fail()
{
echo "$*" | tee -a "$RESULTS"
@ -185,6 +205,11 @@ run_mustfail()
msg="$1"
shift
if _is_file_or_command "$msg"; then
echo "ASSERTION FAIL: 1st argument of run_mustfail must be a message"
exit 1
fi
ins=$(_get_spec_ins "$@")
spec=$(($ins-1))
cmd=$(eval echo "\${$spec}")