mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-30 04:19:30 +01:00
Support running against PHP 7 testsuite
This commit is contained in:
parent
bc21514ecf
commit
f3f24e03ae
@ -165,7 +165,7 @@ namespace Baz {
|
||||
}
|
||||
EOC;
|
||||
|
||||
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
|
||||
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative);
|
||||
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
|
||||
$traverser = new PhpParser\NodeTraverser;
|
||||
$traverser->addVisitor(new NameResolver);
|
||||
@ -255,7 +255,7 @@ try {
|
||||
}
|
||||
EOC;
|
||||
|
||||
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
|
||||
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative);
|
||||
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
|
||||
$traverser = new PhpParser\NodeTraverser;
|
||||
$traverser->addVisitor(new NameResolver);
|
||||
@ -389,7 +389,7 @@ use Bar\Baz;
|
||||
$test = new baz();
|
||||
EOC;
|
||||
|
||||
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
|
||||
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative);
|
||||
$stmts = $parser->parse($source);
|
||||
|
||||
$traverser = new PhpParser\NodeTraverser;
|
||||
@ -417,7 +417,7 @@ class Bar
|
||||
}
|
||||
EOC;
|
||||
|
||||
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
|
||||
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative);
|
||||
$stmts = $parser->parse($source);
|
||||
|
||||
$traverser = new PhpParser\NodeTraverser;
|
||||
|
@ -147,7 +147,7 @@ CODE;
|
||||
</AST>
|
||||
XML;
|
||||
|
||||
$parser = new PhpParser\Parser(new PhpParser\Lexer);
|
||||
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer);
|
||||
$serializer = new XML;
|
||||
|
||||
$code = str_replace("\r\n", "\n", $code);
|
||||
|
@ -41,55 +41,35 @@ if (count($arguments) !== 2) {
|
||||
showHelp('Too little arguments passed!');
|
||||
}
|
||||
|
||||
$SHOW_PROGRESS = true;
|
||||
$showProgress = true;
|
||||
if (count($options) > 0) {
|
||||
if (count($options) === 1 && $options[0] === '--no-progress') {
|
||||
$SHOW_PROGRESS = false;
|
||||
$showProgress = false;
|
||||
} else {
|
||||
showHelp('Invalid option passed!');
|
||||
}
|
||||
}
|
||||
|
||||
$TEST_TYPE = $arguments[0];
|
||||
$DIR = $arguments[1];
|
||||
$testType = $arguments[0];
|
||||
$dir = $arguments[1];
|
||||
|
||||
if ('Symfony' === $TEST_TYPE) {
|
||||
function filter_func($path) {
|
||||
switch ($testType) {
|
||||
case 'Symfony':
|
||||
$version = 'Php5';
|
||||
$fileFilter = function($path) {
|
||||
return preg_match('~\.php(?:\.cache)?$~', $path) && false === strpos($path, 'skeleton');
|
||||
};
|
||||
} elseif ('PHP' === $TEST_TYPE) {
|
||||
function filter_func($path) {
|
||||
$codeExtractor = function($file, $code) {
|
||||
return $code;
|
||||
};
|
||||
break;
|
||||
case 'PHP5':
|
||||
case 'PHP7':
|
||||
$version = $testType === 'PHP5' ? 'Php5' : 'Php7';
|
||||
$fileFilter = function($path) {
|
||||
return preg_match('~\.phpt$~', $path);
|
||||
};
|
||||
} else {
|
||||
showHelp('Test type must be either "Symfony" or "PHP"!');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../lib/PhpParser/Autoloader.php';
|
||||
PhpParser\Autoloader::register();
|
||||
|
||||
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
|
||||
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
|
||||
$nodeDumper = new PhpParser\NodeDumper;
|
||||
|
||||
$parseFail = $ppFail = $compareFail = $count = 0;
|
||||
|
||||
$readTime = $parseTime = $ppTime = $reparseTime = $compareTime = 0;
|
||||
$totalStartTime = microtime(true);
|
||||
|
||||
foreach (new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($DIR),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY)
|
||||
as $file) {
|
||||
if (!filter_func($file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
$code = file_get_contents($file);
|
||||
$readTime += microtime(true) - $startTime;
|
||||
|
||||
if ('PHP' === $TEST_TYPE) {
|
||||
$codeExtractor = function($file, $code) {
|
||||
if (preg_match('~(?:
|
||||
# skeleton files
|
||||
ext.gmp.tests.001
|
||||
@ -105,25 +85,58 @@ foreach (new RecursiveIteratorIterator(
|
||||
| ext.standard.tests.general_functions.bug27678
|
||||
| tests.lang.bug24640
|
||||
)\.phpt$~x', $file)) {
|
||||
continue;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!preg_match('~--FILE--\s*(.*?)--[A-Z]+--~s', $code, $matches)) {
|
||||
continue;
|
||||
return null;
|
||||
}
|
||||
if (preg_match('~--EXPECT(?:F|REGEX)?--\s*(?:Parse|Fatal) error~', $code)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $matches[1];
|
||||
};
|
||||
break;
|
||||
default:
|
||||
showHelp('Test type must be either "Symfony" or "PHP"!');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../lib/PhpParser/Autoloader.php';
|
||||
PhpParser\Autoloader::register();
|
||||
|
||||
$parserName = 'PhpParser\Parser\\' . $version;
|
||||
$parser = new $parserName(new PhpParser\Lexer\Emulative);
|
||||
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
|
||||
$nodeDumper = new PhpParser\NodeDumper;
|
||||
|
||||
$parseFail = $ppFail = $compareFail = $count = 0;
|
||||
|
||||
$readTime = $parseTime = $ppTime = $reparseTime = $compareTime = 0;
|
||||
$totalStartTime = microtime(true);
|
||||
|
||||
foreach (new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($dir),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY)
|
||||
as $file) {
|
||||
if (!$fileFilter($file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$code = $matches[1];
|
||||
$startTime = microtime(true);
|
||||
$code = file_get_contents($file);
|
||||
$readTime += microtime(true) - $startTime;
|
||||
|
||||
if (null === $code = $codeExtractor($file, $code)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
set_time_limit(10);
|
||||
|
||||
++$count;
|
||||
|
||||
if ($SHOW_PROGRESS) {
|
||||
echo substr(str_pad('Testing file ' . $count . ': ' . substr($file, strlen($DIR)), 79), 0, 79), "\r";
|
||||
if ($showProgress) {
|
||||
echo substr(str_pad('Testing file ' . $count . ': ' . substr($file, strlen($dir)), 79), 0, 79), "\r";
|
||||
}
|
||||
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user