btrfs-progs: tests: introduce mustfail helper
authorDavid Sterba <dsterba@suse.com>
Tue, 22 Mar 2016 17:47:18 +0000 (18:47 +0100)
committerDavid Sterba <dsterba@suse.com>
Wed, 30 Mar 2016 14:25:59 +0000 (16:25 +0200)
Invalid syntax, expected failure on corrupted data etc. Failure is
success.

Signed-off-by: David Sterba <dsterba@suse.com>
tests/common

index 6178048..91682ef 100644 (file)
@@ -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