d572f52a64 (test_cmp: diagnose incorrect arguments, 2020-08-09) taught
test_cmp() and test_cmp_bin() to diagnose a missing input source. Even
though the arguments to test_cmp() must name regular files (or standard
input), it only diagnoses whether a source is missing, which makes the
check a bit loose. Teach the check to be more precise by diagnosing, not
only a missing source, but also if the source is not a regular file.
Signed-off-by: Eric Sunshine <redacted>
---
On Wed, Sep 16, 2020 at 5:14 PM Junio C Hamano [off-list ref] wrote:
> Eric Sunshine [off-list ref] writes:
> > [...] I ask because test_cmp() was updated not long ago to
> > provide better diagnostics when one of the files is missing.
> > [1]: d572f52a64 (test_cmp: diagnose incorrect arguments, 2020-08-09)
>
> Yes, you did this with the commit,
> test "x$1" = x- || test -e "$1" || BUG "test_cmp '$1' missing"
> test "x$2" = x- || test -e "$2" || BUG "test_cmp '$2' missing"
> and I do not immediately see why "test -e" shouldn't be "test -f".
> It should ideally be "stdin is OK, otherwise it must be a readable
> regular file".
Perhaps the present patch suitably address your concern?
t/test-lib-functions.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 8d59b90348..4bc54e9e80 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -955,8 +955,8 @@ test_cmp() {
test $# -eq 2 || BUG "test_cmp requires two arguments"
if ! eval "$GIT_TEST_CMP" '"$@"'
then
- test "x$1" = x- || test -e "$1" || BUG "test_cmp '$1' missing"
- test "x$2" = x- || test -e "$2" || BUG "test_cmp '$2' missing"
+ test "x$1" = x- || test -f "$1" || BUG "test_cmp '$1' missing or not regular file"
+ test "x$2" = x- || test -f "$2" || BUG "test_cmp '$2' missing or not regular file"
return 1
fi
}@@ -990,8 +990,8 @@ test_cmp_bin() {
test $# -eq 2 || BUG "test_cmp_bin requires two arguments"
if ! cmp "$@"
then
- test "x$1" = x- || test -e "$1" || BUG "test_cmp_bin '$1' missing"
- test "x$2" = x- || test -e "$2" || BUG "test_cmp_bin '$2' missing"
+ test "x$1" = x- || test -f "$1" || BUG "test_cmp_bin '$1' missing or not regular file"
+ test "x$2" = x- || test -f "$2" || BUG "test_cmp_bin '$2' missing or not regular file"
return 1
fi
}--
2.28.0.942.g77c4c6094c