diff options
| author | Jari Aalto <jari.aalto@cante.net> | 1996-08-26 18:22:31 +0000 |
|---|---|---|
| committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:49 +0000 |
| commit | 726f63884db0132f01745f1fb4465e6621088ccf (patch) | |
| tree | 6c2f7765a890a97e0e513cb539df43283a8f7c4d /tests | |
| download | android_external_bash-726f63884db0132f01745f1fb4465e6621088ccf.tar.gz android_external_bash-726f63884db0132f01745f1fb4465e6621088ccf.tar.bz2 android_external_bash-726f63884db0132f01745f1fb4465e6621088ccf.zip | |
Imported from ../bash-1.14.7.tar.gz.
Diffstat (limited to 'tests')
62 files changed, 1476 insertions, 0 deletions
diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..a1a081b --- /dev/null +++ b/tests/README @@ -0,0 +1 @@ +Type `sh run-all'. diff --git a/tests/dollar-at.sh b/tests/dollar-at.sh new file mode 100755 index 0000000..c3004d5 --- /dev/null +++ b/tests/dollar-at.sh @@ -0,0 +1 @@ +recho "$@" diff --git a/tests/dollar-star.sh b/tests/dollar-star.sh new file mode 100755 index 0000000..982f04c --- /dev/null +++ b/tests/dollar-star.sh @@ -0,0 +1 @@ +recho "$*" diff --git a/tests/dollar.right b/tests/dollar.right new file mode 100644 index 0000000..4d9b746 --- /dev/null +++ b/tests/dollar.right @@ -0,0 +1,3 @@ +argv[1] = <a b> +argv[1] = <a> +argv[2] = <b> diff --git a/tests/exp-tests b/tests/exp-tests new file mode 100644 index 0000000..d45b702 --- /dev/null +++ b/tests/exp-tests @@ -0,0 +1,326 @@ +# +# A suite of tests for bash word expansions +# +# This tests parameter and variable expansion, with an empahsis on +# proper quoting behavior. +# +# Chet Ramey + +# +# If you comment out the body of this function, you can do a diff against +# `expansion-tests.right' to see if the shell is behaving correctly +# +expect() +{ + echo expect "$@" +} + +# Test the substitution quoting characters (CTLESC and CTLNUL) in different +# combinations + +expect "<^A>" +recho `echo ''` +expect "<^A>" +recho `echo ""` +expect "<^B>" +recho `echo ''` +expect "<^B>" +recho `echo ""` +expect "<^A>" +recho `echo ` +expect "<^B>" +recho `echo ` + +# Test null strings without variable expansion +expect "<abcdefgh>" +recho abcd""efgh +expect "<abcdefgh>" +recho abcd''efgh +expect "<abcdefgh>" +recho ""abcdefgh +expect "<abcdefgh>" +recho ''abcdefgh +expect "<abcd>" +recho abcd"" +expect "<abcd>" +recho abcd'' + +# Test the quirky behavior of $@ in "" +expect nothing +recho "$@" +expect "< >" +recho " $@" +expect "<-->" +recho "-${@}-" + +# Test null strings with variable expansion that fails +expect '<>' +recho $xxx"" +expect '<>' +recho ""$xxx +expect '<>' +recho $xxx'' +expect '<>' +recho ''$xxx +expect '<>' +recho $xxx""$yyy +expect '<>' +recho $xxx''$yyy + +# Test null strings with variable expansion that succeeds +xxx=abc +yyy=def + +expect '<abc>' +recho $xxx"" +expect '<abc>' +recho ""$xxx +expect '<abc>' +recho $xxx'' +expect '<abc>' +recho ''$xxx +expect '<abcdef>' +recho $xxx""$yyy +expect '<abcdef>' +recho $xxx''$yyy + +unset xxx yyy + +# Test the unquoted special quoting characters +expect "<^A>" +recho +expect "<^B>" +recho +expect "<^A>" +recho "" +expect "<^B>" +recho "" +expect "<^A>" +recho '' +expect "<^B>" +recho '' + +# Test expansion of a variable that is unset +expect nothing +recho $xxx +expect '<>' +recho "$xxx" + +expect nothing +recho "$xxx${@}" + +# Test empty string expansion +expect '<>' +recho "" +expect '<>' +recho '' + +# Test command substitution with (disabled) history substitution +expect '<Hello World!>' +# set +H +recho "`echo \"Hello world!\"`" + +# Test some shell special characters +expect '<`>' +recho "\`" +expect '<">' +recho "\"" +expect '<\^A>' +recho "\" + +expect '<\$>' +recho "\\$" + +expect '<\\>' +recho "\\\\" + +# This should give argv[1] = a argv[2] = b +expect '<a> <b>' +FOO=`echo 'a b' | tr ' ' '\012'` +recho $FOO + +# This should give argv[1] = ^A argv[2] = ^B +expect '<^A> <^B>' +FOO=`echo ' ' | tr ' ' '\012'` +recho $FOO + +# Test quoted and unquoted globbing characters +expect '<**>' +recho "*"* + +expect '<\.\./*/>' +recho "\.\./*/" + +# Test patterns that come up when the shell quotes funny character +# combinations +expect '<^A^B^A^B>' +recho '' +expect '<^A^A>' +recho '' +expect '<^A^B>' +recho '' +expect '<^A^A^B>' +recho '' + +# More tests of "$@" +expect '< abc> <def> <ghi> <jkl >' +set abc def ghi jkl +recho " $@ " + +expect '<--abc> <def> <ghi> <jkl-->' +set abc def ghi jkl +recho "--$@--" + +expect '< >' +recho " " +expect '< - >' +recho " - " + +# Test combinations of different types of quoting in a fully-quoted string +# (so the WHOLLY_QUOTED tests fail and it doesn't get set) +expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>' +recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/" + +# Test the various Posix parameter expansions + +expect '<foo bar>' +recho "${x:-$(echo "foo bar")}" +expect '<foo> <bar>' +recho ${x:-$(echo "foo bar")} + +unset X +expect '<abc>' +recho ${X:=abc} +expect '<abc>' +recho $X + +set a b c +expect '<posix>' +recho ${3:+posix} + +POSIX=/usr/posix +expect '<10>' +recho ${#POSIX} + +# remove shortest trailing match +x=file.c +expect '<file.o>' +recho ${x%.c}.o + +# remove longest trailing match +x=posix/src/std +expect '<posix>' +recho ${x%%/*} + +# remove shortest leading pattern +x=$HOME/src/cmd +expect '</src/cmd>' +recho ${x#$HOME} + +# remove longest leading pattern +x=/one/two/three +expect '<three>' +recho ${x##*/} + +# Command substitution and the quirky differences between `` and $() + +expect '<\$x>' +recho '\$x' + +expect '<$x>' +recho `echo '\$x'` + +expect '<\$x>' +recho $(echo '\$x') + +# The difference between $* "$*" and "$@" + +set "abc" "def ghi" "jkl" + +expect '<abc> <def> <ghi> <jkl>' +recho $* + +expect '<abc def ghi jkl>' +recho "$*" + +OIFS="$IFS" +IFS=":$IFS" + +# The special behavior of "$*", using the first character of $IFS as separator +expect '<abc:def ghi:jkl>' +recho "$*" + +IFS="$OIFS" + +expect '<abc> <def ghi> <jkl>' +recho "$@" + +expect '<xxabc> <def ghi> <jklyy>' +recho "xx$@yy" + +expect '<abc> <def ghi> <jklabc> <def ghi> <jkl>' +recho "$@$@" + +foo=abc +bar=def + +expect '<abcdef>' +recho "$foo""$bar" + +unset foo +set $foo bar '' xyz "$foo" abc + +expect '<bar> <> <xyz> <> <abc>' +recho "$@" + +# More tests of quoting and deferred evaluation + +foo=10 x=foo +y='$'$x +expect '<$foo>' +recho $y +eval y='$'$x +expect '<10>' +recho $y + +# case statements + +NL=' +' +x='ab +cd' + +expect '<newline expected>' +case "$x" in +*$NL*) recho "newline expected" ;; +esac + +expect '<got it>' +case \? in +*"?"*) recho "got it" ;; +esac + +expect '<got it>' +case \? in +*\?*) recho "got it" ;; +esac + +set one two three four five +expect '<one> <three> <five>' +recho $1 $3 ${5} $8 ${9} +expect '<5> <5>' +recho $# ${#} + +expect '<42>' +recho $((28 + 14)) +expect '<26>' +recho $[ 13 * 2 ] + +expect '<\>' +recho `echo \\\\` + +expect '<~>' +recho '~' + +expect nothing +recho $! diff --git a/tests/exp.right b/tests/exp.right new file mode 100644 index 0000000..f34e88a --- /dev/null +++ b/tests/exp.right @@ -0,0 +1,113 @@ +argv[1] = <^A> +argv[1] = <^A> +argv[1] = <^B> +argv[1] = <^B> +argv[1] = <^A> +argv[1] = <^B> +argv[1] = <abcdefgh> +argv[1] = <abcdefgh> +argv[1] = <abcdefgh> +argv[1] = <abcdefgh> +argv[1] = <abcd> +argv[1] = <abcd> +argv[1] = < > +argv[1] = <--> +argv[1] = <> +argv[1] = <> +argv[1] = <> +argv[1] = <> +argv[1] = <> +argv[1] = <> +argv[1] = <abc> +argv[1] = <abc> +argv[1] = <abc> +argv[1] = <abc> +argv[1] = <abcdef> +argv[1] = <abcdef> +argv[1] = <^A> +argv[1] = <^B> +argv[1] = <^A> +argv[1] = <^B> +argv[1] = <^A> +argv[1] = <^B> +argv[1] = <> +argv[1] = <> +argv[1] = <> +argv[1] = <Hello world!> +argv[1] = <`> +argv[1] = <"> +argv[1] = <\^A> +argv[1] = <\$> +argv[1] = <\\> +argv[1] = <a> +argv[2] = <b> +argv[1] = <^A> +argv[2] = <^B> +argv[1] = <**> +argv[1] = <\.\./*/> +argv[1] = <^A^B^A^B> +argv[1] = <^A^A> +argv[1] = <^A^B> +argv[1] = <^A^A^B> +argv[1] = < abc> +argv[2] = <def> +argv[3] = <ghi> +argv[4] = <jkl > +argv[1] = <--abc> +argv[2] = <def> +argv[3] = <ghi> +argv[4] = <jkl--> +argv[1] = < > +argv[1] = < - > +argv[1] = </^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/> +argv[1] = <foo bar> +argv[1] = <foo> +argv[2] = <bar> +argv[1] = <abc> +argv[1] = <abc> +argv[1] = <posix> +argv[1] = <10> +argv[1] = <file.o> +argv[1] = <posix> +argv[1] = </src/cmd> +argv[1] = <three> +argv[1] = <\$x> +argv[1] = <$x> +argv[1] = <\$x> +argv[1] = <abc> +argv[2] = <def> +argv[3] = <ghi> +argv[4] = <jkl> +argv[1] = <abc def ghi jkl> +argv[1] = <abc:def ghi:jkl> +argv[1] = <abc> +argv[2] = <def ghi> +argv[3] = <jkl> +argv[1] = <xxabc> +argv[2] = <def ghi> +argv[3] = <jklyy> +argv[1] = <abc> +argv[2] = <def ghi> +argv[3] = <jklabc> +argv[4] = <def ghi> +argv[5] = <jkl> +argv[1] = <abcdef> +argv[1] = <bar> +argv[2] = <> +argv[3] = <xyz> +argv[4] = <> +argv[5] = <abc> +argv[1] = <$foo> +argv[1] = <10> +argv[1] = <newline expected> +argv[1] = <got it> +argv[1] = <got it> +argv[1] = <one> +argv[2] = <three> +argv[3] = <five> +argv[1] = <5> +argv[2] = <5> +argv[1] = <42> +argv[1] = <26> +argv[1] = <\> +argv[1] = <~> diff --git a/tests/glob-test b/tests/glob-test new file mode 100644 index 0000000..e8c1c70 --- /dev/null +++ b/tests/glob-test @@ -0,0 +1,179 @@ +# +# test the shell globbing +# +expect() +{ + echo expect "$@" +} + +TESTDIR=/tmp/glob-test +rm -rf $TESTDIR +mkdir $TESTDIR +builtin cd $TESTDIR + +touch a b c d abc abd abe bb bcd ca cb dd de +mkdir bdir + +# see if `regular' globbing works right +expect '<a> <abc> <abd> <abe> <X*>' +recho a* X* + +expect '<a> <abc> <abd> <abe>' +recho \a* + +# see if null glob expansion works +allow_null_glob_expansion= + +expect '<a> <abc> <abd> <abe>' +recho a* X* + +unset allow_null_glob_expansion + +# see if the code that expands directories only works +expect '<bdir/>' +recho b*/ + +# Test quoted and unquoted globbing characters +expect '<*>' +recho \* + +expect '<a*>' +recho 'a*' + +expect '<a*>' +recho a\* + +expect '<c> <ca> <cb> <a*> <*q*>' +recho c* a\* *q* + +expect '<**>' +recho "*"* + +expect '<**>' +recho \** + +expect '<\.\./*/>' +recho "\.\./*/" + +expect '<s/\..*//>' +recho 's/\..*//' + +# Pattern from Larry Wall's Configure that caused bash to blow up +expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>' +recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/" + +# Make sure character classes work properly + +expect '<abc> <abd> <abe> <bb> <cb>' +recho [a-c]b* + +expect '<abd> <abe> <bb> <bcd> <bdir> <ca> <cb> <dd> <de>' +recho [a-y]*[^c] + +expect '<abd> <abe>' +recho a*[^c] + +touch a-b aXb +expect '<a-b> <aXb>' +recho a[X-]b + +touch .x .y +expect '<d> <dd> <de>' +recho [^a-c]* + +# Make sure that filenames with embedded globbing characters are handled +# properly +mkdir a\*b +> a\*b/ooo + +expect '<a*b/ooo>' +recho a\*b/* + +expect '<a*b/ooo>' +recho a\*?/* + +expect '<no match>' +cmd='echo !7' +case "$cmd" in +*\\!*) echo match ;; +*) echo no match ;; +esac + +expect '<not there>' +file='r.*' +case $file in +*.\*) echo not there ;; +*) echo there ;; +esac + +# examples from the Posix.2 spec (d11.2, p. 243) +expect '<abc>' +recho a[b]c + +expect '<abc>' +recho a["b"]c + +expect '<abc>' +recho a[\b]c + +expect '<abc>' +recho a?c + +expect '<match>' +case abc in +a"b"c) echo match + ;; +*) echo BAD + ;; +esac + +expect '<match>' +case abc in +a*c) echo match + ;; +*) echo BAD + ;; +esac + +expect '<ok>' +case abc in +"a?c") echo bad + ;; +*) echo ok + ;; +esac + +expect '<ok>' +case abc in +a\*c) echo bad + ;; +*) echo ok + ;; +esac + +expect '<ok>' +case abc in +a\[b]c) echo bad + ;; +*) echo ok + ;; +esac + +expect '<ok>' +case "$nosuchvar" in +"") echo ok ;; +*) echo bad ;; +esac + +# This is very odd, but sh and ksh seem to agree +expect '<ok>' +case abc in +a["\b"]c) echo ok + ;; +*) echo bad + ;; +esac + +builtin cd / +rm -rf $TESTDIR +exit 0 diff --git a/tests/glob.right b/tests/glob.right new file mode 100644 index 0000000..4f2acbb --- /dev/null +++ b/tests/glob.right @@ -0,0 +1,63 @@ +argv[1] = <a> +argv[2] = <abc> +argv[3] = <abd> +argv[4] = <abe> +argv[5] = <X*> +argv[1] = <a> +argv[2] = <abc> +argv[3] = <abd> +argv[4] = <abe> +argv[1] = <a> +argv[2] = <abc> +argv[3] = <abd> +argv[4] = <abe> +argv[1] = <bdir/> +argv[1] = <*> +argv[1] = <a*> +argv[1] = <a*> +argv[1] = <c> +argv[2] = <ca> +argv[3] = <cb> +argv[4] = <a*> +argv[5] = <*q*> +argv[1] = <**> +argv[1] = <**> +argv[1] = <\.\./*/> +argv[1] = <s/\..*//> +argv[1] = </^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/> +argv[1] = <abc> +argv[2] = <abd> +argv[3] = <abe> +argv[4] = <bb> +argv[5] = <cb> +argv[1] = <abd> +argv[2] = <abe> +argv[3] = <bb> +argv[4] = <bcd> +argv[5] = <bdir> +argv[6] = <ca> +argv[7] = <cb> +argv[8] = <dd> +argv[9] = <de> +argv[1] = <abd> +argv[2] = <abe> +argv[1] = <a-b> +argv[2] = <aXb> +argv[1] = <d> +argv[2] = <dd> +argv[3] = <de> +argv[1] = <a*b/ooo> +argv[1] = <a*b/ooo> +no match +not there +argv[1] = <abc> +argv[1] = <abc> +argv[1] = <abc> +argv[1] = <abc> +match +match +ok +ok +ok +ok +ok diff --git a/tests/ifs-test-1.sh b/tests/ifs-test-1.sh new file mode 100644 index 0000000..a153ce9 --- /dev/null +++ b/tests/ifs-test-1.sh @@ -0,0 +1,5 @@ +OIFS="$IFS" +IFS=":$IFS" +eval foo="a:b:c" +IFS="$OIFS" +echo $foo diff --git a/tests/ifs-test-2.sh b/tests/ifs-test-2.sh new file mode 100644 index 0000000..3249f1b --- /dev/null +++ b/tests/ifs-test-2.sh @@ -0,0 +1,9 @@ +OIFS=$IFS +IFS=":$IFS" +foo=$(echo a:b:c) +IFS=$OIFS + +for i in $foo +do + echo $i +done diff --git a/tests/ifs-test-3.sh b/tests/ifs-test-3.sh new file mode 100644 index 0000000..4693792 --- /dev/null +++ b/tests/ifs-test-3.sh @@ -0,0 +1,9 @@ +OIFS=$IFS +IFS=":$IFS" +foo=`echo a:b:c` +IFS=$OIFS + +for i in $foo +do + echo $i +done diff --git a/tests/ifs.1.right b/tests/ifs.1.right new file mode 100644 index 0000000..af0abb2 --- /dev/null +++ b/tests/ifs.1.right @@ -0,0 +1 @@ +a:b:c diff --git a/tests/ifs.2.right b/tests/ifs.2.right new file mode 100644 index 0000000..af0abb2 --- /dev/null +++ b/tests/ifs.2.right @@ -0,0 +1 @@ +a:b:c diff --git a/tests/ifs.3.right b/tests/ifs.3.right new file mode 100644 index 0000000..af0abb2 --- /dev/null +++ b/tests/ifs.3.right @@ -0,0 +1 @@ +a:b:c diff --git a/tests/input-line.sh b/tests/input-line.sh new file mode 100644 index 0000000..086d7e3 --- /dev/null +++ b/tests/input-line.sh @@ -0,0 +1,4 @@ +echo before calling input-line.sub +../bash ./input-line.sub +this line for input-line.sub +echo finished with input-line.sub diff --git a/tests/input-line.sub b/tests/input-line.sub new file mode 100644 index 0000000..7bc8df2 --- /dev/null +++ b/tests/input-line.sub @@ -0,0 +1,2 @@ +read line +echo line read by $0 was \`$line\' diff --git a/tests/input.right b/tests/input.right new file mode 100644 index 0000000..8733feb --- /dev/null +++ b/tests/input.right @@ -0,0 +1,3 @@ +before calling input-line.sub +line read by ./input-line.sub was `this line for input-line.sub' +finished with input-line.sub diff --git a/tests/minus-e b/tests/minus-e new file mode 100644 index 0000000..be67ec5 --- /dev/null +++ b/tests/minus-e @@ -0,0 +1,6 @@ +set -e +if set +e +then + false +fi +echo hi diff --git a/tests/minus-e.right b/tests/minus-e.right new file mode 100644 index 0000000..45b983b --- /dev/null +++ b/tests/minus-e.right @@ -0,0 +1 @@ +hi diff --git a/tests/misc/chld-trap.sh b/tests/misc/chld-trap.sh new file mode 100755 index 0000000..89b342d --- /dev/null +++ b/tests/misc/chld-trap.sh @@ -0,0 +1,14 @@ +#! /bin/sh +# +# show that setting a trap on SIGCHLD is not disastrous. +# + +trap 'echo caught a child death' SIGCHLD + +sleep 5 & +sleep 5 & +sleep 5 & + +wait + +exit 0 diff --git a/tests/misc/dot-test-1.sh b/tests/misc/dot-test-1.sh new file mode 100644 index 0000000..eab465e --- /dev/null +++ b/tests/misc/dot-test-1.sh @@ -0,0 +1,3 @@ +echo this is $0 +. ./dot-test-1.sub +echo after . dot-test-1.sub diff --git a/tests/misc/dot-test-1.sub b/tests/misc/dot-test-1.sub new file mode 100644 index 0000000..58df5f4 --- /dev/null +++ b/tests/misc/dot-test-1.sub @@ -0,0 +1 @@ +echo this is dot-test-1.sub diff --git a/tests/misc/gotest b/tests/misc/gotest new file mode 100644 index 0000000..df0a342 --- /dev/null +++ b/tests/misc/gotest @@ -0,0 +1,26 @@ +aflag= +bflag= + +while getopts ab: name +do + case $name in + a) aflag=1 ;; + b) bflag=1 + bval=$OPTARG;; + ?) echo Usage: $0 [-a] [-b value] args + exit 2;; + esac + +done + +if [ ! -z "$aflag" ] ; then echo -a specified ; fi +if [ ! -z "$bflag" ] ; then echo -b $bval specified ; fi + +if [ "$OPTIND" -gt 1 ] +then + shift $(( $OPTIND - 1 )) +fi + +echo remaining args: "$*" + +exit 0 diff --git a/tests/misc/perf-script b/tests/misc/perf-script new file mode 100644 index 0000000..e1172a9 --- /dev/null +++ b/tests/misc/perf-script @@ -0,0 +1,81 @@ +#!/bin/bash + +typeset -i m2 m1 M n2 n1 N m n +typeset -i MM=5 NN=5 + +case $# in + 0) : + ;; + 1) MM=$1; NN=$1 + ;; + 2) MM=$1; NN=$2 + ;; + *) echo 1>&2 "Usage: $0 [m [n]]" + ;; +esac + +EMPTYLINE=: # echo +echo 'a = { ' # mathematica + +let "M=1" # for (M=1; M<=MM; M++) +while let "M <= MM"; do + let "N=1" # for (N=1; N<=NN; N++) + while let "N <= NN"; do + + let "m1 = M - 1" + let "m2 = M + 1" + let "n1 = N - 1" + let "n2 = N + 1" + + + echo -n '{ ' # math + let "m=1" # for(m=1; m<=MM; m++) + while let "m <= MM"; do + let "n=1" # for(n=1; n<=NN; n++) + while let "n <= NN"; do + + let "x = (m-m1)*(m-M)*(m-m2)" + let "y = (n-n1)*(n-N)*(n-n2)" + + if let "(x*x + (n-N)*(n-N)) * ((m-M)*(m-M) + y*y)"; then + echo -n "0," + else # neighbour + echo -n "1," + fi + + let "n=n+1" + done + echo -n " "; let "m=m+1" # ". " + done + echo '},' + + + let "N=N+1" + $EMPTYLINE + done + $EMPTYLINE + let "M=M+1" +done + +echo '}' + + + +echo -n 'o = { ' +let "m=1" +while let "m <= MM"; do + let "n=1" + while let "n <= NN"; do + echo -n "1," + let "n=n+1" + done + let "m=m+1" +done +echo " }" + + +echo 'x = LinearSolve[a,o] ' + +exit 0 + + diff --git a/tests/misc/redir.t1.sh b/tests/misc/redir.t1.sh new file mode 100644 index 0000000..0ea00f9 --- /dev/null +++ b/tests/misc/redir.t1.sh @@ -0,0 +1,26 @@ +read line1 + +echo read line1 \"$line1\" + +exec 4</etc/passwd + +exec 5<&0 +exec 0<&4 + +read line2 + +echo read line2 \"$line2\" + +exec 0<&5 + +read line3 + +echo read line3 \"$line3\" + +exec 0<&4 + +read line4 + +echo read line4 \"$line4\" + +exec 4<&- diff --git a/tests/misc/redir.t2.sh b/tests/misc/redir.t2.sh new file mode 100644 index 0000000..44b2624 --- /dev/null +++ b/tests/misc/redir.t2.sh @@ -0,0 +1,17 @@ +read line1 + +echo read line 1 \"$line1\" + +exec 4<&0 + +exec 0</dev/tty + +read line2 + +echo line read from tty = \"$line2\" + +exec 0<&4 + +read line3 + +echo read line 3 \"$line3\" diff --git a/tests/misc/redir.t3.sh b/tests/misc/redir.t3.sh new file mode 100755 index 0000000..9fd42c7 --- /dev/null +++ b/tests/misc/redir.t3.sh @@ -0,0 +1,8 @@ +# +# Test the effect of input buffering on the shell's input +# +echo this is redir.t3.sh + +exec 0< redir.t3.sub + +echo after exec in redir.t3.sh diff --git a/tests/misc/redir.t3.sub b/tests/misc/redir.t3.sub new file mode 100644 index 0000000..b32fbaa --- /dev/null +++ b/tests/misc/redir.t3.sub @@ -0,0 +1 @@ +echo this is redir-test-3.sub diff --git a/tests/misc/redir.t4.sh b/tests/misc/redir.t4.sh new file mode 100644 index 0000000..861acdd --- /dev/null +++ b/tests/misc/redir.t4.sh @@ -0,0 +1,12 @@ +echo "Point 1" +exec 3</etc/passwd +exec 4>a +exec 5>b +echo "Point 2" +echo to a 1>&4 +echo to b 1>&5 +exec 11</etc/printcap +echo "Point 3" +echo to a 1>&4 +echo to b 1>&5 +exit 0 diff --git a/tests/misc/run.r1.sh b/tests/misc/run.r1.sh new file mode 100755 index 0000000..bf22fe3 --- /dev/null +++ b/tests/misc/run.r1.sh @@ -0,0 +1 @@ +../../bash redir.t1.sh diff --git a/tests/misc/run.r2.sh b/tests/misc/run.r2.sh new file mode 100755 index 0000000..3b24701 --- /dev/null +++ b/tests/misc/run.r2.sh @@ -0,0 +1 @@ +../../bash ./redir.t2.sh < /etc/passwd diff --git a/tests/misc/run.r3.sh b/tests/misc/run.r3.sh new file mode 100755 index 0000000..b413674 --- /dev/null +++ b/tests/misc/run.r3.sh @@ -0,0 +1,3 @@ +# +# the `after exec in ...' should not be echoed +../../bash < redir.t3.sh diff --git a/tests/misc/sigint.t1.sh b/tests/misc/sigint.t1.sh new file mode 100755 index 0000000..7b74c30 --- /dev/null +++ b/tests/misc/sigint.t1.sh @@ -0,0 +1,9 @@ +echo before trap +trap 'echo caught sigint' 2 +echo after trap + +for i in 1 2 3 +do + echo $i + sleep 5 +done diff --git a/tests/misc/sigint.t2.sh b/tests/misc/sigint.t2.sh new file mode 100755 index 0000000..69eaf56 --- /dev/null +++ b/tests/misc/sigint.t2.sh @@ -0,0 +1,7 @@ +echo before loop + +for i in 1 2 3 +do + echo $i + sleep 5 +done diff --git a/tests/misc/sigint.t3.sh b/tests/misc/sigint.t3.sh new file mode 100755 index 0000000..2627fe6 --- /dev/null +++ b/tests/misc/sigint.t3.sh @@ -0,0 +1,11 @@ +sleep 5 & +sleep 5 & +sleep 5 & + +echo wait 1 +wait + +echo wait 2 +wait + +exit diff --git a/tests/misc/sigint.t4.sh b/tests/misc/sigint.t4.sh new file mode 100755 index 0000000..587dd26 --- /dev/null +++ b/tests/misc/sigint.t4.sh @@ -0,0 +1,13 @@ +trap 'echo sigint' 2 + +sleep 5 & +sleep 5 & +sleep 5 & + +echo wait 1 +wait + +echo wait 2 +wait + +exit diff --git a/tests/misc/test-minus-e.1 b/tests/misc/test-minus-e.1 new file mode 100644 index 0000000..03d7ecf --- /dev/null +++ b/tests/misc/test-minus-e.1 @@ -0,0 +1,12 @@ +touch .file +while set -e ; test -r .file ; do + echo -n "stop loop? " + read reply + case "$reply" in + y*) rm .file non-dash-file ;; + esac + set +e +done + + + diff --git a/tests/misc/test-minus-e.2 b/tests/misc/test-minus-e.2 new file mode 100644 index 0000000..ad6a0c8 --- /dev/null +++ b/tests/misc/test-minus-e.2 @@ -0,0 +1,14 @@ +touch .file +set -e +while set +e ; test -r .file ; do + echo -n "stop loop? [yes to quit] " + read reply + if [ "$reply" = yes ] ; then + rm .file non-dash-file + fi + set -e +done +rm -f .file + + + diff --git a/tests/new-exp.right b/tests/new-exp.right new file mode 100644 index 0000000..07e2e9c --- /dev/null +++ b/tests/new-exp.right @@ -0,0 +1,33 @@ +argv[1] = <foo bar> +argv[1] = <foo> +argv[1] = </usr/homes/chet> +argv[1] = </usr/homes/chet> +argv[1] = </usr/homes/chet> +./new-exp.tests: ${HOME:`echo }`}: bad substitution +./new-exp.tests: ${_ENV[(_$-=0)+(_=1)-_${-%%*i*}]}: bad substitution +argv[1] = </usr/homes/chet> +argv[1] = </usr/homes/chet> +argv[1] = </usr/homes/chet> +argv[1] = </usr/homes/chet> +argv[1] = </usr/homes/chet> +argv[1] = </usr/homes/chet> +argv[1] = </usr/homes/chet> +argv[1] = <*@> +argv[1] = <@*> +argv[1] = <)> +argv[1] = <")"> +argv[1] = <-abcd> +argv[2] = <-> +argv[1] = <-abcd> +argv[2] = <-> +argv[1] = <-abcd-> +argv[1] = <a b c d e> +bar foo +bar foo +bar foo +bar foo +bar foo +./new-exp.tests: ABX: unbound variable +./new-exp.tests: $6: cannot assign in this way + +./new-exp.tests: ABXD: parameter unset diff --git a/tests/new-exp.tests b/tests/new-exp.tests new file mode 100644 index 0000000..f19ecf6 --- /dev/null +++ b/tests/new-exp.tests @@ -0,0 +1,95 @@ +expect() +{ + echo expect "$@" +} + +HOME=/usr/homes/chet # to make the check against new-exp.right work +expect '<foo bar>' +recho "${undef-"foo bar"}" # should be foo bar +expect '<foo>' +recho "${und="foo"}" # should be foo + +expect "<$HOME>" +recho ${HOME-"}"} +expect "<$HOME>" +recho "${HOME-'}'}" +expect "<$HOME>" +recho "${HOME-"}"}" + +expect $0: '${HOME:`echo }`}: bad substitution' +recho "${HOME:`echo }`}" # should be an error -- bad substitution + +expect $0: '${_ENV[(_$-=0)+(_=1)-_${-%%*i*}]}: bad substitution' +x=${_ENV[(_$-=0)+(_=1)-_${-%%*i*}]} # memory leak + +expect "<$HOME>" +recho ${HOME} +expect "<$HOME>" +recho ${HOME:-`echo }`} +expect "<$HOME>" +recho ${HOME:-`echo "}"`} +expect "<$HOME>" +recho "${HOME:-`echo "}"`}" +expect "<$HOME>" +recho "$(echo "${HOME}")" +expect "<$HOME>" +recho "$(echo "$(echo ${HOME})")" +expect "<$HOME>" +recho "$(echo "$(echo "${HOME}")")" + +P=*@* +expect '<*@>' +recho "${P%"*"}" # should be *@ +expect '<@*>' +recho "${P#\*}" # should be @* + +expect '<)>' +recho "$(echo ")")" # should be ) +expect '<")">' +recho "$(echo "\")\"")" # should be ")" + +foo='abcd ' +expect '<-abcd> <->' +recho -${foo}- # should be -abcd - +expect '<-abcd> <->' +recho -${foo% *}- # should be -abcd - +expect '<-abcd->' +recho -${foo%% *}- # should be -abcd- + +set a b c d e +expect '<a b c d e>' +IFS="" +recho "$@" +IFS=' +' + +foo=bar +expect '<bar foo>' +echo -n $foo' ' ; echo foo + +expect '<bar foo>' +echo -n $foo" " ; echo foo + +expect '<bar foo>' +echo -n "$foo " ; echo foo + +expect '<bar foo>' +echo -e "$foo\c " ; echo foo + +expect '<bar foo>' +echo -e $foo"\c " ; echo foo + +set -u +expect $0: ABX: unbound variable +recho ${ABX} +set +u + +expect $0: '$6: cannot assign in this way' +recho ${6="arg6"} + +expect a newline +echo $abmcde + +# this must be last! +expect $0: 'ABXD: parameter unset' +recho ${ABXD:?"parameter unset"} diff --git a/tests/prec.right b/tests/prec.right new file mode 100644 index 0000000..e6af552 --- /dev/null +++ b/tests/prec.right @@ -0,0 +1,28 @@ +`Say' echos its argument. Its return value is of no interest. +`Truth' echos its argument and returns a TRUE result. +`False' echos its argument and returns a FALSE result. + + Truth 1 && Truth 2 || Say 3 output=12 +( Truth 1 && Truth 2 ) || Say 3 output=12 + + Truth 1 && False 2 || Say 3 output=123 +( Truth 1 && False 2 ) || Say 3 output=123 + + False 1 && Truth 2 || Say 3 output=13 +( False 1 && Truth 2 ) || Say 3 output=13 + + False 1 && False 2 || Say 3 output=13 +( False 1 && False 2 ) || Say 3 output=13 + +Truth 1 || Truth 2 && Say 3 output=13 +Truth 1 || ( Truth 2 && Say 3 ) output=1 + +Truth 1 || False 2 && Say 3 output=13 +Truth 1 || ( False 2 && Say 3 ) output=1 + +False 1 || Truth 2 && Say 3 output=123 +False 1 || ( Truth 2 && Say 3 ) output=123 + +False 1 || False 2 && Say 3 output=12 +False 1 || ( False 2 && Say 3 ) output=12 + diff --git a/tests/precedence b/tests/precedence new file mode 100755 index 0000000..9bbdb97 --- /dev/null +++ b/tests/precedence @@ -0,0 +1,75 @@ +# @(#)precedence_test 1.0 91/07/24 Maarten Litmaath +# test of relative precedences for `&&' and `||' operators + +echo "\`Say' echos its argument. Its return value is of no interest." +case `echo -n` in + '') Say () { echo -n "$*" ; } ;; + *) Say () { echo "$*\c" ; } ;; +esac + +echo "\`Truth' echos its argument and returns a TRUE result." +Truth () { + Say $1; + return 0; +} + +echo "\`False' echos its argument and returns a FALSE result." +False () { + Say $1; + return 1; +} + +echo "" + +cmd1='$open $test1 && $test2 $close || $test3' +cmd2='$test1 || $open $test2 && $test3 $close' + +grouping_sh= +grouping_C='( )' + +test3='Say 3' + +for i in 1 2 +do + eval proto=\$cmd$i + + for test1 in 'Truth 1' 'False 1' + do + for test2 in 'Truth 2' 'False 2' + do + for precedence in sh C + do + eval set x \$grouping_$precedence + shift + open=${1-' '} + close=${2-' '} + eval cmd=\""$proto"\" + Say "$cmd output=" + output=`eval "$cmd"` + Say "$output" + read correct || { echo 'Input fubar. Abort.' >&2; exit 1; } + test "X$output" = "X$correct" || echo " correct=$correct" + echo '' + done + + echo '' + done + done +done << EOF +12 +12 +123 +123 +13 +13 +13 +13 +13 +1 +13 +1 +123 +123 +12 +12 +EOF diff --git a/tests/run-all b/tests/run-all new file mode 100755 index 0000000..7add688 --- /dev/null +++ b/tests/run-all @@ -0,0 +1,17 @@ +#! /bin/sh + +PATH=.:$PATH # just to get the right version of printenv +export PATH +unset ENV + +echo Any output from any test indicates an anomaly worth investigating +for x in run-* +do + case $x in + $0) ;; + *.orig|*~) ;; + *) echo $x ; sh $x ;; + esac +done + +exit 0 diff --git a/tests/run-dollars b/tests/run-dollars new file mode 100755 index 0000000..00ad7f1 --- /dev/null +++ b/tests/run-dollars @@ -0,0 +1,3 @@ +../bash ./dollar-star.sh a b > x 2>&1 +../bash ./dollar-at.sh a b >>x 2>&1 +diff x dollar.right && rm -f x diff --git a/tests/run-exp-tests b/tests/run-exp-tests new file mode 100755 index 0000000..b95f603 --- /dev/null +++ b/tests/run-exp-tests @@ -0,0 +1,2 @@ +../bash ./exp-tests | grep -v '^expect' > xx +diff xx exp.right && rm -f xx diff --git a/tests/run-glob-test b/tests/run-glob-test new file mode 100755 index 0000000..1e598dc --- /dev/null +++ b/tests/run-glob-test @@ -0,0 +1,4 @@ +PATH=$PATH:`pwd` +export PATH +../bash ./glob-test | grep -v '^expect' > xx +diff xx glob.right && rm -f xx diff --git a/tests/run-ifs-tests b/tests/run-ifs-tests new file mode 100755 index 0000000..1f9c8c0 --- /dev/null +++ b/tests/run-ifs-tests @@ -0,0 +1,13 @@ +# +# show that IFS is only applied to the result of expansions +# +../bash ifs-test-1.sh > xx +diff xx ./ifs.1.right + +../bash ifs-test-2.sh > xx +diff xx ./ifs.2.right + +../bash ifs-test-3.sh > xx +diff xx ./ifs.3.right + +rm -f xx diff --git a/tests/run-input-test b/tests/run-input-test new file mode 100755 index 0000000..25d63a0 --- /dev/null +++ b/tests/run-input-test @@ -0,0 +1,2 @@ +../bash < ./input-line.sh > xx +diff xx input.right && rm -f xx diff --git a/tests/run-minus-e b/tests/run-minus-e new file mode 100755 index 0000000..51d3229 --- /dev/null +++ b/tests/run-minus-e @@ -0,0 +1,2 @@ +../bash ./minus-e > xx +diff xx minus-e.right && rm -f xx diff --git a/tests/run-new-exp b/tests/run-new-exp new file mode 100755 index 0000000..ef57d32 --- /dev/null +++ b/tests/run-new-exp @@ -0,0 +1,2 @@ +../bash ./new-exp.tests 2>&1 | grep -v '^expect' > xx +diff xx new-exp.right && rm -f xx diff --git a/tests/run-precedence b/tests/run-precedence new file mode 100755 index 0000000..9303e87 --- /dev/null +++ b/tests/run-precedence @@ -0,0 +1,2 @@ +../bash ./precedence > xx +diff xx prec.right && rm -f xx diff --git a/tests/run-set-e-test b/tests/run-set-e-test new file mode 100755 index 0000000..1afef16 --- /dev/null +++ b/tests/run-set-e-test @@ -0,0 +1,2 @@ +../bash ./set-e-test > xx +diff xx set-e.right && rm -f xx diff --git a/tests/run-strip b/tests/run-strip new file mode 100755 index 0000000..8c97f6f --- /dev/null +++ b/tests/run-strip @@ -0,0 +1,2 @@ +../bash ./strip.tests > xx +diff xx strip.right && rm -f xx diff --git a/tests/run-varenv b/tests/run-varenv new file mode 100755 index 0000000..04aece9 --- /dev/null +++ b/tests/run-varenv @@ -0,0 +1,2 @@ +../bash ./varenv.sh | grep -v '^expect' > xx +diff xx varenv.right && rm -f xx diff --git a/tests/set-e-test b/tests/set-e-test new file mode 100644 index 0000000..ce3feb0 --- /dev/null +++ b/tests/set-e-test @@ -0,0 +1,16 @@ +if : ; then + set -e + N=95 + while :; do + # expr returns 1 if expression is null or 0 + set +e + N_MOD_100=`expr $N % 100` + set -e + echo $N_MOD_100 + N=`expr $N + 1` + if [ $N -eq 110 ]; then + break + fi + done + set +e +fi diff --git a/tests/set-e.right b/tests/set-e.right new file mode 100644 index 0000000..92cb7af --- /dev/null +++ b/tests/set-e.right @@ -0,0 +1,15 @@ +95 +96 +97 +98 +99 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/tests/strip.right b/tests/strip.right new file mode 100644 index 0000000..dfab897 --- /dev/null +++ b/tests/strip.right @@ -0,0 +1,12 @@ +'' +' ab ' +' ' +'' +'' +'' +'ababababababab' +'ababababababab ' +'ababababababab ' +'abababa +bababab ' +'' diff --git a/tests/strip.tests b/tests/strip.tests new file mode 100644 index 0000000..b669b52 --- /dev/null +++ b/tests/strip.tests @@ -0,0 +1,22 @@ +v=`echo "" ; echo "" ; echo ""` +echo "'$v'" +v=`echo -n " ab "` +echo "'$v'" +v=`echo -n " "` +echo "'$v'" +v=`echo -n ""` +echo "'$v'" +v=`echo ""` +echo "'$v'" +v=`echo` +echo "'$v'" +v=`echo ababababababab` +echo "'$v'" +v=`echo "ababababababab "` +echo "'$v'" +v=`echo -n "ababababababab "` +echo "'$v'" +v=`echo -ne "abababa\nbababab "` +echo "'$v'" +v="`echo -e '\n\n\n\n'`" +echo "'$v'" diff --git a/tests/tilde-tests b/tests/tilde-tests new file mode 100644 index 0000000..a510751 --- /dev/null +++ b/tests/tilde-tests @@ -0,0 +1,16 @@ +HOME=/usr/xyz +set -v +echo ~chet +echo ~ch\et +echo ~chet/"foo" +echo "~chet"/"foo" +echo \~chet/"foo" +echo \~chet/bar +echo ~\chet/bar +echo ~chet""/bar +echo ":~chet/" +echo abcd~chet +echo "SHELL=~/bash" +echo SHELL=~/bash +echo abcd:~chet +echo PATH=/usr/ucb:/bin:~/bin:~/tmp/bin:/usr/bin diff --git a/tests/tilde.right b/tests/tilde.right new file mode 100644 index 0000000..2920187 --- /dev/null +++ b/tests/tilde.right @@ -0,0 +1,14 @@ +/usr/homes/chet +~chet +/usr/homes/chet/foo +~chet/foo +~chet/foo +~chet/bar +~chet/bar +~chet/bar +:~chet/ +abcd~chet +SHELL=~/bash +SHELL=/usr/xyz/bash +abcd:~chet +PATH=/usr/ucb:/bin:~/bin:~/tmp/bin:/usr/bin diff --git a/tests/varenv.right b/tests/varenv.right new file mode 100644 index 0000000..74ce5d3 --- /dev/null +++ b/tests/varenv.right @@ -0,0 +1,14 @@ +3 4 +5 6 7 8 9 +7 8 9 +/usr/chet +/usr/chet +/usr/chet +/a/b/c +/usr/chet +/usr/chet 7 +/a/b/c 9 /a/b/c +/a/b/c 9 /a/b/c +/a/b/c /a/b/c +1 2 +1 1 diff --git a/tests/varenv.sh b/tests/varenv.sh new file mode 100644 index 0000000..d6bd4e5 --- /dev/null +++ b/tests/varenv.sh @@ -0,0 +1,94 @@ +# +# varenv.sh +# +# Test the behavior of the shell with respect to variable and environment +# assignments +# +expect() +{ + echo expect "$@" +} + +a=1 +b=2 +c=3 +d=4 +e=5 +f=6 g=7 h=8 + +a=3 b=4 $CHMOD $MODE $FN + +# This should echo "3 4" according to Posix.2 +expect "3 4" +echo $a $b + +set -k + +# Assignment statements made when no words are left affect the shell's +# environment +a=5 b=6 $CHMOD c=7 $MODE d=8 $FN e=9 + +expect "5 6 7 8 9" +echo $a $b $c $d $e + +$CHMOD f=7 $MODE g=8 $FN h=9 +expect "7 8 9" +echo $f $g $h + +set +k + +# The temporary environment does not affect variable expansion, only the +# environment given to the command + +export HOME=/usr/chet +expect $HOME +echo $HOME + +expect $HOME +HOME=/a/b/c /bin/echo $HOME + +expect $HOME +echo $HOME + +# This should echo /a/b/c +expect /a/b/c +HOME=/a/b/c printenv HOME + +set -k + +# This should echo $HOME 9, NOT /a/b/c 9 + +expect "$HOME" +HOME=/a/b/c /bin/echo $HOME c=9 +expect "$HOME 7" +echo $HOME $c + +# I claim the next two echo calls should give identical output. +# ksh agrees, the System V.3 sh does not + +expect "/a/b/c 9 /a/b/c" +HOME=/a/b/c $ECHO a=$HOME c=9 +echo $HOME $c $a + +expect "/a/b/c 9 /a/b/c" +HOME=/a/b/c a=$HOME c=9 +echo $HOME $c $a +set +k + +# How do assignment statements affect subsequent assignments on the same +# line? +expect "/a/b/c /a/b/c" +HOME=/a/b/c a=$HOME +echo $HOME $a + +# The system V.3 sh does this wrong; the last echo should output "1 1", +# but the system V.3 sh has it output "2 2". Posix.2 says the assignment +# statements are processed left-to-right. bash and ksh output the right +# thing +c=1 +d=2 +expect "1 2" +echo $c $d +d=$c c=$d +expect "1 1" +echo $c $d |
