btrfs-progs: tests: catch bad usage of run_mustfail
authorDavid Sterba <dsterba@suse.com>
Wed, 23 Aug 2017 17:26:42 +0000 (19:26 +0200)
committerDavid Sterba <dsterba@suse.com>
Thu, 24 Aug 2017 17:08:18 +0000 (19:08 +0200)
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>
tests/common

index bed6009..a1ab3e0 100644 (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}")