From: Nikita Popov Date: Mon, 11 Feb 2019 14:35:34 +0000 (+0100) Subject: Add bless_tests.php X-Git-Tag: php-7.4.0alpha1~1075 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a17be7f31be344605b244599f37b6f8579ec90b;p=php Add bless_tests.php Helper script to perform certain kinds of trivial test updates. --- diff --git a/scripts/dev/bless_tests.php b/scripts/dev/bless_tests.php new file mode 100644 index 0000000000..121a011f9a --- /dev/null +++ b/scripts/dev/bless_tests.php @@ -0,0 +1,49 @@ +#!/usr/bin/env php +getPathName(); + if (!preg_match('/^(.*)\.phpt$/', $path, $matches)) { + // Not a phpt test + continue; + } + + $outPath = $matches[1] . '.out'; + if (!file_exists($outPath)) { + // Test did not fail + continue; + } + + $phpt = file_get_contents($path); + if (false !== strpos($phpt, '--XFAIL--')) { + // Don't modify expected output of XFAIL tests + continue; + } + + $out = file_get_contents($outPath); + $out = normalizeOutput($out); + $phpt = insertOutput($phpt, $out); + file_put_contents($path, $phpt); +} + +function normalizeOutput(string $out): string { + $out = preg_replace('/in \/.+ on line \d+/', 'in %s on line %d', $out); + $out = preg_replace('/Resource id #\d+/', 'Resource id #%d', $out); + return $out; +} + +function insertOutput(string $phpt, string $out): string { + return preg_replace_callback('/--EXPECTF?--.*$/s', function($matches) use($out) { + $F = strpos($out, '%') !== false ? 'F' : ''; + return "--EXPECT$F--\n" . $out . "\n"; + }, $phpt); +}