Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 25c9f06

Browse files
committed
Add script to replace EXPECT block with generated, [skip ci]
1 parent c2050e1 commit 25c9f06

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

scripts/replace_expect.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
$tests_dir = realpath(__DIR__ . '/../tests');
4+
$iterator = new GlobIterator($tests_dir . '/*.out', FilesystemIterator::KEY_AS_FILENAME);
5+
6+
foreach ($iterator as $item) {
7+
//var_dump($item);
8+
$out_file = $iterator->key();
9+
$base_name = preg_replace('/\.out$/i', '', $iterator->key());
10+
$test_file = $base_name .'.phpt';
11+
12+
$test_content = file_get_contents($tests_dir . '/' . $test_file);
13+
14+
if (false !== ($pos = strpos($test_content, '--EXPECT--'))) {
15+
printf("--EXPECT-- [%s]".PHP_EOL, $iterator->key());
16+
17+
$test_content = substr($test_content, 0, $pos);
18+
$test_content .= '--EXPECT--'.PHP_EOL;
19+
$test_content .= file_get_contents($tests_dir . '/' . $out_file);
20+
$test_content .= PHP_EOL;
21+
file_put_contents($tests_dir . '/' . $test_file, $test_content);
22+
23+
foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php'] as $ext) {
24+
@unlink($tests_dir. '/'.$base_name . $ext);
25+
}
26+
} else {
27+
printf("please, edit manually [%s]".PHP_EOL, $iterator->key());
28+
}
29+
}

0 commit comments

Comments
 (0)