com php-src: Support passing single file to bless_tests.php : scripts/dev/bless_tests.php
| From: | Nikita Popov | Date: | Wed, 20 Feb 2019 11:45:27 +0000 |
| Subject: | com php-src: Support passing single file to bless_tests.php : scripts/dev/bless_tests.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104779@lists.php.net to get a copy of this message | ||
Commit: e53e753c0e90df0039b4789850b2870cf92a8450
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 20 Feb 2019 12:45:27 +0100
Parents: 57fef27521814c575a7ea32abf4bda44f78ff400
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e53e753c0e90df0039b4789850b2870cf92a8450
Log:
Support passing single file to bless_tests.php
Or a mix of multiple directories/files. Also make the file executable.
Changed paths:
M scripts/dev/bless_tests.php
Diff:
diff --git a/scripts/dev/bless_tests.php b/scripts/dev/bless_tests.php
old mode 100644
new mode 100755
index 67c4def..19c24bf
--- 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);