summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-02-20 12:45:27 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-02-20 12:45:27 +0100
commite53e753c0e90df0039b4789850b2870cf92a8450 (patch)
tree4b26e9b25e02e952531c8bbcab13ff0c3322714b /scripts
parent57fef27521814c575a7ea32abf4bda44f78ff400 (diff)
downloadphp-git-e53e753c0e90df0039b4789850b2870cf92a8450.tar.gz
Support passing single file to bless_tests.php
Or a mix of multiple directories/files. Also make the file executable.
Diffstat (limited to 'scripts')
-rwxr-xr-x[-rw-r--r--]scripts/dev/bless_tests.php29
1 files changed, 21 insertions, 8 deletions
diff --git a/scripts/dev/bless_tests.php b/scripts/dev/bless_tests.php
index 67c4defa3b..19c24bf188 100644..100755
--- a/scripts/dev/bless_tests.php
+++ b/scripts/dev/bless_tests.php
@@ -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;
@@ -35,6 +30,24 @@ foreach ($it as $file) {
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);