Skip to content

Commit

Permalink
Add PHP lang spec tests to HHVM test suite
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JoelMarcey authored and hhvm-bot committed Dec 18, 2014
1 parent ba05737 commit 78bb532
Show file tree
Hide file tree
Showing 360 changed files with 28,015 additions and 11 deletions.
5 changes: 5 additions & 0 deletions hphp/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ all sub-suites.
sure, your test doesn't belong here.
* slow - Slower full featured tests. Grouped into sub-suites. By default put
your test here.
* spec - Tests associated with the official PHP language specification.
https://github.com/php/php-langspec/
* zend/good - Passing tests from Zend's suite.
* zend/bad - Failing tests from Zend. Fix these and move them to zend/good.
* zend/flakey - Tests which mostly pass but have race conditions or can't be
Expand All @@ -24,6 +26,9 @@ all sub-suites.
* Slow tests with the JIT in PGO mode -
`test/run test/slow -m pgo`

* PHP Specification tests with JIT
`test/run test/spec`

* Run everything that is supposed to pass -
`test/run all`

Expand Down
8 changes: 6 additions & 2 deletions hphp/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Examples:
# Slow tests in interp mode:
% $argv[0] -m interp test/slow
# PHP specificaion tests in JIT mode:
% $argv[0] test/spec
# Slow closure tests in JIT mode:
% $argv[0] test/slow/closure
Expand Down Expand Up @@ -239,6 +242,7 @@ function map_convenience_filename($file) {
$mappage = array(
'quick' => 'hphp/test/quick',
'slow' => 'hphp/test/slow',
'spec' => 'hphp/test/spec',
'debugger' => 'hphp/test/server/debugger/tests',
'http' => 'hphp/test/server/http/tests',
'fastcgi' => 'hphp/test/server/fastcgi/tests',
Expand Down Expand Up @@ -281,7 +285,7 @@ function find_tests($files, array $options = null) {
$files = array('quick');
}
if ($files == array('all')) {
$files = array('quick', 'slow', 'zend', 'fastcgi');
$files = array('quick', 'slow', 'spec', 'zend', 'fastcgi');
}
foreach ($files as &$file) {
$file = map_convenience_filename($file);
Expand Down Expand Up @@ -822,7 +826,7 @@ function skip_test($options, $test) {
2 => array("pipe", "w"),
);
$pipes = null;
$process = proc_open("$hhvm 2>&1", $descriptorspec, $pipes);
$process = proc_open("$hhvm $test 2>&1", $descriptorspec, $pipes);
if (!is_resource($process)) {
// This is weird. We can't run HHVM but we probably shouldn't skip the test
// since on a broken build everything will show up as skipped and give you a
Expand Down
9 changes: 9 additions & 0 deletions hphp/test/spec/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
php-langspec-master.zip binary
tests/classes/dynamic_properties2.php binary
tests/classes/overloading_2.php binary
tests/classes/overloading_properties2.php binary
tests/lexical_structure/tokens/string_literals.php.expectf binary
tests/variables/variable_kinds.php binary
tests/expressions/postfix_operators/post-increment_and_decrement.php.expect binary
tests/expressions/unary_operators/pre-increment_and_decrement.php.expect binary
tests/expressions/assignment_operators/assignment.php.expect binary
5 changes: 5 additions & 0 deletions hphp/test/spec/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
php-langspec-*/
php-langspec-*.zip
php-langspec-master.zip
all
config.skipif.bak
5 changes: 5 additions & 0 deletions hphp/test/spec/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hhvm.enable_obj_destruct_call = true
hhvm.enable_zend_compat = true
hhvm.http.slow_query_threshold = 0
hhvm.mysql.slow_query_threshold = 0
hhvm.mysql.typed_results = false
28 changes: 28 additions & 0 deletions hphp/test/spec/config.skipif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

$need_fix = array(
"./tests/expressions/multiplicative_operators/multiplication_division_modulus.php", // we use +0 instead of -0 in float situations (http://3v4l.org/OdO04), amongst other things.
"./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)
"./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.
"./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.
"./tests/expressions/postfix_operators/post-increment_and_decrement.php", // We are incrementing and decrementing strings differently than PHP 5.x
"./tests/classes/__php_incomplete_class.php", // print_r differences from php-src
"./tests/exception_handling/exception_class.php", //don't provide the parameters passed to a function in our exception trace
"./tests/exception_handling/exception_class_experiment_1.php", // don't provide the parameters passed to a function in our exception trace
"./tests/expressions/postfix_operators/subscripting.php", // we warn on using scalar value as an array. PHP 5.x does not.
"./tests/exception_handling/exception_class_from_within_a_class.php", // don't provide the parameters passed to a function in our exception trace
"./tests/expressions/postfix_operators/subscripting_2.php", // No notice like: "Notice: Indirect modification of overloaded element of C10 has no effect"
"./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)
"./tests/exception_handling/exception_class_using_conditional_functions.php", // don't provide the parameters passed to a function in our exception trace
"./tests/expressions/primary_expressions/intrinsics_empty.php", // empty on a non-existent intrinsic is returning false (php-src returns true)
"./tests/exception_handling/set_exception_handler.php", // don't provide the parameters passed to a function in our exception trace
"./tests/expressions/assignment_operators/assignment.php", // we use +0 instead of -0 in float situations (http://3v4l.org/OdO04), amongst other things.
"./tests/expressions/coalesce_operator/coalesce.php", //we don't support that operator yet. Only PHP7 does now
"./tests/types/string/numeric_like_strings.php", // We don't handle operations with numeric like strings the same (http://3v4l.org/DsFTd)
"./tests/classes/sleep_and_wakeup.php", // php-src destructs one more object than HHVM
"./tests/variables/variable_names.php", // Ordering, but this might be an ok difference with php-src. Could be an easy fix
);
$test = "./" . substr($argv[1], strrpos($argv[1], "tests/"));
if (in_array($test, $need_fix)) {
echo "skip";
}
192 changes: 192 additions & 0 deletions hphp/test/spec/tests/arrays/arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?php

/*
+-------------------------------------------------------------+
| Copyright (c) 2014 Facebook, Inc. (http://www.facebook.com) |
+-------------------------------------------------------------+
*/

error_reporting(-1);

echo "================= array of zero elements is possible =================\n";

$v = array();
var_dump($v);
$v = [];
var_dump($v);

echo "================= array of 1 element is possible =================\n";

$v = array(TRUE);
var_dump($v);
$v = [TRUE];
var_dump($v);
$v = array(0 => TRUE); // specify explicit key
var_dump($v);
$v = [0 => TRUE];
var_dump($v);

echo "================= array of 2 elements each having the same type =================\n";

$v = array(123, -56);
var_dump($v);
$v = [123, -56];
var_dump($v);
$v = array(0 => 123, 1 => -56); // specify explicit keys
var_dump($v);
$v = [0 => 123, 1 => -56];
var_dump($v);

$pos = 1;
$v = array(0 => 123, $pos => -56); // specify explicit keys
var_dump($v);
$v = [0 => 123, $pos => -56]; // key can be a variable
var_dump($v);

$i = 10;
$v = array(0 => 123, $pos => -56); // specify explicit keys
var_dump($v);
$v = [$i - 10 => 123, $i - 9 => -56]; // key can be a runtime expression
var_dump($v);

echo "================= array of 5 elements each having different type =================\n";

$v = array(NULL, FALSE, 123, 34e12, "Hello");
var_dump($v);
$v = [NULL, FALSE, 123, 34e12, "Hello"];
var_dump($v);
$v = array(0 => NULL, 1 => FALSE, 2 => 123, 3 => 34e12, 4 => "Hello");
var_dump($v);
$v = [0 => NULL, 1 => FALSE, 2 => 123, 3 => 34e12, 4 => "Hello"];
var_dump($v);
$v = array(NULL, 1 => FALSE, 123, 3 => 34e12, "Hello"); // some keys default, others not
var_dump($v);
$v = [NULL, 1 => FALSE, 123, 3 => 34e12, "Hello"];
var_dump($v);

echo "================= trailing comma permitted if list has at least one entry =================\n";

// $v = array(,); // error
// $v = [,]; // error

$v = array(TRUE,);
var_dump($v);
$v = [TRUE,];
var_dump($v);
$v = array(0 => TRUE,);
var_dump($v);
$v = [0 => TRUE,];
var_dump($v);

$v = array(123, -56,);
var_dump($v);
$v = [123, -56,];
var_dump($v);
$v = array(0 => 123, 1 => -56,);
var_dump($v);
$v = [0 => 123, 1 => -56,];
var_dump($v);

echo "================= specify keys in arbitrary order, initial values of runtime expressions, leave gaps =================\n";

$i = 6;
$j = 12;
$v = array(7 => 123, 3 => $i, 6 => ++$j);
var_dump($v);

$i = 6;
$j = 12;
$v = [7 => 123, 3 => $i, 6 => ++$j];
var_dump($v);

foreach($v as $e) // only has 3 elements ([3], [6], and [7]), not 8 ([0]-[7])
{
echo $e.' ';
}
echo "\n";

echo "\$v[1] is >".$v[1]."<\n"; var_dump($v1[1]); // access non-existant element
echo "\$v[4] is >".$v[4]."<\n"; var_dump($v1[4]); // access non-existant element

$v[1] = TRUE; // increases array to 4 elements
$v[4] = 99; // increases array to 5 elements
var_dump($v);
foreach($v as $e) // now has 5 elements
{
echo $e.' ';
}
echo "\n";

echo "================= duplicate keys allowed, but lexically final one used =================\n";

$v = array(2 => 23, 1 => 10, 2 => 46, 1.9 => 6); // key 1.9 is truncated to key 1
var_dump($v);

echo "================= string keys can be expressions too =================\n";

$s1 = "color";
$s2 = "shape";
$v = array($s1 => "red", $s2 => "square");
var_dump($v);

echo "================= can mix int and string keys =================\n";

// "4" as key is taken as key 4
// 9.2 as key is truncated to key 9
// "12.8" as key is treated as key with that string, NOT truncated and made int 12
// NULL as key becomes key ""

$v = array("red" => 10, "4" => 3, 9.2 => 5, "12.8" => 111, NULL => 1);
var_dump($v);

$v = array(FALSE => -4); // FALSE as key becomes key 0
var_dump($v);
$v = array("" => -3);
var_dump($v);
$v = array(INF => 21); // INF as key becomes key 0/IntMin/0 (imp-def?)
var_dump($v);
$v = array(-INF => -1); // -INF as key becomes key 0/IntMin/IntMin (imp-def?)
var_dump($v);
$v = array(NAN => 123); // NAN as key becomes key of IntMin/IntMin/IntMin (imp-def?)
var_dump($v);

echo "================= arrays some of whose elements are arrays, and so on =================\n";

$c = array("red", "white", "blue");
$v = array(10, $c, NULL, array(FALSE, NULL, $c));
var_dump($v);

$v = [[2,4,6,8], [5,10], [100,200,300]];
var_dump($v);

echo "================= see if int keys can be specified in any base. =================\n";

$v = [12 => 10, 0x10 => 16, 010 => 8, 0b11 => 2];
var_dump($v);

echo "================= what about int-looking strings? It appears not. =================\n";

$v = ["12" => 10, "0x10" => 16, "010" => 8, "0b11" => 2];
var_dump($v);

echo "================= iterate using foreach and compare with for loop =================\n";

$v = array(2 => TRUE, 0 => 123, 1 => 34.5, -1 => "red");
var_dump($v);
foreach($v as $e)
{
echo $e.' ';
}
echo "\n";
for ($i = -1; $i <= 2; ++$i)
{
echo $v[$i].' ';
}
echo "\n";

echo "================= remove some elements from an array =================\n";

$v = array("red" => TRUE, 123, 9 => 34e12, "Hello");
var_dump($v);
unset($v[0], $v["red"]);
var_dump($v);
Loading

0 comments on commit 78bb532

Please sign in to comment.