Skip to content

Commit e53e753

Browse files
committed
Support passing single file to bless_tests.php
Or a mix of multiple directories/files. Also make the file executable.
1 parent 57fef27 commit e53e753

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

scripts/dev/bless_tests.php

100644100755
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
<?php
33

44
if ($argc < 2) {
5-
die("Usage: php bless_tests.php dir/");
5+
die("Usage: php bless_tests.php dir/\n");
66
}
77

8-
$dir = $argv[1];
9-
$it = new RecursiveIteratorIterator(
10-
new RecursiveDirectoryIterator($dir),
11-
RecursiveIteratorIterator::LEAVES_ONLY
12-
);
13-
foreach ($it as $file) {
14-
$path = $file->getPathName();
8+
$files = getFiles(array_slice($argv, 1));
9+
foreach ($files as $path) {
1510
if (!preg_match('/^(.*)\.phpt$/', $path, $matches)) {
1611
// Not a phpt test
1712
continue;
@@ -35,6 +30,24 @@
3530
file_put_contents($path, $phpt);
3631
}
3732

33+
function getFiles(array $dirsOrFiles): \Iterator {
34+
foreach ($dirsOrFiles as $dirOrFile) {
35+
if (is_dir($dirOrFile)) {
36+
$it = new RecursiveIteratorIterator(
37+
new RecursiveDirectoryIterator($dirOrFile),
38+
RecursiveIteratorIterator::LEAVES_ONLY
39+
);
40+
foreach ($it as $file) {
41+
yield $file->getPathName();
42+
}
43+
} else if (is_file($dirOrFile)) {
44+
yield $dirOrFile;
45+
} else {
46+
die("$dirOrFile is not a directory or file\n");
47+
}
48+
}
49+
}
50+
3851
function normalizeOutput(string $out): string {
3952
$out = preg_replace('/in \/.+ on line \d+$/m', 'in %s on line %d', $out);
4053
$out = preg_replace('/in \/.+:\d+$/m', 'in %s:%d', $out);

0 commit comments

Comments
 (0)