In a future patch, we plan on running tests with `set -o pipefail`.
However, since grep can return failure in the case that no lines are
matched, this can trigger a failure in a pipe in the case where grep is
being used as a filter.
Define the test_grep_return_success() function which acts as a wrapper
around grep but always returns 0 so that it can be used in the situation
described above.
Signed-off-by: Denton Liu <redacted>
---
t/test-lib-functions.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..dddc4cc3b1 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -990,6 +990,11 @@ test_i18ngrep () {
return 1
}
+# Calls grep but returns zero even if no matching lines are found.
+test_grep_return_success () {
+ grep "$@" || :
+}
+
# Call any command "$@" but be more verbose about its
# failure. This is handy for commands like "test" which do
# not output anything when they fail.--
2.24.0.399.gf8350c9437