Skip to content

Commit 6dfce36

Browse files
committed
Handle error strerror values in bless
One annoyance with bless is its tendency to hardcode OS-specific errors in expect output, especially when the test was already making it to begin with, and bless instead hardcodes it again. Build a list of strerror values, scan the output for them, and replace them with '%s'. Perhaps this may be overzealous, but it does seem to work to keep bless output reasonable with less post-processing.
1 parent a22c56c commit 6dfce36

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

scripts/dev/bless_tests.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
die("Usage: php bless_tests.php dir/\n");
66
}
77

8+
// Build a list of known errors on this platform, so we can avoid hardcoding
9+
// platform-specific errors in expect output, as the errno/strerror differs
10+
// between platforms.
11+
$strerrors = [];
12+
if (function_exists("posix_strerror")) {
13+
for ($i = -1; $i < 255; $i++) {
14+
$str = posix_strerror($i);
15+
if (str_contains($str, "Unknown error") && $i > 0 && strlen($str) > 0) {
16+
break;
17+
}
18+
$strerrors[] = $str;
19+
}
20+
}
21+
822
$files = getFiles(array_slice($argv, 1));
923
foreach ($files as $path) {
1024
if (!preg_match('/^(.*)\.phpt$/', $path, $matches)) {
@@ -74,6 +88,10 @@ function normalizeOutput(string $out): string {
7488
'Resource ID#%d used as offset, casting to integer (%d)',
7589
$out);
7690
$out = preg_replace('/string\(\d+\) "([^"]*%d)/', 'string(%d) "$1', $out);
91+
global $strerrors;
92+
foreach ($strerrors as $strerror) {
93+
$out = str_replace($strerror, "%s", $out);
94+
}
7795
$out = str_replace("\0", '%0', $out);
7896
return $out;
7997
}

0 commit comments

Comments
 (0)