Skip to content

Commit 4a2d9c0

Browse files
committed
Implemented AST pretty-printer to capture expression passed to assert()
1 parent 7a059b6 commit 4a2d9c0

File tree

5 files changed

+1264
-7
lines changed

5 files changed

+1264
-7
lines changed

Zend/tests/assert/expect_015.phpt

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
--TEST--
2+
AST pretty-peinter
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=0
6+
--FILE--
7+
<?php
8+
assert(0 && ($a = function () {
9+
global $a, $$b;
10+
static $c, $d = 0;
11+
unset($e);
12+
$x = isset($a) && !empty($b) || eval($c);
13+
$x = $a ? $b : $c;
14+
$x = $a ?: $c;
15+
$x = $a ?? $b;
16+
list($a, $b, $c) = [1, 2=>'x', 'z'=>'c'];
17+
@foo();
18+
$y = clone $x;
19+
yield 1 => 2;
20+
}));
21+
22+
assert(0 && ($a = function &(array &$a, X $b = null) use ($c,&$d) : X {
23+
abstract class A extends B implements C, D {
24+
const X = 12;
25+
const Y = self::X, Z = "aaa";
26+
27+
public $a = 1, $b;
28+
protected $c;
29+
static private $d = null;
30+
31+
abstract function foo();
32+
33+
static private function f1() {
34+
for ($i = 0, $j = 100; $i < $j; $i++, --$j) {
35+
$s[$i] = $a[$j];
36+
}
37+
foreach ($a as $key => &$val) {
38+
print "$key => $val\n";
39+
}
40+
while ($s[$i]) {
41+
$i++;
42+
}
43+
do {
44+
$i--;
45+
} while ($s[$i]);
46+
$x = foo($a + 1, 4, ...[1,2,3]);
47+
$x = ${$a . "_1"}();
48+
$x = A::foo();
49+
$x = ${$a . "_1"}::foo();
50+
$x = A::${$a . "_1"}();
51+
$x = $x->foo();
52+
$x = ${$a . "_1"}->foo();
53+
$x = $x->{$a . "_1"}();
54+
$x->a = C::C;
55+
${$a . "_1"}->a = ${$a . "_1"}::C;
56+
$x->{a . "_1"} = C::C;
57+
$x = C::$z;
58+
$x = ${$a . "_1"}::$z;
59+
$x = C::${$z . "_1"};
60+
}
61+
}
62+
}));
63+
64+
assert(0 && ($a = function &(array &$a, X $b = null) use ($c,&$d) : X {
65+
final class A {
66+
final protected function f2() {
67+
if (!$x) {
68+
return 0;
69+
}
70+
if ($x == 1) {
71+
return 1;
72+
} else if ($x == 2) {
73+
return 2;
74+
} else if ($x == 3) {
75+
return 3;
76+
} else {
77+
if ($x == 9) {
78+
return 9;
79+
}
80+
L0:
81+
switch ($x) {
82+
case 4: break;
83+
case 5: continue;
84+
case 6: break 2;
85+
case 7: continue 2;
86+
case 8: goto L0;
87+
default: return;
88+
}
89+
}
90+
}
91+
}
92+
}));
93+
94+
assert(0 && ($a = function &(array &$a, X $b = null) use ($c,&$d) : X {
95+
class A {
96+
use T1, T2 {
97+
T1::foo insteadof foo;
98+
T2::foo as bar;
99+
}
100+
use T3;
101+
}
102+
}));
103+
104+
assert(0 && ($a = function &(array &$a, X $b = null) use ($c,&$d) : X {
105+
declare(A=1,B=2);
106+
try {
107+
$i++;
108+
} catch (MyException $e) {
109+
echo 1;
110+
} catch (Exception $e) {
111+
echo 2;
112+
} finally {
113+
echo 3;
114+
}
115+
}));
116+
?>
117+
--EXPECTF--
118+
Warning: Unsupported declare 'A' in %sexpect_015.php on line %d
119+
120+
Warning: Unsupported declare 'B' in %sexpect_015.php on line %d
121+
122+
Warning: assert(): assert(0 && ($a = function () {
123+
global $a;
124+
global $$b;
125+
static $c;
126+
static $d = 0;
127+
unset($e);
128+
$x = isset($a) && !empty($b) || eval($c);
129+
$x = $a ? $b : $c;
130+
$x = $a ?: $c;
131+
$x = $a ?? $b;
132+
list($a, $b, $c) = [1, 2 => 'x', 'z' => 'c'];
133+
@foo();
134+
$y = clone $x;
135+
yield 1 => 2;
136+
})) failed in %sexpect_015.php on line %d
137+
138+
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
139+
abstract class A extends B implements C, D {
140+
const X = 12;
141+
const Y = self::X, Z = 'aaa';
142+
public $a = 1, $b;
143+
protected $c;
144+
private static $d = null;
145+
public abstract function foo();
146+
147+
private static function f1() {
148+
for ($i = 0, $j = 100; $i < $j; $i++, --$j) {
149+
$s[$i] = $a[$j];
150+
}
151+
foreach ($a as $key => & $val) {
152+
print "$key => $val\n";
153+
}
154+
while ($s[$i]) {
155+
$i++;
156+
}
157+
do {
158+
$i--;
159+
} while ($s[$i]);
160+
$x = foo($a + 1, 4, ... [1, 2, 3]);
161+
$x = ${$a . '_1'}();
162+
$x = A::foo();
163+
$x = ${$a . '_1'}::foo();
164+
$x = A::${$a . '_1'}();
165+
$x = $x->foo();
166+
$x = ${$a . '_1'}->foo();
167+
$x = $x->{$a . '_1'}();
168+
$x->a = C::C;
169+
${$a . '_1'}->a = ${$a . '_1'}::C;
170+
$x->{a . '_1'} = C::C;
171+
$x = C::$z;
172+
$x = ${$a . '_1'}::$z;
173+
$x = C::${$z . '_1'};
174+
}
175+
176+
}
177+
178+
})) failed in %sexpect_015.php on line %d
179+
180+
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
181+
final class A {
182+
protected final function f2() {
183+
if (!$x) {
184+
return 0;
185+
}
186+
if ($x == 1) {
187+
return 1;
188+
} else if ($x == 2) {
189+
return 2;
190+
} else if ($x == 3) {
191+
return 3;
192+
} else {
193+
if ($x == 9) {
194+
return 9;
195+
}
196+
L0:
197+
switch ($x) {
198+
case 4:
199+
break;
200+
case 5:
201+
continue;
202+
case 6:
203+
break 2;
204+
case 7:
205+
continue 2;
206+
case 8:
207+
goto L0;
208+
default:
209+
return;
210+
}
211+
}
212+
}
213+
214+
}
215+
216+
})) failed in %sexpect_015.php on line %d
217+
218+
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
219+
class A {
220+
use T1, T2 {
221+
T1::foo insteadof foo;
222+
T2::foo as bar;
223+
}
224+
use T3;
225+
}
226+
227+
})) failed in %sexpect_015.php on line %d
228+
229+
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
230+
declare(A = 1, B = 2);
231+
try {
232+
$i++;
233+
} catch ('MyException''e') {
234+
echo 1;
235+
} catch ('Exception''e') {
236+
echo 2;
237+
} finally {
238+
echo 3;
239+
}
240+
})) failed in %sexpect_015.php on line %d

0 commit comments

Comments
 (0)