26754: tweak zgetdir() and test for realpath()
[zsh.git] / Test / C05debug.ztst
blob9a8df1dad42d3a89c4f507bb486a9437a0d5430b
1 %prep
3   setopt localtraps
5 %test
7   unsetopt DEBUG_BEFORE_CMD
8   debug-trap-bug1() {
9     setopt localtraps
10     print "print bug file here" >bug-file
11     print "print this is line one
12     print this is line two
13     print this is line three
14     print and this is line fifty-nine." >bug-file2
15     function debug_trap_handler {
16         print $functrace[1]
17         do_bug
18     }
19     function do_bug {
20        . ./bug-file
21     }
22     trap 'echo EXIT hit' EXIT
23     trap 'debug_trap_handler' DEBUG
24     . ./bug-file2
25   }
26   debug-trap-bug1
27 0: Relationship between traps and sources
28 >debug-trap-bug1:15
29 >bug file here
30 >this is line one
31 >./bug-file2:1
32 >bug file here
33 >this is line two
34 >./bug-file2:2
35 >bug file here
36 >this is line three
37 >./bug-file2:3
38 >bug file here
39 >and this is line fifty-nine.
40 >./bug-file2:4
41 >bug file here
42 >debug-trap-bug1:16
43 >bug file here
44 >EXIT hit
46   cat >zsh-trapreturn-bug2 <<-'HERE'
47         cmd='./fdasfsdafd'
48         [[ -x $cmd ]] && rm $cmd
49         set -o DEBUG_BEFORE_CMD
50         trap '[[ $? -ne 0 ]] && exit 0' DEBUG
51         $cmd  # invalid command
52         # Failure
53         exit 10
54         HERE
55   $ZTST_testdir/../Src/zsh -f ./zsh-trapreturn-bug2 2>erroutput.dif
56   mystat=$?
57   (
58    setopt extendedglob
59    print ${"$(< erroutput.dif)"%%:[^:]#: ./fdasfsdafd}
60   )
61   (( mystat == 0 ))
62 0: trapreturn handling bug is properly fixed
63 >./zsh-trapreturn-bug2:5
65   fn() {
66     setopt localtraps localoptions debugbeforecmd
67     trap '(( LINENO == 4 )) && setopt errexit' DEBUG
68     print $LINENO three
69     print $LINENO four
70     print $LINENO five
71     [[ -o errexit ]] && print "Hey, ERREXIT is set!"
72   }
73   fn
74 1:Skip line from DEBUG trap
75 >3 three
76 >5 five
78   # Assignments are a special case, since they use a simpler
79   # wordcode type, so we need to test skipping them separately.
80   fn() {
81     setopt localtraps localoptions debugbeforecmd
82     trap '(( LINENO == 4 )) && setopt errexit' DEBUG
83     x=three
84     x=four
85     print $LINENO $x
86     [[ -o errexit ]] && print "Hey, ERREXIT is set!"
87   }
88   fn
89 1:Skip assignment from DEBUG trap
90 >5 three
92   fn() {
93     setopt localtraps localoptions debugbeforecmd
94     trap 'print $LINENO' DEBUG
95     [[ a = a ]] && print a is ok
96   }
97   fn
98 0:line numbers of complex sublists
100 >a is ok
102   fn() {
103     setopt localtraps localoptions debugbeforecmd
104     trap 'print $LINENO' DEBUG
105     print before
106     x='    first
107     second
108     third'
109     print $x
110   }
111   fn
112 0:line numbers of multiline assignments
114 >before
117 >    first
118 >    second
119 >    third
121   fn() {
122     emulate -L zsh; setopt debugbeforecmd
123     trap 'print "$LINENO: '\''$ZSH_DEBUG_CMD'\''"' DEBUG
124     print foo &&
125     print bar ||
126     print rod
127     x=y
128     print $x
129     fn2() { echo wow }
130     fn2
131   }
132   fn
133 0:ZSH_DEBUG_CMD in debug traps
134 >3: 'print foo && print bar || print rod'
135 >foo
136 >bar
137 >6: 'x=y '
138 >7: 'print $x'
140 >8: 'fn2 () {
141 >       echo wow
143 >9: 'fn2'
144 >0: 'echo wow'
145 >wow
147   foo() {
148     emulate -L zsh; setopt debugbeforecmd
149     trap '[[ $ZSH_DEBUG_CMD == *bar* ]] && return 2' DEBUG
150     echo foo
151     echo bar
152   }
153   foo
154 2:Status of forced return from eval-style DEBUG trap
155 >foo
157 %clean
159  rm -f bug-file bug-file2 erroutput.dif zsh-trapreturn-bug2