/hphp/tools/update_expected_slow_output.php
PHP | 85 lines | 77 code | 5 blank | 3 comment | 1 complexity | ec510174b2f48b3b1560eee62825b973 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
- #!/bin/env php
- <?hh
- $php = '/home/engshare/externals/cpp/hphp/centos-dev/php/bin/php';
- // $php = '/home/ptarjan/bin/php-5.4';
- $config = json_decode(file_get_contents(__DIR__.'/update_expected_slow_output.json'), true);
- if (!$config) {
- die("Invalid config file. Not JSON.\n");
- }
- function ends_with($big, $little) {
- return strpos($big, $little, strlen($big) - strlen($little)) !== false;
- }
- // More efficient lookups than array_search
- foreach ($config as $key => $value) {
- $config[$key] = array_fill_keys($value, true);
- }
- function is_valid_diff($wanted_re, $output) {
- $wanted_re = trim($wanted_re);
- $output = trim($output);
- $wanted_re = preg_quote($wanted_re, '/');
- $wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re);
- $wanted_re = str_replace('%s', '[^\r\n]+', $wanted_re);
- $wanted_re = str_replace('%S', '[^\r\n]*', $wanted_re);
- $wanted_re = str_replace('%a', '.+', $wanted_re);
- $wanted_re = str_replace('%A', '.*', $wanted_re);
- $wanted_re = str_replace('%w', '\s*', $wanted_re);
- $wanted_re = str_replace('%i', '[+-]?\d+', $wanted_re);
- $wanted_re = str_replace('%d', '\d+', $wanted_re);
- $wanted_re = str_replace('%x', '[0-9a-fA-F]+', $wanted_re);
- $wanted_re = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $wanted_re);
- $wanted_re = str_replace('%c', '.', $wanted_re);
- return preg_match("/^$wanted_re\$/sm", $output);
- };
- print "Running all test/slow through $php...\n";
- foreach (new RecursiveIteratorIterator (new RecursiveDirectoryIterator ('test/slow')) as $f) {
- $filename = $f->getRealPath();
- $name = str_replace('.php', '', $f->getFilename());
- if (!$f->isFile() ||
- !ends_with($filename, '.php') ||
- isset($config['hard_coded'][$name])) {
- continue;
- }
- $opts = '-dapc.enable_cli=1 -ddisplay_errors=off';
- $output = shell_exec("$php $opts $filename 2>/dev/null");
- $expect = "$filename.expect";
- if (is_file($expect)) {
- file_put_contents($expect, $output);
- } else if (is_file($expect.'f')) {
- $wanted_re = file_get_contents($expect.'f');
- if (isset($config['no_warnings'][$name])) {
- $wanted_re = preg_replace('/^HipHop .*/m', '', $wanted_re);
- }
- $output = str_replace(realpath(__DIR__.'../../..'), '%s', $output);
- if (is_valid_diff($wanted_re, $output)) {
- continue;
- }
- $file = tempnam('/tmp', 'zend-');
- file_put_contents($file, $output);
- $diff = shell_exec("diff --text -u {$expect}f $file");
- echo "\n$diff\n";
- do {
- print "Output differs, use Zend? [y/N]? ";
- $prompt = strtolower(trim(fgets(STDIN)));
- if ($prompt == 'y') {
- file_put_contents($expect.'f', $output);
- break;
- } else if (!$prompt || $prompt == 'n') {
- break;
- }
- } while (true);
- } else {
- die("No $file.expect or $file.expectf. WTF?\n");
- }
- }