Message ID | 3f79d23b40c0586d0351f4d721097be4f7ba26b8.1573779465.git.liu.denton@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | t: general test cleanup + `set -o pipefail` | expand |
Denton Liu <liu.denton@gmail.com> writes: > +# Calls grep but returns zero even if no matching lines are found. > +test_grep_return_success () { > + grep "$@" || : > +} It makes sense to have a helper like this, but the name is quite a mouthful. I wonder if we can call it with a shorter name, e.g. "test_filter" or something.
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.
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(+)