bjori Mon Dec 17 11:34:55 2007 UTC Modified files: /php-src run-tests.php Log: MFB5.3: - Allow to specify php executable on commandline MFB5.3: - Allow to check the out,exp and diff results on console while executing the tests
http://cvs.php.net/viewvc.cgi/php-src/run-tests.php?r1=1.333&r2=1.334&diff_format=u Index: php-src/run-tests.php diff -u php-src/run-tests.php:1.333 php-src/run-tests.php:1.334 --- php-src/run-tests.php:1.333 Wed Dec 12 09:20:41 2007 +++ php-src/run-tests.php Mon Dec 17 11:34:55 2007 @@ -24,7 +24,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: run-tests.php,v 1.333 2007/12/12 09:20:41 tony2001 Exp $ */ +/* $Id: run-tests.php,v 1.334 2007/12/17 11:34:55 bjori Exp $ */ /* Sanity check to ensure that pcre extension needed by this script is available. * In the event it is not, print a nice error message indicating that this script will @@ -113,8 +113,10 @@ $environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi; } -if ($argc !=2 || ($argv[1] != '-h' && $argv[1] != '-help' && $argv != '--help')) +function verify_config() { + global $php; + if (empty($php) || !file_exists($php)) { error("environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!"); } @@ -254,7 +256,7 @@ $no_clean = false; $cfgtypes = array('show', 'keep'); -$cfgfiles = array('skip', 'php', 'clean'); +$cfgfiles = array('skip', 'php', 'clean', 'out', 'diff', 'exp'); $cfg = array(); foreach($cfgtypes as $type) { $cfg[$type] = array(); @@ -279,11 +281,28 @@ $switch = substr($argv[$i],1,1); $repeat = substr($argv[$i],0,1) == '-'; while ($repeat) { - $repeat = false; if (!$is_switch) { $switch = substr($argv[$i],1,1); } $is_switch = true; + if ($repeat) { + foreach($cfgtypes as $type) { + if (strpos($switch, '--'.$type) === 0) { + foreach($cfgfiles as $file) { + if ($switch == '--'.$type.'-'.$file) { + $cfg[$type][$file] = true; + $is_switch = false; + break; + } + } + } + } + } + if (!$is_switch) { + $is_switch = true; + break; + } + $repeat = false; switch($switch) { case 'r': case 'l': @@ -321,15 +340,6 @@ $cfg['keep'][$file] = true; } break; - case '--keep-skip': - $cfg['keep']['skip'] = true; - break; - case '--keep-php': - $cfg['keep']['php'] = true; - break; - case '--keep-clean': - $cfg['keep']['clean'] = true; - break; //case 'l' case 'm': $leak_check = true; @@ -348,6 +358,10 @@ case '--no-clean': $no_clean = true; break; + case 'p': + $php = $argv[++$i]; + putenv("TEST_PHP_EXECUTABLE=$php"); + break; case 'q': putenv('NO_INTERACTION=1'); break; @@ -361,15 +375,6 @@ $cfg['show'][$file] = true; } break; - case '--show-skip': - $cfg['show']['skip'] = true; - break; - case '--show-php': - $cfg['show']['php'] = true; - break; - case '--show-clean': - $cfg['show']['clean'] = true; - break; case '--temp-source': $temp_source = $argv[++$i]; break; @@ -410,7 +415,7 @@ $html_output = is_resource($html_file); break; case '--version': - echo '$Revision: 1.333 $'."\n"; + echo '$Revision: 1.334 $'."\n"; exit(1); default: echo "Illegal switch specified!\n"; @@ -423,8 +428,8 @@ php run-tests.php [options] [files] [directories] Options: - -l <file> Read the testfiles to be executed from <file>. After the test - has finished all failed tests are written to the same <file>. + -l <file> Read the testfiles to be executed from <file>. After the test + has finished all failed tests are written to the same <file>. If the list is empty and no further test is specified then all tests are executed (same as: -r <file> -w <file>). @@ -448,11 +453,13 @@ -m Test for memory leaks with Valgrind. -N Test with unicode.semantics set off. - - -s <file> Write output to <file>. + -p <php> Specify PHP executable to run. + -q Quiet, no user interaction (same as environment NO_INTERACTION). + -s <file> Write output to <file>. + --verbose -v Verbose mode. @@ -460,21 +467,25 @@ -h This Help. --html <file> Generate HTML output. - + --temp-source <sdir> --temp-target <tdir> [--temp-urlbase <url>] - Write temporary files to <tdir> by replacing <sdir> from the - filenames to generate with <tdir>. If --html is being used and + Write temporary files to <tdir> by replacing <sdir> from the + filenames to generate with <tdir>. If --html is being used and <url> given then the generated links are relative and prefixed with the given url. In general you want to make <sdir> the path - to your source files and <tdir> some pach in your web page + to your source files and <tdir> some pach in your web page hierarchy with <url> pointing to <tdir>. --keep-[all|php|skip|clean] - Do not delete 'all' files, 'php' test file, 'skip' or 'clean' + Do not delete 'all' files, 'php' test file, 'skip' or 'clean' file. - --show-[all|php|skip|clean] - Show 'all' files, 'php' test file, 'skip' or 'clean' file. + --show-[all|php|skip|clean|exp|diff|out] + Show 'all' files, 'php' test file, 'skip' or 'clean' file. You + can also use this to show the output 'out', the expected result + 'exp' or the difference between them 'exp'. The result types + get written independent of the log format, however 'diff' only + exists when a test fails. --no-clean Do not execute clean section if any. @@ -514,6 +525,7 @@ // Run selected tests. $test_cnt = count($test_files); if ($test_cnt) { + verify_config(); write_information($html_output); usort($test_files, "test_sort"); $start_time = time(); @@ -549,6 +561,7 @@ } } +verify_config(); write_information($html_output); // Compile a list of all test files (*.phpt). @@ -965,6 +978,23 @@ } // +// Show file or result block +// +function show_file_block($file, $block, $section=NULL) +{ + global $cfg; + + if ($cfg['show'][$file]) { + if (is_null($section)) { + $section = strtoupper($file); + } + echo "\n========".$section."========\n"; + echo rtrim($block); + echo "\n========DONE========\n"; + } +} + +// // Run an individual test case. // function run_test($php, $file, $env, $unicode_semantics) @@ -1151,7 +1181,7 @@ } $temp_filenames = array( 'file' => $copy_file, - 'diff' => $diff_filename, + 'diff' => $diff_filename, 'log' => $log_filename, 'exp' => $exp_filename, 'out' => $output_filename, @@ -1167,7 +1197,7 @@ $section_text['FILE'] = "# original source file: $shortname\n" . $section_text['FILE']; } - // unlink old test results + // unlink old test results @unlink($diff_filename); @unlink($log_filename); @unlink($exp_filename); @@ -1229,11 +1259,7 @@ $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { - if ($cfg['show']['skip']) { - echo "\n========SKIP========\n"; - echo $section_text['SKIPIF']; - echo "========DONE========\n"; - } + show_file_block('skip', $section_text['SKIPIF']); save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;": ""; @@ -1366,11 +1392,7 @@ } // We've satisfied the preconditions - run the test! - if ($cfg['show']['php']) { - echo "\n========TEST========\n"; - echo $section_text['FILE']; - echo "========DONE========\n"; - } + show_file_block('php', $section_text['FILE'], 'TEST'); save_text($test_file, $section_text['FILE'], $temp_file); if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); @@ -1484,11 +1506,7 @@ if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { if (trim($section_text['CLEAN'])) { - if ($cfg['show']['clean']) { - echo "\n========CLEAN=======\n"; - echo $section_text['CLEAN']; - echo "========DONE========\n"; - } + show_file_block('clean', $section_text['CLEAN']); save_text($test_clean, trim($section_text['CLEAN']), $temp_clean); if (!$no_clean) { $clean_params = array(); @@ -1563,12 +1581,14 @@ $output_headers = join("\n", $output_headers); } + show_file_block('out', $output); if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } + show_file_block('exp', $wanted); $wanted_re = preg_replace('/\r\n/',"\n",$wanted); if (isset($section_text['EXPECTF'])) { $wanted_re = preg_quote($wanted_re, '/'); @@ -1609,6 +1629,7 @@ $wanted = unicode_encode($wanted, ini_get('unicode.output_encoding')); } $wanted = preg_replace('/\r\n/',"\n",$wanted); + show_file_block('exp', $wanted); // compare and leave on success if (!strcmp($output, $wanted)) { $passed = true; @@ -1651,17 +1672,19 @@ if (strpos($log_format,'E') !== FALSE && file_put_contents($exp_filename, $wanted) === FALSE) { error("Cannot create expected test output - $exp_filename"); } - + // write .out if (strpos($log_format,'O') !== FALSE && file_put_contents($output_filename, $output) === FALSE) { error("Cannot create test output - $output_filename"); } - + // write .diff - if (strpos($log_format,'D') !== FALSE && file_put_contents($diff_filename, generate_diff($wanted,$wanted_re,$output)) === FALSE) { + $diff = generate_diff($wanted,$wanted_re,$output); + show_file_block('diff', $diff); + if (strpos($log_format,'D') !== FALSE && file_put_contents($diff_filename, $diff) === FALSE) { error("Cannot create test diff - $diff_filename"); } - + // write .log if (strpos($log_format,'L') !== FALSE && file_put_contents($log_filename, " ---- EXPECTED OUTPUT
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php