Skip to content

Commit 78bb532

Browse files
JoelMarceyhhvm-bot
authored andcommitted
Add PHP lang spec tests to HHVM test suite
Summary: We have wanted to do this for a while, so now I am. These are the PHP lang spec tests. I used the PHP 5.x import script as a model to get the tests. But we don't have `good`, `bad`, etc. Instead we have a global `config.skipif` with the tests that are failing and we put a comment as to why they are failing. Key file changes (other than new tests and expect files): ``` hphp/test/README.md hphp/test/run hphp/test/spec/.gitattributes hphp/test/spec/.gitignore hphp/test/tools/find_non_ascii_files.php hphp/test/tools/import_spec_test.py hphp/test/spec/config.skipif (autogenerated by import_spec_test.py) ``` Reviewed By: @paulbiss Differential Revision: D1718437
1 parent ba05737 commit 78bb532

File tree

360 files changed

+28015
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+28015
-11
lines changed

hphp/test/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ all sub-suites.
88
sure, your test doesn't belong here.
99
* slow - Slower full featured tests. Grouped into sub-suites. By default put
1010
your test here.
11+
* spec - Tests associated with the official PHP language specification.
12+
https://github.com/php/php-langspec/
1113
* zend/good - Passing tests from Zend's suite.
1214
* zend/bad - Failing tests from Zend. Fix these and move them to zend/good.
1315
* zend/flakey - Tests which mostly pass but have race conditions or can't be
@@ -24,6 +26,9 @@ all sub-suites.
2426
* Slow tests with the JIT in PGO mode -
2527
`test/run test/slow -m pgo`
2628

29+
* PHP Specification tests with JIT
30+
`test/run test/spec`
31+
2732
* Run everything that is supposed to pass -
2833
`test/run all`
2934

hphp/test/run

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Examples:
5757
# Slow tests in interp mode:
5858
% $argv[0] -m interp test/slow
5959
60+
# PHP specificaion tests in JIT mode:
61+
% $argv[0] test/spec
62+
6063
# Slow closure tests in JIT mode:
6164
% $argv[0] test/slow/closure
6265
@@ -239,6 +242,7 @@ function map_convenience_filename($file) {
239242
$mappage = array(
240243
'quick' => 'hphp/test/quick',
241244
'slow' => 'hphp/test/slow',
245+
'spec' => 'hphp/test/spec',
242246
'debugger' => 'hphp/test/server/debugger/tests',
243247
'http' => 'hphp/test/server/http/tests',
244248
'fastcgi' => 'hphp/test/server/fastcgi/tests',
@@ -281,7 +285,7 @@ function find_tests($files, array $options = null) {
281285
$files = array('quick');
282286
}
283287
if ($files == array('all')) {
284-
$files = array('quick', 'slow', 'zend', 'fastcgi');
288+
$files = array('quick', 'slow', 'spec', 'zend', 'fastcgi');
285289
}
286290
foreach ($files as &$file) {
287291
$file = map_convenience_filename($file);
@@ -822,7 +826,7 @@ function skip_test($options, $test) {
822826
2 => array("pipe", "w"),
823827
);
824828
$pipes = null;
825-
$process = proc_open("$hhvm 2>&1", $descriptorspec, $pipes);
829+
$process = proc_open("$hhvm $test 2>&1", $descriptorspec, $pipes);
826830
if (!is_resource($process)) {
827831
// This is weird. We can't run HHVM but we probably shouldn't skip the test
828832
// since on a broken build everything will show up as skipped and give you a

hphp/test/spec/.gitattributes

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
php-langspec-master.zip binary
2+
tests/classes/dynamic_properties2.php binary
3+
tests/classes/overloading_2.php binary
4+
tests/classes/overloading_properties2.php binary
5+
tests/lexical_structure/tokens/string_literals.php.expectf binary
6+
tests/variables/variable_kinds.php binary
7+
tests/expressions/postfix_operators/post-increment_and_decrement.php.expect binary
8+
tests/expressions/unary_operators/pre-increment_and_decrement.php.expect binary
9+
tests/expressions/assignment_operators/assignment.php.expect binary

hphp/test/spec/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
php-langspec-*/
2+
php-langspec-*.zip
3+
php-langspec-master.zip
4+
all
5+
config.skipif.bak

hphp/test/spec/config.ini

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
hhvm.enable_obj_destruct_call = true
2+
hhvm.enable_zend_compat = true
3+
hhvm.http.slow_query_threshold = 0
4+
hhvm.mysql.slow_query_threshold = 0
5+
hhvm.mysql.typed_results = false

hphp/test/spec/config.skipif

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
$need_fix = array(
4+
"./tests/expressions/multiplicative_operators/multiplication_division_modulus.php", // we use +0 instead of -0 in float situations (http://3v4l.org/OdO04), amongst other things.
5+
"./tests/expressions/unary_operators/cast.php", // we cast INF to int differently. PHP is also inconsistent between PHP 5.x and PHP 7 too. (http://3v4l.org/ZoHVJ)
6+
"./tests/constants/constants.php", // we have to decide whether we want to support case-insensitive constants via a runtime option and also how we want to handle cases like define("TRUE", 999). We throw a notice; php-src does not.
7+
"./tests/expressions/unary_operators/pre-increment_and_decrement.php", // we just do certain things differently when it comes to pre and post inc and dec than PHP 5.x. Period.
8+
"./tests/expressions/postfix_operators/post-increment_and_decrement.php", // We are incrementing and decrementing strings differently than PHP 5.x
9+
"./tests/classes/__php_incomplete_class.php", // print_r differences from php-src
10+
"./tests/exception_handling/exception_class.php", //don't provide the parameters passed to a function in our exception trace
11+
"./tests/exception_handling/exception_class_experiment_1.php", // don't provide the parameters passed to a function in our exception trace
12+
"./tests/expressions/postfix_operators/subscripting.php", // we warn on using scalar value as an array. PHP 5.x does not.
13+
"./tests/exception_handling/exception_class_from_within_a_class.php", // don't provide the parameters passed to a function in our exception trace
14+
"./tests/expressions/postfix_operators/subscripting_2.php", // No notice like: "Notice: Indirect modification of overloaded element of C10 has no effect"
15+
"./tests/functions/anonymous_functions.php", // The way we deal with parameters that look optional but are really required is different than with PHP 5.x (http://3v4l.org/rvBtd)
16+
"./tests/exception_handling/exception_class_using_conditional_functions.php", // don't provide the parameters passed to a function in our exception trace
17+
"./tests/expressions/primary_expressions/intrinsics_empty.php", // empty on a non-existent intrinsic is returning false (php-src returns true)
18+
"./tests/exception_handling/set_exception_handler.php", // don't provide the parameters passed to a function in our exception trace
19+
"./tests/expressions/assignment_operators/assignment.php", // we use +0 instead of -0 in float situations (http://3v4l.org/OdO04), amongst other things.
20+
"./tests/expressions/coalesce_operator/coalesce.php", //we don't support that operator yet. Only PHP7 does now
21+
"./tests/types/string/numeric_like_strings.php", // We don't handle operations with numeric like strings the same (http://3v4l.org/DsFTd)
22+
"./tests/classes/sleep_and_wakeup.php", // php-src destructs one more object than HHVM
23+
"./tests/variables/variable_names.php", // Ordering, but this might be an ok difference with php-src. Could be an easy fix
24+
);
25+
$test = "./" . substr($argv[1], strrpos($argv[1], "tests/"));
26+
if (in_array($test, $need_fix)) {
27+
echo "skip";
28+
}
+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?php
2+
3+
/*
4+
+-------------------------------------------------------------+
5+
| Copyright (c) 2014 Facebook, Inc. (http://www.facebook.com) |
6+
+-------------------------------------------------------------+
7+
*/
8+
9+
error_reporting(-1);
10+
11+
echo "================= array of zero elements is possible =================\n";
12+
13+
$v = array();
14+
var_dump($v);
15+
$v = [];
16+
var_dump($v);
17+
18+
echo "================= array of 1 element is possible =================\n";
19+
20+
$v = array(TRUE);
21+
var_dump($v);
22+
$v = [TRUE];
23+
var_dump($v);
24+
$v = array(0 => TRUE); // specify explicit key
25+
var_dump($v);
26+
$v = [0 => TRUE];
27+
var_dump($v);
28+
29+
echo "================= array of 2 elements each having the same type =================\n";
30+
31+
$v = array(123, -56);
32+
var_dump($v);
33+
$v = [123, -56];
34+
var_dump($v);
35+
$v = array(0 => 123, 1 => -56); // specify explicit keys
36+
var_dump($v);
37+
$v = [0 => 123, 1 => -56];
38+
var_dump($v);
39+
40+
$pos = 1;
41+
$v = array(0 => 123, $pos => -56); // specify explicit keys
42+
var_dump($v);
43+
$v = [0 => 123, $pos => -56]; // key can be a variable
44+
var_dump($v);
45+
46+
$i = 10;
47+
$v = array(0 => 123, $pos => -56); // specify explicit keys
48+
var_dump($v);
49+
$v = [$i - 10 => 123, $i - 9 => -56]; // key can be a runtime expression
50+
var_dump($v);
51+
52+
echo "================= array of 5 elements each having different type =================\n";
53+
54+
$v = array(NULL, FALSE, 123, 34e12, "Hello");
55+
var_dump($v);
56+
$v = [NULL, FALSE, 123, 34e12, "Hello"];
57+
var_dump($v);
58+
$v = array(0 => NULL, 1 => FALSE, 2 => 123, 3 => 34e12, 4 => "Hello");
59+
var_dump($v);
60+
$v = [0 => NULL, 1 => FALSE, 2 => 123, 3 => 34e12, 4 => "Hello"];
61+
var_dump($v);
62+
$v = array(NULL, 1 => FALSE, 123, 3 => 34e12, "Hello"); // some keys default, others not
63+
var_dump($v);
64+
$v = [NULL, 1 => FALSE, 123, 3 => 34e12, "Hello"];
65+
var_dump($v);
66+
67+
echo "================= trailing comma permitted if list has at least one entry =================\n";
68+
69+
// $v = array(,); // error
70+
// $v = [,]; // error
71+
72+
$v = array(TRUE,);
73+
var_dump($v);
74+
$v = [TRUE,];
75+
var_dump($v);
76+
$v = array(0 => TRUE,);
77+
var_dump($v);
78+
$v = [0 => TRUE,];
79+
var_dump($v);
80+
81+
$v = array(123, -56,);
82+
var_dump($v);
83+
$v = [123, -56,];
84+
var_dump($v);
85+
$v = array(0 => 123, 1 => -56,);
86+
var_dump($v);
87+
$v = [0 => 123, 1 => -56,];
88+
var_dump($v);
89+
90+
echo "================= specify keys in arbitrary order, initial values of runtime expressions, leave gaps =================\n";
91+
92+
$i = 6;
93+
$j = 12;
94+
$v = array(7 => 123, 3 => $i, 6 => ++$j);
95+
var_dump($v);
96+
97+
$i = 6;
98+
$j = 12;
99+
$v = [7 => 123, 3 => $i, 6 => ++$j];
100+
var_dump($v);
101+
102+
foreach($v as $e) // only has 3 elements ([3], [6], and [7]), not 8 ([0]-[7])
103+
{
104+
echo $e.' ';
105+
}
106+
echo "\n";
107+
108+
echo "\$v[1] is >".$v[1]."<\n"; var_dump($v1[1]); // access non-existant element
109+
echo "\$v[4] is >".$v[4]."<\n"; var_dump($v1[4]); // access non-existant element
110+
111+
$v[1] = TRUE; // increases array to 4 elements
112+
$v[4] = 99; // increases array to 5 elements
113+
var_dump($v);
114+
foreach($v as $e) // now has 5 elements
115+
{
116+
echo $e.' ';
117+
}
118+
echo "\n";
119+
120+
echo "================= duplicate keys allowed, but lexically final one used =================\n";
121+
122+
$v = array(2 => 23, 1 => 10, 2 => 46, 1.9 => 6); // key 1.9 is truncated to key 1
123+
var_dump($v);
124+
125+
echo "================= string keys can be expressions too =================\n";
126+
127+
$s1 = "color";
128+
$s2 = "shape";
129+
$v = array($s1 => "red", $s2 => "square");
130+
var_dump($v);
131+
132+
echo "================= can mix int and string keys =================\n";
133+
134+
// "4" as key is taken as key 4
135+
// 9.2 as key is truncated to key 9
136+
// "12.8" as key is treated as key with that string, NOT truncated and made int 12
137+
// NULL as key becomes key ""
138+
139+
$v = array("red" => 10, "4" => 3, 9.2 => 5, "12.8" => 111, NULL => 1);
140+
var_dump($v);
141+
142+
$v = array(FALSE => -4); // FALSE as key becomes key 0
143+
var_dump($v);
144+
$v = array("" => -3);
145+
var_dump($v);
146+
$v = array(INF => 21); // INF as key becomes key 0/IntMin/0 (imp-def?)
147+
var_dump($v);
148+
$v = array(-INF => -1); // -INF as key becomes key 0/IntMin/IntMin (imp-def?)
149+
var_dump($v);
150+
$v = array(NAN => 123); // NAN as key becomes key of IntMin/IntMin/IntMin (imp-def?)
151+
var_dump($v);
152+
153+
echo "================= arrays some of whose elements are arrays, and so on =================\n";
154+
155+
$c = array("red", "white", "blue");
156+
$v = array(10, $c, NULL, array(FALSE, NULL, $c));
157+
var_dump($v);
158+
159+
$v = [[2,4,6,8], [5,10], [100,200,300]];
160+
var_dump($v);
161+
162+
echo "================= see if int keys can be specified in any base. =================\n";
163+
164+
$v = [12 => 10, 0x10 => 16, 010 => 8, 0b11 => 2];
165+
var_dump($v);
166+
167+
echo "================= what about int-looking strings? It appears not. =================\n";
168+
169+
$v = ["12" => 10, "0x10" => 16, "010" => 8, "0b11" => 2];
170+
var_dump($v);
171+
172+
echo "================= iterate using foreach and compare with for loop =================\n";
173+
174+
$v = array(2 => TRUE, 0 => 123, 1 => 34.5, -1 => "red");
175+
var_dump($v);
176+
foreach($v as $e)
177+
{
178+
echo $e.' ';
179+
}
180+
echo "\n";
181+
for ($i = -1; $i <= 2; ++$i)
182+
{
183+
echo $v[$i].' ';
184+
}
185+
echo "\n";
186+
187+
echo "================= remove some elements from an array =================\n";
188+
189+
$v = array("red" => TRUE, 123, 9 => 34e12, "Hello");
190+
var_dump($v);
191+
unset($v[0], $v["red"]);
192+
var_dump($v);

0 commit comments

Comments
 (0)