Skip to content

Commit

Permalink
Add progress indicator for test_old.
Browse files Browse the repository at this point in the history
I hate waiting for something without seeing at least *some* output.
  • Loading branch information
nikic committed May 5, 2012
1 parent 101a6dd commit 5438cc0
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions test_old/run.php
Expand Up @@ -7,14 +7,51 @@
die('This script is designed for running on the command line.');
}

if (3 !== $argc) {
die('This script expects exactly two arguments:
1. The test type (either "Symfony" or "PHP")
2. The path to the test files');
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!');
}
}

$TEST_TYPE = $argv[1];
$DIR = $argv[2];
$TEST_TYPE = $arguments[0];
$DIR = $arguments[1];

if ('Symfony' === $TEST_TYPE) {
function filter_func($path) {
Expand All @@ -25,7 +62,7 @@ function filter_func($path) {
return preg_match('~\.phpt$~', $path);
};
} else {
die('The test type must be either "Symfony" or "PHP".');
showHelp('Test type must be either "Symfony" or "PHP"!');
}

require_once dirname(__FILE__) . '/../lib/PHPParser/Autoloader.php';
Expand All @@ -35,7 +72,7 @@ function filter_func($path) {
$prettyPrinter = new PHPParser_PrettyPrinter_Zend;
$nodeDumper = new PHPParser_NodeDumper;

$parseFail = $ppFail = $compareFail = $count = 0;;
$parseFail = $ppFail = $compareFail = $count = 0;

$readTime = $parseTime = $ppTime = $reparseTime = $compareTime = 0;
$totalStartTime = microtime(true);
Expand Down Expand Up @@ -85,6 +122,10 @@ function filter_func($path) {

++$count;

if ($SHOW_PROGRESS) {
echo substr(str_pad('Testing file ' . $count . ': ' . substr($file, strlen($DIR)), 79), 0, 79), "\r";
}

try {
$startTime = microtime(true);
$stmts = $parser->parse($code);
Expand Down Expand Up @@ -121,9 +162,9 @@ function filter_func($path) {
}

if (0 === $parseFail && 0 === $ppFail && 0 === $compareFail) {
echo 'All tests passed.', "\n";
echo "\n\n", 'All tests passed.', "\n";
} else {
echo "\n", '==========', "\n\n", 'There were: ', "\n";
echo "\n\n", '==========', "\n\n", 'There were: ', "\n";
if (0 !== $parseFail) {
echo ' ', $parseFail, ' parse failures.', "\n";
}
Expand Down

0 comments on commit 5438cc0

Please sign in to comment.