diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/history.right | 4 | ||||
-rw-r--r-- | tests/history.tests | 2 | ||||
-rw-r--r-- | tests/history.tests~ | 111 | ||||
-rw-r--r-- | tests/history2.sub | 10 | ||||
-rw-r--r-- | tests/trap.right | 11 | ||||
-rw-r--r-- | tests/trap.tests | 3 | ||||
-rw-r--r-- | tests/trap.tests~ | 90 | ||||
-rw-r--r-- | tests/trap3.sub | 9 | ||||
-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 |