2011-05-29 17:33:03 +02:00
|
|
|
<?php
|
|
|
|
|
2011-06-05 18:40:04 +02:00
|
|
|
$DIR = '../..';
|
2011-05-29 17:33:03 +02:00
|
|
|
|
|
|
|
function __autoload($class) {
|
|
|
|
is_file($file = '../lib/' . strtr($class, '_', '/') . '.php') && require_once $file;
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:40:04 +02:00
|
|
|
$parser = new PHPParser_Parser;
|
|
|
|
$prettyPrinter = new PHPParser_PrettyPrinter_Zend;
|
|
|
|
$nodeDumper = new PHPParser_NodeDumper;
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-05-31 17:24:01 +02:00
|
|
|
include './testFormatting.html';
|
2011-05-29 20:38:36 +02:00
|
|
|
|
2011-05-31 17:24:01 +02:00
|
|
|
echo '<table>
|
2011-05-29 17:33:03 +02:00
|
|
|
<tr>
|
|
|
|
<td>File</td>
|
|
|
|
<td>Parse</td>
|
|
|
|
<td>PrettyPrint</td>
|
2011-05-29 20:38:36 +02:00
|
|
|
<td>Compare</td>
|
2011-05-29 17:33:03 +02:00
|
|
|
</tr>';
|
|
|
|
|
2011-05-29 20:38:36 +02:00
|
|
|
$parseFail = $parseCount = $ppFail = $ppCount = $compareFail = $compareCount = 0;
|
|
|
|
|
2011-06-01 20:00:52 +02:00
|
|
|
$parseTime = $ppTime = $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) {
|
|
|
|
if ('.php' !== substr($file, -4)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<tr>
|
|
|
|
<td>' . $file . '</td>';
|
|
|
|
|
2011-05-31 16:33:11 +02:00
|
|
|
set_time_limit(10);
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-06-03 17:44:23 +02:00
|
|
|
try {
|
|
|
|
++$parseCount;
|
|
|
|
$startTime = microtime(true);
|
2011-06-05 18:40:04 +02:00
|
|
|
$stmts = $parser->parse(new PHPParser_Lexer(file_get_contents($file)));
|
2011-06-03 17:44:23 +02:00
|
|
|
$parseTime += microtime(true) - $startTime;
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-06-01 20:00:52 +02:00
|
|
|
++$ppCount;
|
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-06-05 18:40:04 +02:00
|
|
|
$ppStmts = $parser->parse(new PHPParser_Lexer($code));
|
2011-05-29 17:33:03 +02:00
|
|
|
|
2011-05-29 20:38:36 +02:00
|
|
|
++$compareCount;
|
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
|
|
|
|
|
|
|
if ($same) {
|
2011-05-29 17:33:03 +02:00
|
|
|
echo '
|
|
|
|
<td class="pass">PASS</td>
|
|
|
|
<td class="pass">PASS</td>
|
|
|
|
<td class="pass">PASS</td>
|
2011-06-01 22:37:10 +02:00
|
|
|
</tr>';
|
|
|
|
} else {
|
2011-05-29 17:33:03 +02:00
|
|
|
echo '
|
|
|
|
<td class="pass">PASS</td>
|
|
|
|
<td class="pass">PASS</td>
|
|
|
|
<td class="fail">FAIL</td>
|
|
|
|
</tr>';
|
2011-05-29 20:38:36 +02:00
|
|
|
|
|
|
|
++$compareFail;
|
2011-05-29 17:33:03 +02:00
|
|
|
}
|
2011-06-05 18:40:04 +02:00
|
|
|
} catch (PHPParser_ParseErrorException $e) {
|
2011-05-29 17:33:03 +02:00
|
|
|
echo '
|
|
|
|
<td class="pass">PASS</td>
|
|
|
|
<td class="fail">FAIL</td>
|
|
|
|
<td></td>
|
2011-06-03 17:44:23 +02:00
|
|
|
</tr>
|
|
|
|
<tr class="failReason"><td colspan="4">' . $e->getMessage() . '</td></tr>';
|
2011-05-29 20:38:36 +02:00
|
|
|
|
|
|
|
++$ppFail;
|
2011-05-29 17:33:03 +02:00
|
|
|
}
|
2011-06-05 18:40:04 +02:00
|
|
|
} catch (PHPParser_ParseErrorException $e) {
|
2011-05-29 17:33:03 +02:00
|
|
|
echo '
|
|
|
|
<td class="fail">FAIL</td>
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
</tr>
|
2011-06-03 17:44:23 +02:00
|
|
|
<tr class="failReason"><td colspan="4">' . $e->getMessage() . '</td></tr>';
|
2011-05-29 20:38:36 +02:00
|
|
|
|
|
|
|
++$parseFail;
|
2011-05-29 17:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
2011-05-29 20:38:36 +02:00
|
|
|
<tr>
|
|
|
|
<td>Fail / Total:</td>
|
|
|
|
<td><span class="failCount">' . $parseFail . '</span> / ' . $parseCount . '</td>
|
|
|
|
<td><span class="failCount">' . $ppFail . '</span> / ' . $ppCount . '</td>
|
|
|
|
<td><span class="failCount">' . $compareFail . '</span> / ' . $compareCount . '</td>
|
|
|
|
</tr>
|
2011-06-01 20:00:52 +02:00
|
|
|
<tr>
|
|
|
|
<td>Time:</td>
|
|
|
|
<td>' . $parseTime . '</td>
|
|
|
|
<td>' . $ppTime . '</td>
|
|
|
|
<td>' . $compareTime . '</td>
|
|
|
|
</tr>
|
2011-05-29 17:33:03 +02:00
|
|
|
</table>';
|
|
|
|
|
2011-06-01 20:00:52 +02:00
|
|
|
echo 'Total time: ', microtime(true) - $totalStartTime, '<br />',
|
|
|
|
'Maximum memory usage: ', memory_get_peak_usage(true);
|