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

Commit c1953fe

Browse files
committed
Add support for EXPECTF test updating from output [skip ci]
1 parent b310dcf commit c1953fe

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

scripts/replace_expect.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,42 @@
3535
foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
3636
@unlink($tests_dir. '/'.$base_name . $ext);
3737
}
38-
} else {
39-
printf("please, edit manually [%s]".PHP_EOL, $iterator->key());
38+
39+
continue;
40+
} elseif (false !== ($pos = strpos($test_content, '--EXPECTF--'))) {
41+
42+
printf("--EXPECTF-- [%s]".PHP_EOL, $iterator->key());
43+
44+
// get replacements
45+
46+
$tests = substr($test_content, 0, $pos);
47+
$result = file_get_contents($tests_dir . '/' . $out_file);
48+
49+
preg_match_all('#// EXPECTF: \-\-\-(.+)#', $tests, $expectf_search);
50+
preg_match_all('#// EXPECTF: \+\+\+(.+)#', $tests, $expectf_replace);
51+
52+
if (count($expectf_search) != count($expectf_replace)) {
53+
printf("please, edit manually [%s]: searches and replaces count doesn't match".PHP_EOL, $iterator->key());
54+
continue;
55+
}
56+
57+
foreach (array_combine($expectf_search[1], $expectf_replace[1]) as $search => $replace) {
58+
$result = preg_replace($search, $replace, $result);
59+
}
60+
61+
$test_content = $tests;
62+
$test_content .= '--EXPECTF--'.PHP_EOL;
63+
$test_content .= $result;
64+
$test_content .= PHP_EOL;
65+
66+
file_put_contents($tests_dir . '/' . $test_file, $test_content);
67+
68+
foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
69+
@unlink($tests_dir. '/'.$base_name . $ext);
70+
}
71+
72+
continue;
4073
}
74+
75+
printf("please, edit manually [%s]".PHP_EOL, $iterator->key());
4176
}

0 commit comments

Comments
 (0)