summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>1999-02-19 17:11:39 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:52 +0000
commitb72432fdcc59300c6fe7c9d6c8a31ad3447933f5 (patch)
treeb9899162338c2ff3fd83a8aef8831cb119e85cd7 /tests
parentbc4cd23ce958feda898c618215f94d8a4e8f4ffa (diff)
downloadbash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.tar.gz
Imported from ../bash-2.03.tar.gz.
Diffstat (limited to 'tests')
-rw-r--r--tests/cprint.right72
-rw-r--r--tests/cprint.tests67
-rw-r--r--tests/extglob.right19
-rw-r--r--tests/extglob.tests69
-rw-r--r--tests/more-exp.right10
-rw-r--r--tests/more-exp.tests26
-rw-r--r--tests/printf.rightbin1179 -> 1182 bytes
-rw-r--r--tests/printf.tests5
-rw-r--r--tests/run-cprint2
-rw-r--r--tests/run-printf5
-rw-r--r--tests/shopt.right3
-rw-r--r--tests/test.right34
-rw-r--r--tests/type.right2
13 files changed, 294 insertions, 20 deletions
diff --git a/tests/cprint.right b/tests/cprint.right
new file mode 100644
index 00000000..6b711b8c
--- /dev/null
+++ b/tests/cprint.right
@@ -0,0 +1,72 @@
+tf is a function
+tf ()
+{
+ echo this is ${0##*/} >/dev/null;
+ echo a | cat - >/dev/null;
+ test -f ${0##*/} && echo ${0##*/} is a regular file;
+ test -d ${0##*/} || echo ${0##*/} is not a directory;
+ echo a;
+ echo b;
+ echo c;
+ echo background >/dev/null & ( exit 1 );
+ echo $?;
+ {
+ echo a
+ };
+ i=0;
+ while (( " i < 3 " )); do
+ test -r /dev/fd/$i;
+ i=$(( i + 1 ));
+ done;
+ [[ -r /dev/fd/0 && -w /dev/fd/1 ]] || echo oops >/dev/null;
+ for name in $( echo 1 2 3 );
+ do
+ test -r /dev/fd/$name;
+ done;
+ if [[ -r /dev/fd/0 && -w /dev/fd/1 ]]; then
+ echo ok >/dev/null;
+ else
+ if (( " 7 > 40 " )); then
+ echo oops;
+ else
+ echo done;
+ fi;
+ fi >/dev/null;
+ case $PATH in
+ *$PWD*)
+ echo \$PWD in \$PATH
+ ;;
+ *)
+ echo \$PWD not in \$PATH
+ ;;
+ esac >/dev/null;
+ while false; do
+ echo z;
+ done >/dev/null;
+ until true; do
+ echo z;
+ done >/dev/null;
+ echo \&\|'()' \{ echo abcde \; \};
+ eval fu\%nc'()' \{ echo abcde \; \};
+ type fu\%nc
+}
+tf2 is a function
+tf2 ()
+{
+ ( {
+ time -p echo a | cat - >/dev/null
+ } ) 2>&1
+}
+cprint.tests is a regular file
+cprint.tests is not a directory
+a
+b
+c
+1
+a
+&|() { echo abcde ; }
+fu%nc is a function
+fu%nc ()
+{
+ echo abcde
+}
diff --git a/tests/cprint.tests b/tests/cprint.tests
new file mode 100644
index 00000000..08ff1ebc
--- /dev/null
+++ b/tests/cprint.tests
@@ -0,0 +1,67 @@
+#
+# a nonsense script and shell function to test out the command printing code
+#
+tf()
+{
+ # simple command with redir
+ echo this is ${0##*/} > /dev/null
+
+ # pipeline
+ echo a | cat - > /dev/null
+
+ test -f ${0##*/} && echo ${0##*/} is a regular file
+ test -d ${0##*/} || echo ${0##*/} is not a directory
+
+ echo a ; echo b ; echo c
+
+ echo background >/dev/null &
+
+ ( exit 1 )
+ echo $?
+
+ { echo a ; }
+
+ i=0
+ while (( i < 3 )); do
+ test -r /dev/fd/$i
+ i=$(( i + 1 ))
+ done
+
+ [[ -r /dev/fd/0 && -w /dev/fd/1 ]] || echo oops > /dev/null
+
+ for name in $( echo 1 2 3 ); do
+ test -r /dev/fd/$name
+ done
+
+ if [[ -r /dev/fd/0 && -w /dev/fd/1 ]] ; then
+ echo ok > /dev/null
+ elif (( 7 > 40 )) ; then
+ echo oops
+ else
+ echo done
+ fi > /dev/null
+
+ case $PATH in
+ *$PWD*) echo \$PWD in \$PATH ;;
+ *) echo \$PWD not in \$PATH ;;
+ esac > /dev/null
+
+ while false; do echo z; done > /dev/null
+
+ until true; do echo z ; done > /dev/null
+
+ echo \&\|'()' \{ echo abcde \; \}
+ # when not in POSIX mode, we can have weirdly-named functions
+ eval fu\%nc'()' \{ echo abcde \; \}
+ type fu\%nc
+}
+
+tf2()
+{
+ ( { time -p echo a | cat - > /dev/null ; } ) 2>&1
+}
+
+type tf
+type tf2
+
+tf
diff --git a/tests/extglob.right b/tests/extglob.right
index 190f5ad2..c205a4f1 100644
--- a/tests/extglob.right
+++ b/tests/extglob.right
@@ -57,3 +57,22 @@ yes
5: ef
6: ef
7: abcdef
+ab abef
+abcfef abef
+abcdef
+ab abcdef abcfef abef
+abcdef abcfef abef
+ok 37
+ok 38
+ok 39
+ok 40
+ok 41
+a b a,b a-b a.b a:b a;b a_b
+a b a,b a-b a.b a:b a;b a_b
+a b a,b a-b a.b a:b a;b a_b
+a b a,b a-b a.b a:b a;b a_b
+a.b
+a b a,b a-b a:b a;b a_b
+a b a,b a-b a.b a:b a;b a_b
+a b a,b a-b a.b a:b a;b a_b
+a b a,b a-b a.b a:b a;b a_b
diff --git a/tests/extglob.tests b/tests/extglob.tests
index 4747eb5c..a815bab3 100644
--- a/tests/extglob.tests
+++ b/tests/extglob.tests
@@ -274,7 +274,74 @@ echo 6: "${x#*(a|b)cd}"
expect '7: abcdef'
echo 7: ${x#"*(a|b)cd"}
-# clean up and exit
+# More tests derived from a bug report concerning extended glob patterns
+# following a *
+builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
+rm -rf *
+
+touch ab abcdef abef abcfef
+
+expect 'ab abef'
+echo ab*(e|f)
+
+expect 'abcfef abef'
+echo ab?*(e|f)
+
+expect abcdef
+echo ab*d+(e|f)
+
+expect 'ab abcdef abcfef abef'
+echo ab**(e|f)
+
+expect 'abcdef abcfef abef'
+echo ab*+(e|f)
+
+case 'abcfefg' in
+ab**(e|f)) echo ok 37;;
+*) echo bad 37;;
+esac
+
+case 'abcfefg' in
+ab**(e|f)g) echo ok 38;;
+*a) echo bad 38;;
+esac
+
+case ab in
+ab*+(e|f)) echo bad 39;;
+*) echo ok 39;;
+esac
+
+case abef in
+ab***ef) echo ok 40;;
+*) echo bad 40;;
+esac
+
+case abef in
+ab**) echo ok 41;;
+*) echo bad 41;;
+esac
+
+# clean up and do the next one
+
+builtin cd /
+rm -rf $TESTDIR
+
+mkdir $TESTDIR
+builtin cd $TESTDIR
+
+touch a.b a,b a:b a-b a\;b a\ b a_b
+
+echo a[^[:alnum:]]b
+echo a[-.,:\;\ _]b
+
+echo a@([^[:alnum:]])b
+echo a@([-.,:; _])b
+echo a@([.])b
+echo a@([^.])b
+echo a@([^x])b
+echo a+([^[:alnum:]])b
+
+echo a@(.|[^[:alnum:]])b
builtin cd /
rm -rf $TESTDIR
diff --git a/tests/more-exp.right b/tests/more-exp.right
index 63e44dfc..e57ce2ad 100644
--- a/tests/more-exp.right
+++ b/tests/more-exp.right
@@ -192,3 +192,13 @@ argv[1] = <0>
./more-exp.tests: ${#1xyz}: bad substitution
./more-exp.tests: #: %: syntax error: operand expected (error token is "%")
argv[1] = <0>
+argv[1] = <a+b>
+argv[1] = <+>
+argv[1] = <+>
+argv[1] = <+>
+argv[1] = <G { I >
+argv[2] = <K>
+argv[3] = <}>
+argv[1] = <hi>
+argv[2] = <K>
+argv[3] = <}>
diff --git a/tests/more-exp.tests b/tests/more-exp.tests
index d01d9686..d3f4b6f2 100644
--- a/tests/more-exp.tests
+++ b/tests/more-exp.tests
@@ -434,3 +434,29 @@ recho ${#:%}
expect '<0>'
recho ${#:-}
+
+set --
+unset a b
+
+x=a
+y=b
+
+IFS=+
+
+expect '<a+b>'
+recho $x+$y
+expect '<+>'
+recho $a+$b
+
+expect '<+>'
+recho + "$@"
+expect '<+>'
+recho +"$@"
+
+expect '<G { I>' '<K>' '<}>'
+recho ${gik:-G { I } K }
+
+abc=hi
+
+expect '<hi>' '<K>' '<}>'
+recho ${abc:-G { I } K }
diff --git a/tests/printf.right b/tests/printf.right
index 0e6ab14c..ac1bce45 100644
--- a/tests/printf.right
+++ b/tests/printf.right
Binary files differ
diff --git a/tests/printf.tests b/tests/printf.tests
index d21eb4e7..9b47d9e8 100644
--- a/tests/printf.tests
+++ b/tests/printf.tests
@@ -83,6 +83,11 @@ printf -- "--%b--\n"
# of the format string
printf -- "--%b--\n" '4.2\c5.4\n'; printf "\n"
+# make sure extra arguments are ignored if the format string doesn't
+# actually use them
+printf "\n" 4.4 BSD
+printf " " 4.4 BSD ; printf "\n"
+
# make sure that a fieldwidth and precision of `*' are handled right
printf "%10.8s\n" 4.4BSD
printf "%*.*s\n" 10 8 4.4BSD
diff --git a/tests/run-cprint b/tests/run-cprint
new file mode 100644
index 00000000..5f202e43
--- /dev/null
+++ b/tests/run-cprint
@@ -0,0 +1,2 @@
+${THIS_SH} ./cprint.tests > /tmp/xx 2>&1
+diff /tmp/xx cprint.right && rm -f /tmp/xx
diff --git a/tests/run-printf b/tests/run-printf
index 10361bce..4555c626 100644
--- a/tests/run-printf
+++ b/tests/run-printf
@@ -1,2 +1,5 @@
+# See whether or not we can use `diff -a'
+( diff -a ./printf.tests ./printf.tests >/dev/null 2>&1 ) && AFLAG=-a
+
${THIS_SH} ./printf.tests > /tmp/xx 2>&1
-diff /tmp/xx printf.right && rm -f /tmp/xx
+diff $AFLAG /tmp/xx printf.right && rm -f /tmp/xx
diff --git a/tests/shopt.right b/tests/shopt.right
index 845ee901..9dc01fbc 100644
--- a/tests/shopt.right
+++ b/tests/shopt.right
@@ -21,6 +21,7 @@ shopt -u mailwarn
shopt -u nocaseglob
shopt -u nullglob
shopt -s promptvars
+shopt -u restricted_shell
shopt -u shift_verbose
shopt -s sourcepath
--
@@ -50,6 +51,7 @@ shopt -u lithist
shopt -u mailwarn
shopt -u nocaseglob
shopt -u nullglob
+shopt -u restricted_shell
shopt -u shift_verbose
--
cdable_vars off
@@ -66,6 +68,7 @@ lithist off
mailwarn off
nocaseglob off
nullglob off
+restricted_shell off
shift_verbose off
--
set +o allexport
diff --git a/tests/test.right b/tests/test.right
index e534c17b..8684a121 100644
--- a/tests/test.right
+++ b/tests/test.right
@@ -222,45 +222,45 @@ t -h /tmp/test.symlink
0
t 4+3 -eq 7
./test-tests: test: 4+3: integer expression expected
-1
+2
b 4-5 -eq 7
./test-tests: [: 4+3: integer expression expected
-1
+2
t 9 -eq 4+5
./test-tests: test: 4+5: integer expression expected
-1
+2
b 9 -eq 4+5
./test-tests: [: 4+5: integer expression expected
-1
+2
t A -eq 7
./test-tests: test: A: integer expression expected
-1
+2
b A -eq 7
./test-tests: [: A: integer expression expected
-1
+2
t 9 -eq B
./test-tests: test: B: integer expression expected
-1
+2
b 9 -eq B
./test-tests: [: B: integer expression expected
-1
+2
t ( 1 = 2
./test-tests: test: `)' expected
-1
+2
b ( 1 = 2
./test-tests: [: `)' expected, found ]
-1
+2
./test-tests: test: a: unary operator expected
-1
+2
./test-tests: test: b: binary operator expected
-1
+2
./test-tests: test: -A: unary operator expected
-1
+2
./test-tests: test: too many arguments
-1
+2
./test-tests: test: too many arguments
-1
+2
./test-tests: [: missing `]'
-1
+2
./test-tests: test: (: unary operator expected
-1
+2
diff --git a/tests/type.right b/tests/type.right
index fe2c196e..89b6f536 100644
--- a/tests/type.right
+++ b/tests/type.right
@@ -1,4 +1,4 @@
-./type.tests: type: unknown option: f
+./type.tests: type: illegal option: -f
type: usage: type [-apt] name [name ...]
./type.tests: type: notthere: not found
./type.tests: command: notthere: not found