From 07a3b04d5ce1d7a22a4ce01f1b6b8f8fc6ffbb05 Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Tue, 12 Nov 2013 20:27:35 +0530 Subject: tests: add EXPECT_NOT macro We needed this macro while writing test cases for quota. With quota, a directory size is only guaranteed to be within some margin of quota limit, but not an accurate number. With not knowing what size to expect and EXPECT macro not complete enough to accept ranges of sizes, we can atleast write test-cases with EXPECT_NOT macro. After copying data to an empty file, it will be guaranteed the size will not be zero. This is good enough for quota test cases. Change-Id: I722ebd68044716a5eeaf0bd7e9aae61df8469017 BUG: 1022995 Signed-off-by: Raghavendra G Reviewed-on: http://review.gluster.org/6253 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- tests/include.rc | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/include.rc b/tests/include.rc index bb541eaa1..de28241c2 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -14,7 +14,7 @@ mkdir -p $B0; mkdir -p $M0 $M1; mkdir -p $N0 $N1; -testcnt=`egrep '^[[:space:]]*(EXPECT|TEST|EXPECT_WITHIN|EXPECT_KEYWORD)[[:space:]]' $0 | wc -l` +testcnt=`egrep '^[[:space:]]*(EXPECT|EXPECT_NOT|TEST|EXPECT_WITHIN|EXPECT_KEYWORD)[[:space:]]' $0 | wc -l` expect_tests=`egrep '^[[:space:]]*TESTS_EXPECTED_IN_LOOP[[:space:]]*' $0` x_ifs=$IFS @@ -71,6 +71,7 @@ function test_expect_footer() err="Got \"$a\" instead of \"$e\"" fi [[ "x${e}" == "x${a}" ]]; + test_footer "$err"; } @@ -89,6 +90,35 @@ function _EXPECT() test_expect_footer "$e" "$a"; } +function test_expect_not_footer() +{ + local e=$1 + local a=$2 + local err="" + + if [ "x${e}" == "x${a}" ]; then + err="Got \"$a\" when not expecting it" + fi + + [[ "x${e}" != "x${a}" ]]; + test_footer "$err"; +} + +function _EXPECT_NOT() +{ + TESTLINE=$1; + shift; + local a="" + + test_header "$@"; + + e="$1"; + shift; + a=$("$@" | tail -1) + + test_expect_not_footer "$e" "$a"; +} + function _EXPECT_KEYWORD() { TESTLINE=$1; @@ -238,6 +268,7 @@ function process_leak_count () } alias EXPECT='_EXPECT $LINENO' +alias EXPECT_NOT='_EXPECT_NOT $LINENO' alias TEST='_TEST $LINENO' alias EXPECT_WITHIN='_EXPECT_WITHIN $LINENO' alias EXPECT_KEYWORD='_EXPECT_KEYWORD $LINENO' -- cgit