From c9ba8373643a5e988f68e5840e785a6a1cf7ab19 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Wed, 7 Dec 2011 09:03:26 -0500 Subject: [PATCH] commit bash-20070208 snapshot --- MANIFEST | 2 ++ builtins/echo.def | 4 +++- tests/builtins.right | 15 ++++++++++++--- tests/builtins.tests | 3 +++ tests/cond-regexp.sub | 36 ++++++++++++++++++++++++++++++++++++ tests/cond.right | 15 +++++++++++++++ tests/cond.tests | 2 ++ tests/run-builtins | 3 +++ tests/source6.sub | 29 +++++++++++++++++++++++++++++ 9 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 tests/cond-regexp.sub create mode 100644 tests/source6.sub diff --git a/MANIFEST b/MANIFEST index 8e1a8ff32..a5055eaea 100644 --- a/MANIFEST +++ b/MANIFEST @@ -714,10 +714,12 @@ tests/source2.sub f tests/source3.sub f tests/source4.sub f tests/source5.sub f +tests/source6.sub f tests/comsub.tests f tests/comsub.right f tests/cond.tests f tests/cond.right f +tests/cond-regexp.sub f tests/cprint.tests f tests/cprint.right f tests/dbg-support.right f diff --git a/builtins/echo.def b/builtins/echo.def index 923c43a24..4291d7c16 100644 --- a/builtins/echo.def +++ b/builtins/echo.def @@ -43,7 +43,7 @@ following backslash-escaped characters is turned on: \a alert (bell) \b backspace \c suppress trailing newline - \E escape character + \e escape character \f form feed \n new line \r carriage return @@ -52,6 +52,8 @@ following backslash-escaped characters is turned on: \\ backslash \0nnn the character whose ASCII code is NNN (octal). NNN can be 0 to 3 octal digits + \xHH the eight-bit character whose value is HH (hexadecimal). HH + can be one or two hex digits You can explicitly turn off the interpretation of the above characters with the -E option. diff --git a/tests/builtins.right b/tests/builtins.right index 9266b5a71..30e10ca94 100644 --- a/tests/builtins.right +++ b/tests/builtins.right @@ -108,6 +108,15 @@ m n o p ./source5.sub: line 10: /tmp/source-notthere: No such file or directory after bad source 1 ./source5.sub: line 17: /tmp/source-notthere: No such file or directory +one - OK +0 +0 +two - OK +0 +three - OK +0 +four - OK +0 AVAR foo foo @@ -118,15 +127,15 @@ AVAR foo declare -x foo="" declare -x FOO="\$\$" -./builtins.tests: line 207: declare: FOO: not found +./builtins.tests: line 210: declare: FOO: not found declare -x FOO="\$\$" ok ok -./builtins.tests: line 239: kill: 4096: invalid signal specification +./builtins.tests: line 242: kill: 4096: invalid signal specification 1 a\n\n\nb a b -./builtins.tests: line 248: exit: status: numeric argument required +./builtins.tests: line 251: exit: status: numeric argument required diff --git a/tests/builtins.tests b/tests/builtins.tests index 3c286338a..6d20ae92a 100644 --- a/tests/builtins.tests +++ b/tests/builtins.tests @@ -176,6 +176,9 @@ ${THIS_SH} ./builtins1.sub # test behavior of `.' when given a non-existant file argument ${THIS_SH} ./source5.sub +# test bugs in sourcing non-regular files, fixed post-bash-3.2 +${THIS_SH} ./source6.sub + # in posix mode, assignment statements preceding special builtins are # reflected in the shell environment. `.' and `eval' need special-case # code. diff --git a/tests/cond-regexp.sub b/tests/cond-regexp.sub new file mode 100644 index 000000000..2d3bfe717 --- /dev/null +++ b/tests/cond-regexp.sub @@ -0,0 +1,36 @@ +VAR='[[:alpha:]]' + +[[ $VAR =~ '[[:alpha:]]' ]] && echo match 1 + +[[ a =~ '[[:alpha:]]' ]] || echo match 2 + +[[ a =~ [[:alpha:]] ]] && echo match 3 + +[[ a =~ $VAR ]] && echo match 4 + +[[ a =~ "$VAR" ]] || echo match 5 + +line=aab +[[ $line =~ [[:space:]]*(a)?b ]] && echo match 6 + +V="alphabet" +[[ $V == alphabet ]] && echo yes 1 +[[ $V == "alphabet" ]] && echo yes 2 +[[ $V == 'alphabet' ]] && echo yes 3 +[[ $V =~ alphabet ]] && echo yes 4 +[[ $V =~ "alphabet" ]] && echo yes 5 +[[ $V =~ 'alphabet' ]] && echo yes 6 + +DOG="Dog name - 01 - Wiggles" +REPAT='([[:alpha:][:blank:]]*)- ([[:digit:]]*) - (.*)$' +if [[ $DOG =~ ([[:alpha:][:blank:]]*)-\ ([[:digit:]]*)\ -\ (.*)$ ]] +then + echo Dog ${BASH_REMATCH[2]} is ${BASH_REMATCH[3]} +fi +if [[ $DOG =~ $REPAT ]] +then + echo Dog ${BASH_REMATCH[2]} is ${BASH_REMATCH[3]} +fi + +[[ $REPAT =~ "$REPAT" ]] && echo rematch 1 + diff --git a/tests/cond.right b/tests/cond.right index 2e1675497..999de18ed 100644 --- a/tests/cond.right +++ b/tests/cond.right @@ -40,3 +40,18 @@ found 2 libc ok 42 ok 43 +match 1 +match 2 +match 3 +match 4 +match 5 +match 6 +yes 1 +yes 2 +yes 3 +yes 4 +yes 5 +yes 6 +Dog 01 is Wiggles +Dog 01 is Wiggles +rematch 1 diff --git a/tests/cond.tests b/tests/cond.tests index 78d2e7855..5ba18561c 100755 --- a/tests/cond.tests +++ b/tests/cond.tests @@ -175,3 +175,5 @@ echo ${BASH_REMATCH[@]} # bug in all versions up to and including bash-2.05b if [[ "123abc" == *?(a)bc ]]; then echo ok 42; else echo bad 42; fi if [[ "123abc" == *?(a)bc ]]; then echo ok 43; else echo bad 43; fi + +${THIS_SH} ./cond-regexp.sub diff --git a/tests/run-builtins b/tests/run-builtins index 53d963ebf..df5956ccc 100644 --- a/tests/run-builtins +++ b/tests/run-builtins @@ -1,2 +1,5 @@ +echo "warning: some of these tests may fail if process substitution has not" >&2 +echo "warning: been compiled into the shell" >&2 + ${THIS_SH} ./builtins.tests > /tmp/xx 2>&1 diff /tmp/xx builtins.right && rm -f /tmp/xx diff --git a/tests/source6.sub b/tests/source6.sub new file mode 100644 index 000000000..bd03708d0 --- /dev/null +++ b/tests/source6.sub @@ -0,0 +1,29 @@ +# tests sourcing non-regular files, fixed post-3.2 + +: ${TMPDIR:=/tmp} + +rm -f $TMPDIR/foo +echo "echo one - OK" > $TMPDIR/foo +. $TMPDIR/foo +echo $? +rm -f $TMPDIR/foo + +# non-regular readable file +. /dev/null +echo $? + +# FIFO or pipe via /dev/fd +. <(echo "echo two - OK") +echo $? + +# pipe +echo "echo three - OK" | . /dev/stdin +echo $? + +# FIFO +mkfifo $TMPDIR/fifo-$$ +echo "echo four - OK" > $TMPDIR/fifo-$$ & +sleep 1 # allow the child echo to execute +. $TMPDIR/fifo-$$ +echo $? +rm -f $TMPDIR/fifo-$$ -- 2.47.3