]> granicus.if.org Git - php/commitdiff
Support passing single file to bless_tests.php
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 20 Feb 2019 11:45:27 +0000 (12:45 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 20 Feb 2019 11:45:27 +0000 (12:45 +0100)
Or a mix of multiple directories/files. Also make the file executable.

scripts/dev/bless_tests.php [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 67c4def..19c24bf
@@ -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);