tests: add and use bt_grep_ok
[babeltrace.git] / tests / utils / utils.sh
index 24f1b2d26b6c9af59655bf303c4f5e324935d476..7f1a4368008e977b846bf84f49bbbbc4f3e9cfb1 100644 (file)
@@ -302,6 +302,29 @@ bt_grep() {
        "$BT_TESTS_GREP_BIN" "$@"
 }
 
+# ok() with the test name `$3` on the result of bt_grep() matching the
+# pattern `$1` within the file `$2`.
+bt_grep_ok() {
+       local pattern=$1
+       local file=$2
+       local test_name=$3
+
+       bt_grep --silent "$pattern" "$file"
+
+       local ret=$?
+
+       if ! ok $ret "$test_name"; then
+               {
+                       echo "Pattern \`$pattern\` doesn't match the contents of \`$file\`:"
+                       echo '--- 8< ---'
+                       cat "$file"
+                       echo '--- >8 ---'
+               } >&2
+       fi
+
+       return $ret
+}
+
 ### Functions ###
 
 check_coverage() {
This page took 0.025168 seconds and 4 git commands to generate.