]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-lib: fix non-portable pattern bracket expressions
authorSZEDER Gábor <szeder.dev@gmail.com>
Mon, 11 Feb 2019 19:58:03 +0000 (20:58 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Feb 2019 22:34:36 +0000 (14:34 -0800)
Use a '!' character to start a non-matching pattern bracket
expression, as specified by POSIX in Shell Command Language section
2.13.1 Patterns Matching a Single Character [1].

I used '^' instead in three places in the previous three commits, to
verify that the arguments of the '--stress=' and '--stress-limit='
options and the values of various '*_PORT' environment variables are
valid numbers.  With certain shells, at least with dash (upstream and
in Ubuntu 14.04) and mksh, this led to various undesired behaviors:

  # error message in case of a valid number
  $ ~/src/dash/src/dash ./t3903-stash.sh --stress=8
  error: --stress=<N> requires the number of jobs to run

  # not the expected error message
  $ ~/src/dash/src/dash ./t3903-stash.sh --stress=foo
  ./t3903-stash.sh: 238: test: Illegal number: foo

  # no error message at all?!
  $ mksh ./t3903-stash.sh --stress=foo
  $ echo $?
  0

Some other shells, e.g. Bash (even in posix mode), ksh, dash in Ubuntu
16.04 or later, are apparently happy to accept '^' just as well.

[1] http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_13

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib-functions.sh
t/test-lib.sh

index 92cf8f812cca26c94c8054ccd40af806f6b77310..969e2ba6dadd50ecb3a5a03fe9f8c72527eac279 100644 (file)
@@ -1289,7 +1289,7 @@ test_set_port () {
                        port=$(($port + 10000))
                fi
                ;;
-       *[^0-9]*|0*)
+       *[!0-9]*|0*)
                error >&7 "invalid port number: $port"
                ;;
        *)
index 77eff04c92ab183c992e871aa34720f2d78014b1..4e7cb52b57a59b76404f701a542fc58ce06ec685 100644 (file)
@@ -144,7 +144,7 @@ do
        --stress=*)
                stress=${opt#--*=}
                case "$stress" in
-               *[^0-9]*|0*|"")
+               *[!0-9]*|0*|"")
                        echo "error: --stress=<N> requires the number of jobs to run" >&2
                        exit 1
                        ;;
@@ -155,7 +155,7 @@ do
        --stress-limit=*)
                stress_limit=${opt#--*=}
                case "$stress_limit" in
-               *[^0-9]*|0*|"")
+               *[!0-9]*|0*|"")
                        echo "error: --stress-limit=<N> requires the number of repetitions" >&2
                        exit 1
                        ;;