]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/dbg-support.tests
Imported from ../bash-3.0.tar.gz.
[thirdparty/bash.git] / tests / dbg-support.tests
1 #!../bash
2 #
3 # Test correct functioning bash debug support not via the bashdb
4 # debugger but merely by printing via print_trap()
5 # $Id: dbg-support.tests,v 1.13 2003/02/17 22:02:25 rockyb Exp $
6 shopt -s extdebug
7 print_debug_trap() {
8 echo "debug lineno: $1 ${FUNCNAME[1]}"
9 return
10 }
11
12 print_return_trap() {
13 echo "return lineno: $1 ${FUNCNAME[1]}"
14 return
15 }
16
17 fn1() {
18 echo "LINENO $LINENO"
19 echo "LINENO $LINENO"
20 echo "BASH_SOURCE[0]" ${BASH_SOURCE[0]}
21 echo "FUNCNAME[0]" ${FUNCNAME[0]}
22 echo `caller`
23 echo `caller 0`
24 echo `caller 1`
25 echo `caller foo`
26 }
27
28 fn2() {
29 echo "fn2 here. Calling fn1..."
30 fn1
31 }
32
33 fn3() {
34 echo "LINENO $LINENO"
35 echo "BASH_SOURCE[0]" ${BASH_SOURCE[0]}
36
37 # Print a stack trace
38 declare -i n
39 n=${#FUNCNAME[@]}
40 for (( i=0 ; (( i < $n )) ; i++ )) ; do
41 local -i j=i+1
42 [ $j -eq $n ] && j=i # main()'s file is the same as the first caller
43 echo "${FUNCNAME[$i]} called from file " \
44 "\`${BASH_SOURCE[$j]}' at line ${BASH_LINENO[$j]}"
45 done
46 source ./dbg-support.sub
47 }
48
49 fn4() {
50 echo "fn4 here. Calling fn3..."
51 fn3
52 }
53
54
55 #!../bash
56 #
57 # Test of support for debugging facilities in bash
58 #
59 # Test debugger set option fntrace - set on. Not in vanilla Bash 2.05
60 #
61 set -o functrace
62 trap 'print_debug_trap $LINENO' DEBUG
63 trap 'print_return_trap $LINENO' RETURN
64
65 # Funcname is now an array. Vanilla Bash 2.05 doesn't have FUNCNAME array.
66 echo "FUNCNAME" ${FUNCNAME[0]}
67
68 # We should trace into the below.
69 # Start easy with a simple function.
70 fn1
71 fn2
72 fn3
73 source ./dbg-support.sub
74
75 # Test debugger set option fntrace - set off
76 set +T
77
78 # We should not trace into this.
79 fn1
80 fn2
81 fn3
82 fn4
83 source ./dbg-support.sub
84
85 # Another way to say: set -o fntrace
86 set -T
87
88 # We should trace into this.
89 source ./dbg-support.sub
90 set +T
91
92 # Test that the line numbers in the presence of conditionals are correct.
93 for (( i=0 ; (( i <= 2 )) ; i++ )) ; do
94 if [ $i -eq 2 ] ; then
95 echo "Hit 2"
96 fi
97 j=4
98 done
99
100 #
101 # Check line numbers in command substitution
102 #
103 echo $(sourced_fn)
104 echo `sourced_fn`
105 x=$((sourced_fn))
106 x={ sourced_fn }
107
108 # Make sure we step into sourced_fn as a comand when we request to do so.
109 # Vanilla bash 2.0 doesn't do.
110 set -o functrace
111 x={ sourced_fn }
112
113 # Should see line number of xyzzy below. Vanilla bash 2.05b doesn't do
114 case xyzzy in
115 a )
116 x=5
117 ;;
118 xyzz? )
119 case 3 in
120 2 )
121 x=6 ;;
122 3 )
123 echo "got it" ;;
124 * ) echo "no good" ;;
125 esac
126 ;;
127 * )
128 esac
129
130 # Should see line numbers for initial for lines.
131 for i in 0 1 ; do
132 for j in 3 4 ; do
133 ((x=i+j))
134 done
135 done
136 #;;; Local Variables: ***
137 #;;; mode:shell-script ***
138 #;;; eval: (sh-set-shell "bash") ***
139 #;;; End: ***