about summary refs log tree commit diff
path: root/Test/C05debug.ztst
blob: 9a8df1dad42d3a89c4f507bb486a9437a0d5430b (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
%prep

  setopt localtraps

%test

  unsetopt DEBUG_BEFORE_CMD
  debug-trap-bug1() {
    setopt localtraps
    print "print bug file here" >bug-file
    print "print this is line one
    print this is line two
    print this is line three
    print and this is line fifty-nine." >bug-file2
    function debug_trap_handler {
	print $functrace[1]
	do_bug
    }
    function do_bug {
       . ./bug-file
    }
    trap 'echo EXIT hit' EXIT
    trap 'debug_trap_handler' DEBUG
    . ./bug-file2
  }
  debug-trap-bug1
0: Relationship between traps and sources
>debug-trap-bug1:15
>bug file here
>this is line one
>./bug-file2:1
>bug file here
>this is line two
>./bug-file2:2
>bug file here
>this is line three
>./bug-file2:3
>bug file here
>and this is line fifty-nine.
>./bug-file2:4
>bug file here
>debug-trap-bug1:16
>bug file here
>EXIT hit

  cat >zsh-trapreturn-bug2 <<-'HERE'
	cmd='./fdasfsdafd'
	[[ -x $cmd ]] && rm $cmd
	set -o DEBUG_BEFORE_CMD
	trap '[[ $? -ne 0 ]] && exit 0' DEBUG
	$cmd  # invalid command
	# Failure
	exit 10
	HERE
  $ZTST_testdir/../Src/zsh -f ./zsh-trapreturn-bug2 2>erroutput.dif
  mystat=$?
  (
   setopt extendedglob
   print ${"$(< erroutput.dif)"%%:[^:]#: ./fdasfsdafd}
  )
  (( mystat == 0 ))
0: trapreturn handling bug is properly fixed
>./zsh-trapreturn-bug2:5

  fn() {
    setopt localtraps localoptions debugbeforecmd
    trap '(( LINENO == 4 )) && setopt errexit' DEBUG
    print $LINENO three
    print $LINENO four
    print $LINENO five
    [[ -o errexit ]] && print "Hey, ERREXIT is set!"
  }
  fn
1:Skip line from DEBUG trap
>3 three
>5 five

  # Assignments are a special case, since they use a simpler
  # wordcode type, so we need to test skipping them separately.
  fn() {
    setopt localtraps localoptions debugbeforecmd
    trap '(( LINENO == 4 )) && setopt errexit' DEBUG
    x=three
    x=four
    print $LINENO $x
    [[ -o errexit ]] && print "Hey, ERREXIT is set!"
  }
  fn
1:Skip assignment from DEBUG trap
>5 three

  fn() {
    setopt localtraps localoptions debugbeforecmd
    trap 'print $LINENO' DEBUG
    [[ a = a ]] && print a is ok
  }
  fn
0:line numbers of complex sublists
>3
>a is ok

  fn() {
    setopt localtraps localoptions debugbeforecmd
    trap 'print $LINENO' DEBUG
    print before
    x='    first
    second
    third'
    print $x
  }
  fn
0:line numbers of multiline assignments
>3
>before
>4
>7
>    first
>    second
>    third

  fn() {
    emulate -L zsh; setopt debugbeforecmd
    trap 'print "$LINENO: '\''$ZSH_DEBUG_CMD'\''"' DEBUG
    print foo &&
    print bar ||
    print rod
    x=y
    print $x
    fn2() { echo wow }
    fn2
  }
  fn
0:ZSH_DEBUG_CMD in debug traps
>3: 'print foo && print bar || print rod'
>foo
>bar
>6: 'x=y '
>7: 'print $x'
>y
>8: 'fn2 () {
>	echo wow
>}'
>9: 'fn2'
>0: 'echo wow'
>wow

  foo() {
    emulate -L zsh; setopt debugbeforecmd
    trap '[[ $ZSH_DEBUG_CMD == *bar* ]] && return 2' DEBUG
    echo foo
    echo bar
  }
  foo
2:Status of forced return from eval-style DEBUG trap
>foo

%clean

 rm -f bug-file bug-file2 erroutput.dif zsh-trapreturn-bug2