Add %0 format to run-tests.php

This format matches against null bytes, and prevents the test
expectation from being interpreted as binary data.

bless_tests.php will automatically replace \0 with %0 as well.
This commit is contained in:
Nikita Popov 2021-05-28 13:08:25 +02:00 committed by Nikita Popov
parent e838de342a
commit ea256a218b
120 changed files with 55 additions and 52 deletions

View file

@ -72,6 +72,7 @@ function normalizeOutput(string $out): string {
'Resource ID#%d used as offset, casting to integer (%d)',
$out);
$out = preg_replace('/string\(\d+\) "([^"]*%d)/', 'string(%d) "$1', $out);
$out = str_replace("\0", '%0', $out);
return $out;
}
@ -86,6 +87,7 @@ function formatToRegex(string $format): string {
$result = str_replace('%x', '[0-9a-fA-F]+', $result);
$result = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $result);
$result = str_replace('%c', '.', $result);
$result = str_replace('%0', '\0', $result);
return "/^$result$/s";
}
@ -113,7 +115,7 @@ function generateMinimallyDifferingOutput(string $out, string $oldExpect) {
function insertOutput(string $phpt, string $out): string {
return preg_replace_callback('/--EXPECTF?--.*?(--CLEAN--|$)/sD', function($matches) use($out) {
$hasWildcard = preg_match('/%[resSaAwidxfc]/', $out);
$hasWildcard = preg_match('/%[resSaAwidxfc0]/', $out);
$F = $hasWildcard ? 'F' : '';
return "--EXPECT$F--\n" . $out . "\n" . $matches[1];
}, $phpt);