3 error_reporting(E_ALL | E_STRICT);
4 ini_set('short_open_tag', false);
6 if ('cli' !== php_sapi_name()) {
7 die('This script is designed for running on the command line.');
10 function showHelp($error) {
13 This script has to be called with the following signature:
15 php run.php [--no-progress] testType pathToTestFiles
17 The test type must be one of: PHP5, PHP7 or Symfony.
19 The following options are available:
21 --no-progress Disables showing which file is currently tested.
30 // remove script name from argv
33 foreach ($argv as $arg) {
34 if ('-' === $arg[0]) {
41 if (count($arguments) !== 2) {
42 showHelp('Too little arguments passed!');
47 foreach ($options as $option) {
48 if ($option === '--no-progress') {
49 $showProgress = false;
50 } elseif ($option === '--verbose') {
53 showHelp('Invalid option passed!');
57 $testType = $arguments[0];
63 $fileFilter = function($path) {
64 return preg_match('~\.php(?:\.cache)?$~', $path) && false === strpos($path, 'skeleton');
66 $codeExtractor = function($file, $code) {
72 $version = $testType === 'PHP5' ? 'Php5' : 'Php7';
73 $fileFilter = function($path) {
74 return preg_match('~\.phpt$~', $path);
76 $codeExtractor = function($file, $code) {
80 | ext.skeleton.tests.001
81 # multibyte encoded files
82 | ext.mbstring.tests.zend_multibyte-01
83 | Zend.tests.multibyte.multibyte_encoding_001
84 | Zend.tests.multibyte.multibyte_encoding_004
85 | Zend.tests.multibyte.multibyte_encoding_005
86 # pretty print difference due to INF vs 1e1000
87 | ext.standard.tests.general_functions.bug27678
89 # pretty print differences due to negative LNumbers
90 | Zend.tests.neg_num_string
92 # pretty print difference due to nop statements
93 | ext.mbstring.tests.htmlent
94 | ext.standard.tests.file.fread_basic
95 )\.phpt$~x', $file)) {
99 if (!preg_match('~--FILE--\s*(.*?)--[A-Z]+--~s', $code, $matches)) {
102 if (preg_match('~--EXPECT(?:F|REGEX)?--\s*(?:Parse|Fatal) error~', $code)) {
110 showHelp('Test type must be one of: PHP5, PHP7 or Symfony');
113 require_once dirname(__FILE__) . '/../lib/PhpParser/Autoloader.php';
114 PhpParser\Autoloader::register();
116 $parserName = 'PhpParser\Parser\\' . $version;
117 $parser = new $parserName(new PhpParser\Lexer\Emulative);
118 $prettyPrinter = new PhpParser\PrettyPrinter\Standard;
119 $nodeDumper = new PhpParser\NodeDumper;
121 $parseFail = $ppFail = $compareFail = $count = 0;
123 $readTime = $parseTime = $ppTime = $reparseTime = $compareTime = 0;
124 $totalStartTime = microtime(true);
126 foreach (new RecursiveIteratorIterator(
127 new RecursiveDirectoryIterator($dir),
128 RecursiveIteratorIterator::LEAVES_ONLY)
130 if (!$fileFilter($file)) {
134 $startTime = microtime(true);
135 $code = file_get_contents($file);
136 $readTime += microtime(true) - $startTime;
138 if (null === $code = $codeExtractor($file, $code)) {
147 echo substr(str_pad('Testing file ' . $count . ': ' . substr($file, strlen($dir)), 79), 0, 79), "\r";
151 $startTime = microtime(true);
152 $stmts = $parser->parse($code);
153 $parseTime += microtime(true) - $startTime;
155 $startTime = microtime(true);
156 $code = '<?php' . "\n" . $prettyPrinter->prettyPrint($stmts);
157 $ppTime += microtime(true) - $startTime;
160 $startTime = microtime(true);
161 $ppStmts = $parser->parse($code);
162 $reparseTime += microtime(true) - $startTime;
164 $startTime = microtime(true);
165 $same = $nodeDumper->dump($stmts) == $nodeDumper->dump($ppStmts);
166 $compareTime += microtime(true) - $startTime;
169 echo $file, ":\n Result of initial parse and parse after pretty print differ\n";
171 echo "Pretty printer output:\n=====\n$code\n=====\n\n";
176 } catch (PhpParser\Error $e) {
177 echo $file, ":\n Parse of pretty print failed with message: {$e->getMessage()}\n";
179 echo "Pretty printer output:\n=====\n$code\n=====\n\n";
184 } catch (PhpParser\Error $e) {
185 echo $file, ":\n Parse failed with message: {$e->getMessage()}\n";
191 if (0 === $parseFail && 0 === $ppFail && 0 === $compareFail) {
193 echo "\n\n", 'All tests passed.', "\n";
196 echo "\n\n", '==========', "\n\n", 'There were: ', "\n";
197 if (0 !== $parseFail) {
198 echo ' ', $parseFail, ' parse failures.', "\n";
201 echo ' ', $ppFail, ' pretty print failures.', "\n";
203 if (0 !== $compareFail) {
204 echo ' ', $compareFail, ' compare failures.', "\n";
209 'Tested files: ', $count, "\n",
211 'Reading files took: ', $readTime, "\n",
212 'Parsing took: ', $parseTime, "\n",
213 'Pretty printing took: ', $ppTime, "\n",
214 'Reparsing took: ', $reparseTime, "\n",
215 'Comparing took: ', $compareTime, "\n",
217 'Total time: ', microtime(true) - $totalStartTime, "\n",
218 'Maximum memory usage: ', memory_get_peak_usage(true), "\n";