[PATCH 21/27] t: define test_grep_return_success()
- From
Denton Liu <liu.denton@gmail.com>
- Date
- Nov 15, 2019, 01:01 UTC
- Message-ID
- <3f79d23b40c0586d0351f4d721097be4f7ba26b8.1573779465.git.liu.denton@gmail.com>
- In-Reply-To
- <cover.1573779465.git.liu.denton@gmail.com>
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 <liu.denton@gmail.com> --- 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