summary refs log tree commit diff
path: root/Test/E02xtrace.ztst
blob: 56bc20f1a9014cd2e5939db0f7bc4d5ae08d8764 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Test that xtrace output is correctly generated

%prep
  mkdir xtrace.tmp && cd xtrace.tmp

  function xtf {
    local regression_test_dummy_variable
    print "$*"
  }
  function xtfx {
    local regression_test_dummy_variable
    print "Tracing: (){ builtin 2>file }" 2>>xtrace.err
    { print "Tracing: (){ { builtin } 2>file }" } 2>>xtrace.err
  }
  echo 'print "$*"' > xt.in

%test

  PS4='+%N:%i> '
  set -x
  print 'Tracing: builtin'
  print 'Tracing: builtin 2>file' 2>xtrace.err
  cat <<<'Tracing: external'
  cat <<<'Tracing: external 2>file' 2>>xtrace.err
  ( print 'Tracing: ( builtin )' )
  ( print 'Tracing: ( builtin ) 2>file' ) 2>>xtrace.err
  ( cat <<<'Tracing: ( external )' )
  ( cat <<<'Tracing: ( external ) 2>file' ) 2>>xtrace.err
  { print 'Tracing: { builtin }' }
  { print 'Tracing: { builtin } 2>file' } 2>>xtrace.err
  { cat <<<'Tracing: { external }' }
  { cat <<<'Tracing: { external } 2>file' } 2>>xtrace.err
  repeat 1 do print 'Tracing: do builtin done'; done
  repeat 1 do print 'Tracing: do builtin done 2>file'; done 2>>xtrace.err
  repeat 1 do cat <<<'Tracing: do external done'; done
  repeat 1 do cat <<<'Tracing: do external done 2>file'; done 2>>xtrace.err
  xtf 'Tracing: function'
  xtf 'Tracing: function 2>file' 2>>xtrace.err
  xtfx
  . ./xt.in 'Tracing: source'
  . ./xt.in 'Tracing: source 2>file' 2>>xtrace.err
  set +x
  cat xtrace.err
0:xtrace with and without redirection
>Tracing: builtin
>Tracing: builtin 2>file
>Tracing: external
>Tracing: external 2>file
>Tracing: ( builtin )
>Tracing: ( builtin ) 2>file
>Tracing: ( external )
>Tracing: ( external ) 2>file
>Tracing: { builtin }
>Tracing: { builtin } 2>file
>Tracing: { external }
>Tracing: { external } 2>file
>Tracing: do builtin done
>Tracing: do builtin done 2>file
>Tracing: do external done
>Tracing: do external done 2>file
>Tracing: function
>Tracing: function 2>file
>Tracing: (){ builtin 2>file }
>Tracing: (){ { builtin } 2>file }
>Tracing: source
>Tracing: source 2>file
>+(eval):8> print 'Tracing: ( builtin ) 2>file'
>+(eval):10> cat
>+(eval):12> print 'Tracing: { builtin } 2>file'
>+(eval):14> cat
>+(eval):16> print 'Tracing: do builtin done 2>file'
>+(eval):18> cat
>+xtf:1> local regression_test_dummy_variable
>+xtf:2> print 'Tracing: function 2>file'
>+xtfx:3> print 'Tracing: (){ { builtin } 2>file }'
?+(eval):3> print 'Tracing: builtin'
?+(eval):4> print 'Tracing: builtin 2>file'
?+(eval):5> cat
?+(eval):6> cat
?+(eval):7> print 'Tracing: ( builtin )'
?+(eval):9> cat
?+(eval):11> print 'Tracing: { builtin }'
?+(eval):13> cat
?+(eval):15> print 'Tracing: do builtin done'
?+(eval):17> cat
?+(eval):19> xtf 'Tracing: function'
?+xtf:1> local regression_test_dummy_variable
?+xtf:2> print 'Tracing: function'
?+(eval):20> xtf 'Tracing: function 2>file'
?+(eval):21> xtfx
?+xtfx:1> local regression_test_dummy_variable
?+xtfx:2> print 'Tracing: (){ builtin 2>file }'
?+(eval):22> . ./xt.in 'Tracing: source'
?+./xt.in:1> print 'Tracing: source'
?+(eval):23> . ./xt.in 'Tracing: source 2>file'
?+./xt.in:1> print 'Tracing: source 2>file'
?+(eval):24> set +x

 typeset -ft xtf
 xtf 'Tracing: function'
0:tracing function
>Tracing: function
?+xtf:1> local regression_test_dummy_variable
?+xtf:2> print 'Tracing: function'

 echo 'PS4="+%x:%I> "
 fn() {
   print This is fn.
 }
 :
 fn
 ' >fnfile
 $ZTST_testdir/../Src/zsh -fx ./fnfile 2>errfile
 grep '\./fnfile' errfile 1>&2
0:Trace output with sourcefile and line number.
>This is fn.
?+./fnfile:1> PS4='+%x:%I> ' 
?+./fnfile:5> :
?+./fnfile:6> fn
?+./fnfile:3> print This is fn.

 set -x
 [[ 'f o' == 'f x'* || 'b r' != 'z o' && 'squashy sound' < 'squishy sound' ]]
 [[ 'f o' = 'f x'* || 'b r' != 'z o' && 'squashy sound' < 'squishy sound' ]]
 [[ -e nonexistentfile || ( -z '' && -t 3 ) ]]
 set +x
0:Trace for conditions
?+(eval):2> [[ 'f o' == f\ x* || 'b r' != z\ o && 'squashy sound' < 'squishy sound' ]]
?+(eval):3> [[ 'f o' = f\ x* || 'b r' != z\ o && 'squashy sound' < 'squishy sound' ]]
?+(eval):4> [[ -e nonexistentfile || -z '' && -t 3 ]]
?+(eval):5> set +x

  # Part 1: Recurses into nested anonymous functions
  fn() {
    () { () { true } }
  }
  functions -T fn
  fn
  # Part 2: Doesn't recurse into named functions
  gn() { true }
  fn() { gn }
  functions -T fn
  fn
0:tracing recurses into anonymous functions
?+fn:1> '(anon)'
?+(anon):0> '(anon)'
?+(anon):0> true
?+fn:0> gn

  test_cases=(
      f            # baseline
      foo-bar      # Dash
      ヌ           # Meta (the UTF-8 representation of this character has an 0x83 byte)
      \$\'ba\\0z\' # Nul, escaped as though by ${(qqqq)}
  )
  for 1 in "$test_cases[@]"; do
    eval "
      ${1}() {
        ${1}() { echo inner }
      }
      functions -T ${1}
      ${1}
      LC_ALL=C which ${1}
    "
  done
0:a function that redefines itself preserves tracing
>f () {
>	# traced
>	echo inner
>}
>foo-bar () {
>	# traced
>	echo inner
>}
>$'\M-c\M-\C-C\M-\C-L' () {
>	# traced
>	echo inner
>}
>$'ba\C-@z' () {
>	# traced
>	echo inner
>}

 function -T { echo traced anonymous function }
 functions -- -T # no output
1:define traced function: anonymous function
?+(anon):0> echo traced anonymous function
>traced anonymous function

 function -T f { echo traced named function }
 functions -- -T # no output
 functions f
 f
0:define traced function: named function
>f () {
>	# traced
>	echo traced named function
>}
?+f:0> echo traced named function
>traced named function

 function -T -- -T { echo trace function literally named "-T" }
 -T
 function -T -- { echo trace anonymous function }
 functions -- -- # no output
1:define traced function: parse test
?+-T:0> echo trace function literally named -T
>trace function literally named -T
?+(anon):0> echo trace anonymous function
>trace anonymous function

 function -- g { echo g }
 g
 function -- { echo anonymous }
 functions -- -- # no output
1:function end-of-"options" syntax, #1
>g
>anonymous

 function -- -T { echo runs }
 functions -- -- # no output
 echo the definition didn\'t execute it
 -T
0:function end-of-"options" syntax, #2
>the definition didn't execute it
>runs

 f() g
 g() :
 functions -t f
 f
0:functions -t smoke test #1
?+f:4> g
?+g:4> :
F:The `4' on the second line is incorrect; see workers/48594.

 f() g
 g() { () : }
 functions -t f
 f
0:functions -t smoke test #2
?+f:4> g
?+g:0> '(anon)'
?+(anon):0> :

 f() g
 g() :
 (
  functions -T f
  functions -t f
  f
 )
 (
  functions -t f
  functions -T f
  f
 )
0:ensure the behaviour  of 'functions -Tt f' doesn't change surreptitiously
?+f:6> g
?+f:11> g
F:If this test fails, the new behaviour may be 
F:workers/48591.