|
2 | 2 | <?php
|
3 | 3 |
|
4 | 4 | if ($argc < 2) {
|
5 |
| - die("Usage: php bless_tests.php dir/"); |
| 5 | + die("Usage: php bless_tests.php dir/\n"); |
6 | 6 | }
|
7 | 7 |
|
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) { |
15 | 10 | if (!preg_match('/^(.*)\.phpt$/', $path, $matches)) {
|
16 | 11 | // Not a phpt test
|
17 | 12 | continue;
|
|
35 | 30 | file_put_contents($path, $phpt);
|
36 | 31 | }
|
37 | 32 |
|
| 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 | + |
38 | 51 | function normalizeOutput(string $out): string {
|
39 | 52 | $out = preg_replace('/in \/.+ on line \d+$/m', 'in %s on line %d', $out);
|
40 | 53 | $out = preg_replace('/in \/.+:\d+$/m', 'in %s:%d', $out);
|
|
0 commit comments