summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2011-12-08 20:06:56 -0500
committerChet Ramey <chet.ramey@case.edu>2011-12-08 20:06:56 -0500
commitc302751c7b9cc559f6d517c7b2ce701a89b8a2da (patch)
tree774a1d097319e4bbf9ccae8f467b930b11f536a4 /tests
parent1231ac4798fd77b9ac9a07c8cad7b1ee720781d3 (diff)
downloadbash-c302751c7b9cc559f6d517c7b2ce701a89b8a2da.tar.gz
commit bash-20090319 snapshot
Diffstat (limited to 'tests')
-rw-r--r--tests/history.right4
-rw-r--r--tests/history.tests2
-rw-r--r--tests/history.tests~111
-rw-r--r--tests/history2.sub10
-rw-r--r--tests/trap.right11
-rw-r--r--tests/trap.tests3
-rw-r--r--tests/trap.tests~90
-rw-r--r--tests/trap3.sub9
-rw-r--r--tests/trap3.sub~7
9 files changed, 247 insertions, 0 deletions
diff --git a/tests/history.right b/tests/history.right
index 128b0deb..6c0caa05 100644
--- a/tests/history.right
+++ b/tests/history.right
@@ -140,3 +140,7 @@ three
one
two
three
+4.0
+echo ${BASH_VERSION%\.*}
+4.0
+ echo ${BASH_VERSION%\.*}
diff --git a/tests/history.tests b/tests/history.tests
index 7ca75587..688095d5 100644
--- a/tests/history.tests
+++ b/tests/history.tests
@@ -109,3 +109,5 @@ shopt -q -o history
echo $?
${THIS_SH} ./history1.sub
+
+${THIS_SH} ./history2.sub
diff --git a/tests/history.tests~ b/tests/history.tests~
new file mode 100644
index 00000000..7ca75587
--- /dev/null
+++ b/tests/history.tests~
@@ -0,0 +1,111 @@
+trap 'rm /tmp/newhistory' 0
+
+# bad options
+history -x
+# cannot use -r and -w at the same time
+history -r -w /dev/null
+
+# bad option
+fc -v
+
+unset HISTFILESIZE
+
+# all of these should result in an empty history list
+history -c
+history -r /dev/null
+history -n /dev/null
+history -c
+
+HISTFILE=history.list
+HISTCONTROL=ignoreboth
+HISTIGNORE='&:history*:fc*'
+HISTSIZE=32
+
+shopt -s cmdhist
+set -o history
+
+history
+
+fc -l
+fc -nl
+
+fc -lr
+fc -nlr
+
+history -s "echo line for history"
+history
+
+history -p '!!'
+
+fc -nl
+
+HISTFILE=/tmp/newhistory
+history -a
+echo displaying \$HISTFILE after history -a
+cat $HISTFILE
+
+history
+history -w
+cat $HISTFILE
+
+history -s "echo line 2 for history"
+history
+history -p '!e'
+history -p '!!'
+
+# this should show up as one history entry
+for x in one two three
+do
+ :
+done
+history
+
+# just a basic test. a full test suite for history expansion should be
+# created
+set -H
+!!
+!e
+
+unset HISTSIZE
+unset HISTFILE
+
+fc -l 4
+fc -l 4 8
+
+fc -l one=two three=four 502
+
+history 4
+
+shopt -so history
+shopt -s expand_aliases
+
+alias r="fc -s"
+
+echo aa ab ac
+
+r a=x
+r x=4 b=8
+
+# this had better fail with `no command found'
+r cc
+
+unalias -a
+alias
+
+# these two blocks had better both result in the same output
+echo aa
+echo bb
+echo cc
+fc -e cat
+
+echo aa
+echo bb
+echo cc
+fc -e cat -1
+
+set +o history
+
+shopt -q -o history
+echo $?
+
+${THIS_SH} ./history1.sub
diff --git a/tests/history2.sub b/tests/history2.sub
new file mode 100644
index 00000000..1a8e78c4
--- /dev/null
+++ b/tests/history2.sub
@@ -0,0 +1,10 @@
+set -o history
+HISTSIZE=256
+HISTFILE=/dev/null
+
+# these two lines should be the same
+echo ${BASH_VERSION%\.*}
+echo $(fc -nl -1)
+
+echo ${BASH_VERSION%\.*}
+fc -nl -1
diff --git a/tests/trap.right b/tests/trap.right
index 6e357d9a..8103e166 100644
--- a/tests/trap.right
+++ b/tests/trap.right
@@ -63,6 +63,17 @@ after while
before false in trap2a.sub
after false in trap2a.sub
command substitution
++[6] echo 1
+1
++[7] echo 2
+2
++[8] echo 3
++[8] cat
++[8] false
+++[8] echo trap: 8
+trap: 8
++[9] echo 4
+4
caught a child death
trap -- 'echo caught a child death' SIGCHLD
trap -- 'echo exiting' EXIT
diff --git a/tests/trap.tests b/tests/trap.tests
index 83497a31..ded1d70a 100644
--- a/tests/trap.tests
+++ b/tests/trap.tests
@@ -66,6 +66,8 @@ trap '' USR2
# test ERR trap
./trap2.sub
+${THIS_SH} ./trap3.sub
+
#
# show that setting a trap on SIGCHLD is not disastrous.
#
@@ -88,3 +90,4 @@ trap
trap - SIGCHLD
wait
+
diff --git a/tests/trap.tests~ b/tests/trap.tests~
new file mode 100644
index 00000000..83497a31
--- /dev/null
+++ b/tests/trap.tests~
@@ -0,0 +1,90 @@
+# test the trap code
+
+trap 'echo exiting' 0
+trap 'echo aborting' 1 2 3 6 15
+
+# make sure a user-specified subshell runs the exit trap, but does not
+# inherit the exit trap from a parent shell
+( trap 'echo subshell exit' 0; exit 0 )
+( exit 0 )
+
+trap
+
+func()
+{
+ trap 'echo ${FUNCNAME:-$0}[$LINENO] funcdebug' DEBUG
+ echo funcdebug line
+}
+
+trap 'echo [$LINENO] debug' DEBUG
+echo debug line
+
+trap
+
+func
+
+trap
+
+trap 'echo ${FUNCNAME:-$0}[$LINENO] debug' DEBUG
+func2()
+{
+ echo func2debug line
+}
+declare -ft func2
+func2
+
+unset -f func2
+
+trap '' DEBUG
+
+trap
+
+trap - debug
+
+trap
+
+trap - HUP
+trap hup
+trap '' INT
+trap '' int
+
+trap
+
+# exit 0 in exit trap should set exit status
+(
+set -e
+trap 'exit 0' EXIT
+false
+echo bad
+)
+echo $?
+
+# hmmm...should this set the handling to SIG_IGN for children, too?
+trap '' USR2
+./trap1.sub
+
+# test ERR trap
+./trap2.sub
+
+#
+# show that setting a trap on SIGCHLD is not disastrous.
+#
+set -o monitor
+
+trap 'echo caught a child death' SIGCHLD
+
+sleep 7 & sleep 6 & sleep 5 &
+
+# this will only catch the first, since there's a trap on SIGCHLD
+wait
+
+trap -p SIGCHLD
+
+# Now reset some of the signals the shell handles specially back to
+# their default values (with or without the SIG prefix)
+trap - SIGINT QUIT TERM
+
+trap
+
+trap - SIGCHLD
+wait
diff --git a/tests/trap3.sub b/tests/trap3.sub
new file mode 100644
index 00000000..0df44550
--- /dev/null
+++ b/tests/trap3.sub
@@ -0,0 +1,9 @@
+PS4='+[$LINENO] '
+trap 'echo trap: $LINENO' ERR
+
+set -x
+
+echo 1
+echo 2
+echo 3 | cat | false
+echo 4
diff --git a/tests/trap3.sub~ b/tests/trap3.sub~
new file mode 100644
index 00000000..fb4df8ce
--- /dev/null
+++ b/tests/trap3.sub~
@@ -0,0 +1,7 @@
+PS4='+[$LINENO] '
+trap 'echo trap: $LINENO' ERR
+
+echo 1
+echo 2
+echo 3 | cat | false
+echo 4