From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Jeff King" <peff@peff.net>,
git@vger.kernel.org, "SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH] test-lib: fix non-portable pattern bracket expressions
Date: Mon, 11 Feb 2019 20:58:03 +0100 [thread overview]
Message-ID: <20190211195803.1682-1-szeder.dev@gmail.com> (raw)
In-Reply-To: <20190208115045.13256-1-szeder.dev@gmail.com>
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>
---
Should go on top of 'sg/stress-test'.
t/test-lib-functions.sh | 2 +-
t/test-lib.sh | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 92cf8f812c..969e2ba6da 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1289,7 +1289,7 @@ test_set_port () {
port=$(($port + 10000))
fi
;;
- *[^0-9]*|0*)
+ *[!0-9]*|0*)
error >&7 "invalid port number: $port"
;;
*)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 77eff04c92..4e7cb52b57 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -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
;;
--
2.21.0.rc0.405.g6226d63c89
next prev parent reply other threads:[~2019-02-11 19:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-08 11:50 [PATCH] test-lib: make '--stress' more bisect-friendly SZEDER Gábor
2019-02-08 16:47 ` Jeff King
2019-02-08 16:49 ` Jeff King
2019-02-08 18:33 ` SZEDER Gábor
2019-02-08 19:12 ` Jeff King
2019-02-08 18:23 ` SZEDER Gábor
2019-02-08 19:11 ` Jeff King
2019-02-11 19:58 ` SZEDER Gábor [this message]
2019-02-11 22:29 ` [PATCH] test-lib: fix non-portable pattern bracket expressions Junio C Hamano
2019-02-11 23:46 ` Jeff King
2019-02-12 0:30 ` SZEDER Gábor
2019-02-12 0:34 ` Jeff King
2019-02-12 10:47 ` Carlo Arenas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190211195803.1682-1-szeder.dev@gmail.com \
--to=szeder.dev@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.