Skip to content

Commit 7d661e5

Browse files
szedergitster
authored andcommitted
test-lib: fix non-portable pattern bracket expressions
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76e27fb commit 7d661e5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

t/test-lib-functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ test_set_port () {
12891289
port=$(($port + 10000))
12901290
fi
12911291
;;
1292-
*[^0-9]*|0*)
1292+
*[!0-9]*|0*)
12931293
error >&7 "invalid port number: $port"
12941294
;;
12951295
*)

t/test-lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ do
144144
--stress=*)
145145
stress=${opt#--*=}
146146
case "$stress" in
147-
*[^0-9]*|0*|"")
147+
*[!0-9]*|0*|"")
148148
echo "error: --stress=<N> requires the number of jobs to run" >&2
149149
exit 1
150150
;;
@@ -155,7 +155,7 @@ do
155155
--stress-limit=*)
156156
stress_limit=${opt#--*=}
157157
case "$stress_limit" in
158-
*[^0-9]*|0*|"")
158+
*[!0-9]*|0*|"")
159159
echo "error: --stress-limit=<N> requires the number of repetitions" >&2
160160
exit 1
161161
;;

0 commit comments

Comments
 (0)