2011-05-29 17:33:03 +02:00
|
|
|
<?php
|
|
|
|
|
2011-10-20 22:36:10 +02:00
|
|
|
error_reporting(E_ALL | E_STRICT);
|
|
|
|
ini_set('short_open_tag', false);
|
|
|
|
|
2011-10-19 17:53:40 +02:00
|
|
|
if ('cli' !== php_sapi_name()) {
|
|
|
|
die('This script is designed for running on the command line.');
|
|
|
|
}
|
|
|
|
|
2012-05-05 12:22:23 +02:00
|
|
|
function showHelp($error) {
|
|
|
|
die($error . "\n\n" .
|
|
|
|
<<<OUTPUT
|
|
|
|
This script has to be called with the following signature:
|
|
|
|
|
|
|
|
php run.php [--no-progress] testType pathToTestFiles
|
|
|
|
|
|
|
|
The test type can be either "Symfony" or "PHP".
|
|
|
|
|
|
|
|
The following options are available:
|
|
|
|
|
|
|
|
--no-progress Disables showing which file is currently tested.
|
|
|
|
OUTPUT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$options = array();
|
|
|
|
$arguments = array();
|
|
|
|
|
|
|
|
// remove script name from argv
|
|
|
|
array_shift($argv);
|
|
|
|
|
|
|
|
foreach ($argv as $arg) {
|
|
|
|
if ('-' === $arg[0]) {
|
|
|
|
$options[] = $arg;
|
|
|
|
} else {
|
|
|
|
$arguments[] = $arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($arguments) !== 2) {
|
|
|
|
showHelp('Too little arguments passed!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$SHOW_PROGRESS = true;
|
|
|
|
if (count($options) > 0) {
|
|
|
|
if (count($options) === 1 && $options[0] === '--no-progress') {
|
|
|
|
$SHOW_PROGRESS = false;
|
|
|
|
} else {
|
|
|
|
showHelp('Invalid option passed!');
|
|
|
|
}
|
2011-10-19 17:53:40 +02:00
|
|
|
}
|
2011-10-17 17:49:24 +02:00
|
|
|
|
2012-05-05 12:22:23 +02:00
|
|
|
$TEST_TYPE = $arguments[0];
|
|
|
|
$DIR = $arguments[1];
|
2011-10-19 17:53:40 +02:00
|
|
|
|
|
|
|
if ('Symfony' === $TEST_TYPE) {
|
2012-01-15 16:36:00 +01:00
|
|
|
function filter_func($path) {
|
2011-10-19 17:53:40 +02:00
|
|
|
return preg_match('~\.php(?:\.cache)?$~', $path) && false === strpos($path, 'skeleton');
|
|
|
|
};
|
|
|
|
} elseif ('PHP' === $TEST_TYPE) {
|
2012-01-15 16:36:00 +01:00
|
|
|
function filter_func($path) {
|
2011-10-19 17:53:40 +02:00
|
|
|
return preg_match('~\.phpt$~', $path);
|
|
|
|
};
|
|
|
|
} else {
|
2012-05-05 12:22:23 +02:00
|
|
|
showHelp('Test type must be either "Symfony" or "PHP"!');
|
2011-10-19 17:53:40 +02:00
|
|
|
}
|
|
|
|
|
2011-09-21 21:43:19 +02:00
|
|
|
require_once dirname(__FILE__) . '/../lib/PHPParser/Autoloader.php';
|
2014-02-06 14:44:16 +01:00
|
|
|
PhpParser\Autoloader::register();
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
|
|
|
|
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
|
|
|
|
$nodeDumper = new PhpParser\NodeDumper;
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2012-05-05 12:22:23 +02:00
|
|
|
$parseFail = $ppFail = $compareFail = $count = 0;
|
2011-06-01 20:00:52 +02:00
|
|
|
|
2011-10-30 12:16:31 +01:00
|
|
|
$readTime = $parseTime = $ppTime = $reparseTime = $compareTime = 0;
|
2011-06-03 17:44:23 +02:00
|
|
|
$totalStartTime = microtime(true);
|
|
|
|
|
2011-05-29 17:33:03 +02:00
|
|
|
foreach (new RecursiveIteratorIterator(
|
|
|
|
new RecursiveDirectoryIterator($DIR),
|
|
|
|
RecursiveIteratorIterator::LEAVES_ONLY)
|
|
|
|
as $file) {
|
2012-01-15 16:36:00 +01:00
|
|
|
if (!filter_func($file)) {
|
2011-05-29 17:33:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-30 12:16:31 +01:00
|
|
|
$startTime = microtime(true);
|
2011-10-19 17:53:40 +02:00
|
|
|
$code = file_get_contents($file);
|
2011-10-30 12:16:31 +01:00
|
|
|
$readTime += microtime(true) - $startTime;
|
2011-10-19 17:53:40 +02:00
|
|
|
|
|
|
|
if ('PHP' === $TEST_TYPE) {
|
2011-10-19 20:04:57 +02:00
|
|
|
if (preg_match('~(?:
|
|
|
|
# skeleton files
|
|
|
|
ext.gmp.tests.001
|
|
|
|
| ext.skeleton.tests.001
|
|
|
|
# multibyte encoded files
|
|
|
|
| ext.mbstring.tests.zend_multibyte-01
|
|
|
|
| Zend.tests.multibyte.multibyte_encoding_001
|
|
|
|
| Zend.tests.multibyte.multibyte_encoding_004
|
|
|
|
| Zend.tests.multibyte.multibyte_encoding_005
|
|
|
|
# token_get_all bug (https://bugs.php.net/bug.php?id=60097)
|
|
|
|
| Zend.tests.bug47516
|
2011-10-30 12:16:31 +01:00
|
|
|
# pretty print difference due to INF vs 1e1000
|
|
|
|
| ext.standard.tests.general_functions.bug27678
|
|
|
|
| tests.lang.bug24640
|
2011-10-19 20:04:57 +02:00
|
|
|
)\.phpt$~x', $file)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-19 17:53:40 +02:00
|
|
|
if (!preg_match('~--FILE--\s*(.*?)--[A-Z]+--~s', $code, $matches)) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-10-19 20:04:57 +02:00
|
|
|
if (preg_match('~--EXPECT(?:F|REGEX)?--\s*(?:Parse|Fatal) error~', $code)) {
|
2011-10-19 17:53:40 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$code = $matches[1];
|
|
|
|
}
|
|
|
|
|
2011-05-31 16:33:11 +02:00
|
|
|
set_time_limit(10);
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-09-05 21:48:00 +02:00
|
|
|
++$count;
|
|
|
|
|
2012-05-05 12:22:23 +02:00
|
|
|
if ($SHOW_PROGRESS) {
|
|
|
|
echo substr(str_pad('Testing file ' . $count . ': ' . substr($file, strlen($DIR)), 79), 0, 79), "\r";
|
|
|
|
}
|
|
|
|
|
2011-06-03 17:44:23 +02:00
|
|
|
try {
|
|
|
|
$startTime = microtime(true);
|
2012-04-29 23:04:06 +02:00
|
|
|
$stmts = $parser->parse($code);
|
2011-06-03 17:44:23 +02:00
|
|
|
$parseTime += microtime(true) - $startTime;
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-06-03 17:44:23 +02:00
|
|
|
$startTime = microtime(true);
|
2011-06-02 22:52:24 +02:00
|
|
|
$code = '<?php' . "\n" . $prettyPrinter->prettyPrint($stmts);
|
2011-06-03 17:44:23 +02:00
|
|
|
$ppTime += microtime(true) - $startTime;
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-06-03 17:44:23 +02:00
|
|
|
try {
|
2011-10-30 12:16:31 +01:00
|
|
|
$startTime = microtime(true);
|
2012-04-29 23:04:06 +02:00
|
|
|
$ppStmts = $parser->parse($code);
|
2011-10-30 12:16:31 +01:00
|
|
|
$reparseTime += microtime(true) - $startTime;
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-06-03 17:44:23 +02:00
|
|
|
$startTime = microtime(true);
|
2011-06-01 20:00:52 +02:00
|
|
|
$same = $nodeDumper->dump($stmts) == $nodeDumper->dump($ppStmts);
|
2011-06-03 17:44:23 +02:00
|
|
|
$compareTime += microtime(true) - $startTime;
|
2011-06-01 20:00:52 +02:00
|
|
|
|
2011-09-05 21:48:00 +02:00
|
|
|
if (!$same) {
|
|
|
|
echo $file, ":\n Result of initial parse and parse after pretty print differ\n";
|
2011-05-29 20:38:36 +02:00
|
|
|
|
|
|
|
++$compareFail;
|
2011-05-29 17:33:03 +02:00
|
|
|
}
|
2014-02-06 14:44:16 +01:00
|
|
|
} catch (PhpParser\Error $e) {
|
2011-09-05 21:48:00 +02:00
|
|
|
echo $file, ":\n Parse of pretty print failed with message: {$e->getMessage()}\n";
|
2011-05-29 20:38:36 +02:00
|
|
|
|
|
|
|
++$ppFail;
|
2011-05-29 17:33:03 +02:00
|
|
|
}
|
2014-02-06 14:44:16 +01:00
|
|
|
} catch (PhpParser\Error $e) {
|
2011-09-05 21:48:00 +02:00
|
|
|
echo $file, ":\n Parse failed with message: {$e->getMessage()}\n";
|
2011-05-29 20:38:36 +02:00
|
|
|
|
|
|
|
++$parseFail;
|
2011-05-29 17:33:03 +02:00
|
|
|
}
|
2011-09-05 21:48:00 +02:00
|
|
|
}
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-09-05 21:48:00 +02:00
|
|
|
if (0 === $parseFail && 0 === $ppFail && 0 === $compareFail) {
|
2012-05-05 12:22:23 +02:00
|
|
|
echo "\n\n", 'All tests passed.', "\n";
|
2011-09-05 21:48:00 +02:00
|
|
|
} else {
|
2012-05-05 12:22:23 +02:00
|
|
|
echo "\n\n", '==========', "\n\n", 'There were: ', "\n";
|
2011-09-05 21:48:00 +02:00
|
|
|
if (0 !== $parseFail) {
|
|
|
|
echo ' ', $parseFail, ' parse failures.', "\n";
|
|
|
|
}
|
|
|
|
if (0 !== $ppFail) {
|
|
|
|
echo ' ', $ppFail, ' pretty print failures.', "\n";
|
|
|
|
}
|
|
|
|
if (0 !== $compareFail) {
|
|
|
|
echo ' ', $compareFail, ' compare failures.', "\n";
|
|
|
|
}
|
2011-05-29 17:33:03 +02:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:48:00 +02:00
|
|
|
echo "\n",
|
|
|
|
'Tested files: ', $count, "\n",
|
|
|
|
"\n",
|
2011-10-30 12:16:31 +01:00
|
|
|
'Reading files took: ', $readTime, "\n",
|
2011-09-05 21:48:00 +02:00
|
|
|
'Parsing took: ', $parseTime, "\n",
|
|
|
|
'Pretty printing took: ', $ppTime, "\n",
|
2011-10-30 12:16:31 +01:00
|
|
|
'Reparsing took: ', $reparseTime, "\n",
|
2011-09-05 21:48:00 +02:00
|
|
|
'Comparing took: ', $compareTime, "\n",
|
|
|
|
"\n",
|
|
|
|
'Total time: ', microtime(true) - $totalStartTime, "\n",
|
2011-10-19 17:53:40 +02:00
|
|
|
'Maximum memory usage: ', memory_get_peak_usage(true), "\n";
|