summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2017-08-23 19:26:42 +0200
committerDavid Sterba <dsterba@suse.com>2017-08-24 19:08:18 +0200
commitd7dd9d00e944ee2308ee23f7881fb1b58edf7214 (patch)
tree8b0c9126eb1379dc18edc28a2ee33ce4eaf9a753 /tests/common
parentf0c7703671996ed078462f41bb52490d7774aea3 (diff)
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>
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/common b/tests/common
index bed60094..a1ab3e03 100644
--- a/tests/common
+++ b/tests/common
@@ -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}")