Skip to content

Commit

Permalink
Support more placeholders in bless_tests.php
Browse files Browse the repository at this point in the history
And don't replace trailing --CLEAN-- sections.
  • Loading branch information
nikic committed Sep 8, 2020
1 parent 5a201dd commit ababa22
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/dev/bless_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,15 @@ function normalizeOutput(string $out): string {

function formatToRegex(string $format): string {
$result = preg_quote($format, '/');
$result = str_replace('%d', '\d+', $result);
$result = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $result);
$result = str_replace('%s', '[^\r\n]+', $result);
$result = str_replace('%S', '[^\r\n]*', $result);
$result = str_replace('%w', '\s*', $result);
$result = str_replace('%i', '[+-]?\d+', $result);
$result = str_replace('%d', '\d+', $result);
$result = str_replace('%x', '[0-9a-fA-F]+', $result);
$result = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $result);
$result = str_replace('%c', '.', $result);
return "/^$result$/s";
}

Expand All @@ -105,10 +112,10 @@ function generateMinimallyDifferingOutput(string $out, string $oldExpect) {
}

function insertOutput(string $phpt, string $out): string {
return preg_replace_callback('/--EXPECTF?--.*$/s', function($matches) use($out) {
return preg_replace_callback('/--EXPECTF?--.*?(--CLEAN--|$)/sD', function($matches) use($out) {
$hasWildcard = preg_match('/%[resSaAwidxfc]/', $out);
$F = $hasWildcard ? 'F' : '';
return "--EXPECT$F--\n" . $out . "\n";
return "--EXPECT$F--\n" . $out . "\n" . $matches[1];
}, $phpt);
}

Expand Down

0 comments on commit ababa22

Please sign in to comment.