Skip to content

Commit

Permalink
Support passing single file to bless_tests.php
Browse files Browse the repository at this point in the history
Or a mix of multiple directories/files. Also make the file executable.
  • Loading branch information
nikic committed Feb 20, 2019
1 parent 57fef27 commit e53e753
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions scripts/dev/bless_tests.php 100644 → 100755
Expand Up @@ -2,16 +2,11 @@
<?php

if ($argc < 2) {
die("Usage: php bless_tests.php dir/");
die("Usage: php bless_tests.php dir/\n");
}

$dir = $argv[1];
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($it as $file) {
$path = $file->getPathName();
$files = getFiles(array_slice($argv, 1));
foreach ($files as $path) {
if (!preg_match('/^(.*)\.phpt$/', $path, $matches)) {
// Not a phpt test
continue;
Expand All @@ -35,6 +30,24 @@
file_put_contents($path, $phpt);
}

function getFiles(array $dirsOrFiles): \Iterator {
foreach ($dirsOrFiles as $dirOrFile) {
if (is_dir($dirOrFile)) {
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dirOrFile),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($it as $file) {
yield $file->getPathName();
}
} else if (is_file($dirOrFile)) {
yield $dirOrFile;
} else {
die("$dirOrFile is not a directory or file\n");
}
}
}

function normalizeOutput(string $out): string {
$out = preg_replace('/in \/.+ on line \d+$/m', 'in %s on line %d', $out);
$out = preg_replace('/in \/.+:\d+$/m', 'in %s:%d', $out);
Expand Down

0 comments on commit e53e753

Please sign in to comment.