|
15 | 15 | $tests_dir = realpath(__DIR__ . '/../tests');
|
16 | 16 |
|
17 | 17 |
|
18 |
| -if ($argc == 2) { |
19 |
| - $mask = str_replace(['tests/', '.phpt', '.diff'], '', $argv[1]); |
| 18 | +$mode = 'write'; |
| 19 | + |
| 20 | +$args = $argv; |
| 21 | +unset($args[0]); |
| 22 | + |
| 23 | +foreach ($argv as $i => $item) { |
| 24 | + if ($item == '--pretend') { |
| 25 | + $mode = 'pretend'; |
| 26 | + unset($args[$i]); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +if (count($args) > 1) { |
| 31 | + echo 'Invalid options', PHP_EOL; |
| 32 | + exit(1); |
| 33 | +} |
| 34 | + |
| 35 | +if ($args) { |
| 36 | + $mask = str_replace(['tests/', '.phpt', '.diff'], '', array_pop($args)); |
20 | 37 | } else {
|
21 | 38 | $mask = '*';
|
22 | 39 | }
|
|
25 | 42 |
|
26 | 43 | foreach ($iterator as $item) {
|
27 | 44 | //var_dump($item);
|
28 |
| - $out_file = $iterator->key(); |
| 45 | + $out_file = $iterator->key(); |
29 | 46 | $base_name = preg_replace('/\.out$/i', '', $iterator->key());
|
30 |
| - $test_file = $base_name .'.phpt'; |
| 47 | + $test_file = $base_name . '.phpt'; |
31 | 48 |
|
32 | 49 | $test_content = file_get_contents($tests_dir . '/' . $test_file);
|
33 | 50 |
|
34 | 51 | if (false !== ($pos = strpos($test_content, '--EXPECT--'))) {
|
35 |
| - printf("--EXPECT-- [%s]".PHP_EOL, $iterator->key()); |
| 52 | + printf("--EXPECT-- [%s]" . PHP_EOL, $iterator->key()); |
36 | 53 |
|
37 | 54 | $test_content = substr($test_content, 0, $pos);
|
38 |
| - $test_content .= '--EXPECT--'.PHP_EOL; |
| 55 | + $test_content .= '--EXPECT--' . PHP_EOL; |
39 | 56 | $test_content .= file_get_contents($tests_dir . '/' . $out_file);
|
40 | 57 | $test_content .= PHP_EOL;
|
41 | 58 | file_put_contents($tests_dir . '/' . $test_file, $test_content);
|
42 | 59 |
|
43 | 60 | foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
|
44 |
| - @unlink($tests_dir. '/'.$base_name . $ext); |
| 61 | + @unlink($tests_dir . '/' . $base_name . $ext); |
45 | 62 | }
|
46 | 63 |
|
47 | 64 | continue;
|
48 |
| - //} elseif (0) { |
| 65 | + //} elseif (0) { |
49 | 66 | } elseif (false !== ($pos = strpos($test_content, '--EXPECTF--'))) {
|
50 | 67 |
|
51 |
| - printf("--EXPECTF-- [%s]".PHP_EOL, $iterator->key()); |
| 68 | + printf("--EXPECTF-- [%s]" . PHP_EOL, $iterator->key()); |
52 | 69 |
|
53 | 70 | // get replacements
|
54 | 71 |
|
55 |
| - $tests = substr($test_content, 0, $pos); |
| 72 | + $tests = substr($test_content, 0, $pos); |
56 | 73 | $result = file_get_contents($tests_dir . '/' . $out_file);
|
57 | 74 |
|
58 | 75 | preg_match_all('#// EXPECTF: \-\-\-(.+)#', $tests, $expectf_search);
|
59 | 76 | preg_match_all('#// EXPECTF: \+\+\+(.+)#', $tests, $expectf_replace);
|
60 | 77 |
|
61 | 78 | if (count($expectf_search) != count($expectf_replace)) {
|
62 |
| - printf("please, edit manually [%s]: searches and replaces count doesn't match".PHP_EOL, $iterator->key()); |
| 79 | + printf("please, edit manually [%s]: searches and replaces count doesn't match" . PHP_EOL, $iterator->key()); |
63 | 80 | continue;
|
64 | 81 | }
|
65 | 82 |
|
|
68 | 85 | }
|
69 | 86 |
|
70 | 87 | $test_content = $tests;
|
71 |
| - $test_content .= '--EXPECTF--'.PHP_EOL; |
| 88 | + $test_content .= '--EXPECTF--' . PHP_EOL; |
72 | 89 | $test_content .= $result;
|
73 | 90 | $test_content .= PHP_EOL;
|
74 | 91 |
|
75 |
| - file_put_contents($tests_dir . '/' . $test_file, $test_content); |
| 92 | + if ($mode == 'pretend') { |
| 93 | + echo $result, PHP_EOL; |
| 94 | + echo PHP_EOL; |
76 | 95 |
|
77 |
| - foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) { |
78 |
| - @unlink($tests_dir. '/'.$base_name . $ext); |
| 96 | + } elseif ($mode = 'write') { |
| 97 | + file_put_contents($tests_dir . '/' . $test_file, $test_content); |
| 98 | + |
| 99 | + foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) { |
| 100 | + @unlink($tests_dir . '/' . $base_name . $ext); |
| 101 | + } |
79 | 102 | }
|
80 | 103 |
|
81 | 104 | continue;
|
82 | 105 | }
|
83 | 106 |
|
84 |
| - printf("please, edit manually [%s]".PHP_EOL, $iterator->key()); |
| 107 | + printf("please, edit manually [%s]" . PHP_EOL, $iterator->key()); |
85 | 108 | }
|
0 commit comments