From 10d308d5ead864fe6b3db5228ed7833163bbca97 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 22 Mar 2016 18:47:18 +0100 Subject: [PATCH] btrfs-progs: tests: introduce mustfail helper Invalid syntax, expected failure on corrupted data etc. Failure is success. Signed-off-by: David Sterba --- tests/common | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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