summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-03-22 18:47:18 +0100
committerDavid Sterba <dsterba@suse.com>2016-03-30 16:25:59 +0200
commit10d308d5ead864fe6b3db5228ed7833163bbca97 (patch)
tree15dda03191b7ac0fe57cd8f16eade66d5f6e6b6b
parent338e5832e7b2e0bec91b1907b9ed9eee81d7795d (diff)
btrfs-progs: tests: introduce mustfail helper
Invalid syntax, expected failure on corrupted data etc. Failure is success. Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--tests/common26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/common b/tests/common
index 61780486..91682eff 100644
--- a/tests/common
+++ b/tests/common
@@ -61,6 +61,32 @@ run_mayfail()
fi
}
+# first argument is error message to print if it fails, otherwise
+# same as run_check but expects the command to fail, output is logged
+run_mustfail()
+{
+ local msg
+
+ msg="$1"
+ shift
+
+ echo "############### $@" >> $RESULTS 2>&1
+ if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mustfail): $@" > /dev/tty; fi
+ if [ "$1" = 'root_helper' ]; then
+ "$@" >> $RESULTS 2>&1
+ else
+ $INSTRUMENT "$@" >> $RESULTS 2>&1
+ fi
+ if [ $? != 0 ]; then
+ echo "failed (expected): $@" >> $RESULTS
+ return 0
+ else
+ echo "succeeded (unexpected!): $@" >> $RESULTS
+ _fail "unexpected success: $msg"
+ return 1
+ fi
+}
+
check_prereq()
{
if ! [ -f $TOP/$1 ]; then