summaryrefslogtreecommitdiff
path: root/testprogs
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2022-11-09 14:04:23 +0100
committerVolker Lendecke <vl@samba.org>2022-11-10 07:27:31 +0000
commit55feb593012fc5b24e795a00081666fca740429c (patch)
tree6340f3961823d2f98d809688efaff568c7d8d639 /testprogs
parente24481251ddc64abfd51b9bd101833814defd8c4 (diff)
downloadsamba-55feb593012fc5b24e795a00081666fca740429c.tar.gz
testprogs: Add testit_grep_count() helper
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'testprogs')
-rwxr-xr-xtestprogs/blackbox/subunit.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/testprogs/blackbox/subunit.sh b/testprogs/blackbox/subunit.sh
index 75a9b5ec7e3..ba4e997c525 100755
--- a/testprogs/blackbox/subunit.sh
+++ b/testprogs/blackbox/subunit.sh
@@ -121,6 +121,35 @@ testit_grep()
return $status
}
+# This returns 0 if the command gave success and the grep value was found
+# num times all other cases return != 0
+testit_grep_count()
+{
+ name="$1"
+ shift
+ grep="$1"
+ shift
+ num="$1"
+ shift
+ cmdline="$@"
+ subunit_start_test "$name"
+ output=$($cmdline 2>&1)
+ status=$?
+ if [ x$status != x0 ]; then
+ printf '%s' "$output" | subunit_fail_test "$name"
+ return $status
+ fi
+ found=$(printf '%s' "$output" | grep -c "$grep")
+ if [ x"$found" = x"$num" ]; then
+ subunit_pass_test "$name"
+ else
+ printf 'GREP: "%s" found "%d" times, expected "%d" in output:\n%s'\
+ "$grep" "$found" "$num" "$output" |
+ subunit_fail_test "$name"
+ fi
+ return $status
+}
+
testit_expect_failure()
{
name="$1"