[PATCH 2/2] test-lib-functions: use BUG() in 'test_must_fail'
From: SZEDER Gábor <hidden>
Date: 2021-02-21 19:26:20
Subsystem:
the rest · Maintainer:
Linus Torvalds
In many test helper functions we verify that they were invoked with
sensible parameters, and call BUG() to abort the test script when the
parameters are buggy. 6a67c75948 (test-lib-functions: restrict
test_must_fail usage, 2020-07-07) added such a parameter verification
to 'test_must_fail', but it didn't report the error with BUG(), like
we usually do.
As discussed in detail in the previous patch, BUG() didn't really work
in 'test_must_fail' back then, but it resolved those issues, so let's
use BUG() in this case as well.
The two tests checking that 'test_must_fail' recognizes invalid
parameters need some updates:
- BUG() calls 'exit 1' to abort the test script, but we don't want
that to happen while testing 'test_must_fail' itself, so in those
tests we must invoke that function in a subshell.
- These tests check that 'test_must_fail' failed with the
appropriate error message, but BUG() sends its error message to a
different file descriptor, so update the redirection accordingly.
Signed-off-by: SZEDER Gábor <redacted>
---
t/t0000-basic.sh | 4 ++--
t/test-lib-functions.sh | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index a6e570d674..b9d5c6c404 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh@@ -1315,12 +1315,12 @@ test_expect_success 'test_must_fail on a failing git command with env' ' ' test_expect_success 'test_must_fail rejects a non-git command' ' - ! test_must_fail grep ^$ notafile 2>err && + ! ( test_must_fail grep ^$ notafile ) 7>err && grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err ' test_expect_success 'test_must_fail rejects a non-git command with env' ' - ! test_must_fail env var1=a var2=b grep ^$ notafile 2>err && + ! ( test_must_fail env var1=a var2=b grep ^$ notafile ) 7>err && grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err '
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index a40c1c5d83..cdbc59e4f0 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh@@ -910,8 +910,7 @@ test_must_fail () { esac if ! test_must_fail_acceptable "$@" then - echo >&6 "test_must_fail: only 'git' is allowed: $*" - return 1 + BUG "test_must_fail: only 'git' is allowed: $*" fi "$@" 2>&6 exit_code=$?
--
2.30.1.940.gce394404de