felipe Sat, 26 Nov 2011 20:18:03 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=319967
Log: - Added JUnit output format option patch by: Ferenc Kovacs (tyrael at php.net) Changed paths: U php/php-src/branches/PHP_5_3/run-tests.php U php/php-src/branches/PHP_5_4/run-tests.php U php/php-src/trunk/run-tests.php
Modified: php/php-src/branches/PHP_5_3/run-tests.php =================================================================== --- php/php-src/branches/PHP_5_3/run-tests.php 2011-11-26 19:04:51 UTC (rev 319966) +++ php/php-src/branches/PHP_5_3/run-tests.php 2011-11-26 20:18:03 UTC (rev 319967) @@ -200,6 +200,26 @@ $DETAILED = 0; } +// Check whether a junit log is wanted. +$JUNIT = getenv('TEST_PHP_JUNIT'); +if (empty($JUNIT) || (!file_exists($JUNIT) && !is_writable(dirname($JUNIT))) || (file_exists($JUNIT) && !is_writable($JUNIT)) || !($JUNIT = @fopen($JUNIT, 'w'))) { + $JUNIT = FALSE; +} +else{ + $JUNIT = array( + 'fp' => $JUNIT, + 'test_total' => 0, + 'test_pass' => 0, + 'test_fail' => 0, + 'test_error' => 0, + 'test_skip' => 0, + 'started_at' => microtime(true), + 'finished_at' => NULL, + 'execution_time'=> NULL, + 'result_xml' => '', + ); +} + if (getenv('SHOW_ONLY_GROUPS')) { $SHOW_ONLY_GROUPS = explode(",", getenv('SHOW_ONLY_GROUPS')); } else { @@ -811,6 +831,10 @@ if ($output_file != '' && $just_save_results) { save_or_mail_results(); } + + if ($JUNIT) { + save_junit_xml(); + } if (getenv('REPORT_EXIT_STATUS') == 1 and preg_match('/FAILED(?: |$)/', implode(' ', $test_results))) { exit(1); @@ -946,6 +970,10 @@ save_or_mail_results(); +if ($JUNIT) { + save_junit_xml(); +} + if (getenv('REPORT_EXIT_STATUS') == 1 and $sum_results['FAILED']) { exit(1); } @@ -1165,6 +1193,7 @@ global $leak_check, $temp_source, $temp_target, $cfg, $environment; global $no_clean; global $valgrind_version; + global $JUNIT; $temp_filenames = null; $org_file = $file; @@ -1300,6 +1329,14 @@ 'diff' => '', 'info' => "$bork_info [$file]", ); + + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested_file, ENT_QUOTES).'" time="0">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="'.$bork_info.'" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1322,6 +1359,13 @@ $php = realpath("./sapi/cgi/php-cgi") . ' -C '; } else { show_result('SKIP', $tested, $tested_file, "reason: CGI not available"); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_skip']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="0">'."\n"; + $JUNIT['result_xml'] .= '<skipped>CGI not available</skipped>'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'SKIPPED'; } } @@ -1459,7 +1503,14 @@ $env['USE_ZEND_ALLOC'] = '1'; } + if ($JUNIT) { + $test_started_at = microtime(true); + } $output = system_with_timeout("$extra $php $pass_options -q $ini_settings -d display_errors=0 $test_skipif", $env); + if ($JUNIT) { + $test_finished_at = microtime(true); + $test_execution_time= number_format($test_finished_at-$test_started_at, 2); + } if (!$cfg['keep']['skip']) { @unlink($test_skipif); @@ -1481,6 +1532,13 @@ @unlink($test_skipif); } + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_skip']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<skipped><![CDATA['."\n".$m[1]."\n".']]></skipped>'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'SKIPPED'; } @@ -1535,6 +1593,12 @@ // a redirected test never fails $IN_REDIRECT = false; + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'REDIR'; } else { @@ -1566,6 +1630,13 @@ 'diff' => '', 'info' => "$bork_info [$file]", ); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="'.$bork_info.'" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1619,6 +1690,13 @@ $env['REQUEST_METHOD'] = 'POST'; if (empty($request)) { + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="empty $request" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1681,7 +1759,14 @@ COMMAND $cmd "; + if ($JUNIT) { + $test_started_at = microtime(true); + } $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null); + if ($JUNIT) { + $test_finished_at = microtime(true); + $test_execution_time= number_format($test_finished_at-$test_started_at, 2); + } if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { @@ -1870,6 +1955,12 @@ $info = " (warn: XFAIL section but test passes)"; }else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'PASSED'; } } @@ -1899,6 +1990,12 @@ $info = " (warn: XFAIL section but test passes)"; }else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'PASSED'; } } @@ -1994,6 +2091,23 @@ if (isset($old_php)) { $php = $old_php; } + + if ($JUNIT) { + $JUNIT['result_xml'] .= '<testcase classname="'. str_replace($cwd . '/', '', $tested_file).'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['test_total']++; + if (in_array('XFAIL', $restype)) { + $JUNIT['test_pass']++; + } + elseif (in_array('FAIL', $restype)) { + $JUNIT['test_fail']++; + $JUNIT['result_xml'] .= '<failure type="'.$restype[0].'ED" message="'.$info.'"><![CDATA['."\n".$diff."\n".']]></failure>'."\n"; + } + else{ + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<error type="'.$restype[0].'ED" message="'.$info.'"><![CDATA['."\n".$diff."\n".']]></error>'."\n"; + } + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return $restype[0] . 'ED'; } @@ -2481,6 +2595,20 @@ } } +function save_junit_xml() { + global $JUNIT; + $JUNIT['finished_at'] = microtime(true); + $JUNIT['execution_time']= number_format(($JUNIT['finished_at']-$JUNIT['started_at']), 2); + $JUNIT['result_xml'] = '<?xml version="1.0" encoding="UTF-8"?>'."\n". + '<testsuites>'."\n". + '<testsuite name="php-src" tests="'.$JUNIT['test_total'].'" failures="'.$JUNIT['test_fail'].'" errors="'.$JUNIT['test_error'].'" skip="'.$JUNIT['test_skip'].'" time="'.$JUNIT['execution_time'].'">'."\n". + $JUNIT['result_xml']. + '</testsuite>'."\n". + '</testsuites>'; + fwrite($JUNIT['fp'], $JUNIT['result_xml']); +} + + /* * Local variables: * tab-width: 4 Modified: php/php-src/branches/PHP_5_4/run-tests.php =================================================================== --- php/php-src/branches/PHP_5_4/run-tests.php 2011-11-26 19:04:51 UTC (rev 319966) +++ php/php-src/branches/PHP_5_4/run-tests.php 2011-11-26 20:18:03 UTC (rev 319967) @@ -200,6 +200,26 @@ $DETAILED = 0; } +// Check whether a junit log is wanted. +$JUNIT = getenv('TEST_PHP_JUNIT'); +if (empty($JUNIT) || (!file_exists($JUNIT) && !is_writable(dirname($JUNIT))) || (file_exists($JUNIT) && !is_writable($JUNIT)) || !($JUNIT = @fopen($JUNIT, 'w'))) { + $JUNIT = FALSE; +} +else{ + $JUNIT = array( + 'fp' => $JUNIT, + 'test_total' => 0, + 'test_pass' => 0, + 'test_fail' => 0, + 'test_error' => 0, + 'test_skip' => 0, + 'started_at' => microtime(true), + 'finished_at' => NULL, + 'execution_time'=> NULL, + 'result_xml' => '', + ); +} + if (getenv('SHOW_ONLY_GROUPS')) { $SHOW_ONLY_GROUPS = explode(",", getenv('SHOW_ONLY_GROUPS')); } else { @@ -811,6 +831,10 @@ if ($output_file != '' && $just_save_results) { save_or_mail_results(); } + + if ($JUNIT) { + save_junit_xml(); + } if (getenv('REPORT_EXIT_STATUS') == 1 and preg_match('/FAILED(?: |$)/', implode(' ', $test_results))) { exit(1); @@ -946,6 +970,10 @@ save_or_mail_results(); +if ($JUNIT) { + save_junit_xml(); +} + if (getenv('REPORT_EXIT_STATUS') == 1 and $sum_results['FAILED']) { exit(1); } @@ -1165,6 +1193,7 @@ global $leak_check, $temp_source, $temp_target, $cfg, $environment; global $no_clean; global $valgrind_version; + global $JUNIT; $temp_filenames = null; $org_file = $file; @@ -1300,6 +1329,14 @@ 'diff' => '', 'info' => "$bork_info [$file]", ); + + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested_file, ENT_QUOTES).'" time="0">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="'.$bork_info.'" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1322,6 +1359,13 @@ $php = realpath("./sapi/cgi/php-cgi") . ' -C '; } else { show_result('SKIP', $tested, $tested_file, "reason: CGI not available"); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_skip']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="0">'."\n"; + $JUNIT['result_xml'] .= '<skipped>CGI not available</skipped>'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'SKIPPED'; } } @@ -1459,7 +1503,14 @@ $env['USE_ZEND_ALLOC'] = '1'; } + if ($JUNIT) { + $test_started_at = microtime(true); + } $output = system_with_timeout("$extra $php $pass_options -q $ini_settings -d display_errors=0 $test_skipif", $env); + if ($JUNIT) { + $test_finished_at = microtime(true); + $test_execution_time= number_format($test_finished_at-$test_started_at, 2); + } if (!$cfg['keep']['skip']) { @unlink($test_skipif); @@ -1481,6 +1532,13 @@ @unlink($test_skipif); } + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_skip']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<skipped><![CDATA['."\n".$m[1]."\n".']]></skipped>'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'SKIPPED'; } @@ -1535,6 +1593,12 @@ // a redirected test never fails $IN_REDIRECT = false; + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'REDIR'; } else { @@ -1566,6 +1630,13 @@ 'diff' => '', 'info' => "$bork_info [$file]", ); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="'.$bork_info.'" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1619,6 +1690,13 @@ $env['REQUEST_METHOD'] = 'POST'; if (empty($request)) { + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="empty $request" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1681,7 +1759,14 @@ COMMAND $cmd "; + if ($JUNIT) { + $test_started_at = microtime(true); + } $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null); + if ($JUNIT) { + $test_finished_at = microtime(true); + $test_execution_time= number_format($test_finished_at-$test_started_at, 2); + } if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { @@ -1870,6 +1955,12 @@ $info = " (warn: XFAIL section but test passes)"; }else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'PASSED'; } } @@ -1899,6 +1990,12 @@ $info = " (warn: XFAIL section but test passes)"; }else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'PASSED'; } } @@ -1994,6 +2091,23 @@ if (isset($old_php)) { $php = $old_php; } + + if ($JUNIT) { + $JUNIT['result_xml'] .= '<testcase classname="'. str_replace($cwd . '/', '', $tested_file).'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['test_total']++; + if (in_array('XFAIL', $restype)) { + $JUNIT['test_pass']++; + } + elseif (in_array('FAIL', $restype)) { + $JUNIT['test_fail']++; + $JUNIT['result_xml'] .= '<failure type="'.$restype[0].'ED" message="'.$info.'"><![CDATA['."\n".$diff."\n".']]></failure>'."\n"; + } + else{ + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<error type="'.$restype[0].'ED" message="'.$info.'"><![CDATA['."\n".$diff."\n".']]></error>'."\n"; + } + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return $restype[0] . 'ED'; } @@ -2481,6 +2595,20 @@ } } +function save_junit_xml() { + global $JUNIT; + $JUNIT['finished_at'] = microtime(true); + $JUNIT['execution_time']= number_format(($JUNIT['finished_at']-$JUNIT['started_at']), 2); + $JUNIT['result_xml'] = '<?xml version="1.0" encoding="UTF-8"?>'."\n". + '<testsuites>'."\n". + '<testsuite name="php-src" tests="'.$JUNIT['test_total'].'" failures="'.$JUNIT['test_fail'].'" errors="'.$JUNIT['test_error'].'" skip="'.$JUNIT['test_skip'].'" time="'.$JUNIT['execution_time'].'">'."\n". + $JUNIT['result_xml']. + '</testsuite>'."\n". + '</testsuites>'; + fwrite($JUNIT['fp'], $JUNIT['result_xml']); +} + + /* * Local variables: * tab-width: 4 Modified: php/php-src/trunk/run-tests.php =================================================================== --- php/php-src/trunk/run-tests.php 2011-11-26 19:04:51 UTC (rev 319966) +++ php/php-src/trunk/run-tests.php 2011-11-26 20:18:03 UTC (rev 319967) @@ -200,6 +200,26 @@ $DETAILED = 0; } +// Check whether a junit log is wanted. +$JUNIT = getenv('TEST_PHP_JUNIT'); +if (empty($JUNIT) || (!file_exists($JUNIT) && !is_writable(dirname($JUNIT))) || (file_exists($JUNIT) && !is_writable($JUNIT)) || !($JUNIT = @fopen($JUNIT, 'w'))) { + $JUNIT = FALSE; +} +else{ + $JUNIT = array( + 'fp' => $JUNIT, + 'test_total' => 0, + 'test_pass' => 0, + 'test_fail' => 0, + 'test_error' => 0, + 'test_skip' => 0, + 'started_at' => microtime(true), + 'finished_at' => NULL, + 'execution_time'=> NULL, + 'result_xml' => '', + ); +} + if (getenv('SHOW_ONLY_GROUPS')) { $SHOW_ONLY_GROUPS = explode(",", getenv('SHOW_ONLY_GROUPS')); } else { @@ -811,6 +831,10 @@ if ($output_file != '' && $just_save_results) { save_or_mail_results(); } + + if ($JUNIT) { + save_junit_xml(); + } if (getenv('REPORT_EXIT_STATUS') == 1 and preg_match('/FAILED(?: |$)/', implode(' ', $test_results))) { exit(1); @@ -946,6 +970,10 @@ save_or_mail_results(); +if ($JUNIT) { + save_junit_xml(); +} + if (getenv('REPORT_EXIT_STATUS') == 1 and $sum_results['FAILED']) { exit(1); } @@ -1165,6 +1193,7 @@ global $leak_check, $temp_source, $temp_target, $cfg, $environment; global $no_clean; global $valgrind_version; + global $JUNIT; $temp_filenames = null; $org_file = $file; @@ -1300,6 +1329,14 @@ 'diff' => '', 'info' => "$bork_info [$file]", ); + + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested_file, ENT_QUOTES).'" time="0">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="'.$bork_info.'" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1322,6 +1359,13 @@ $php = realpath("./sapi/cgi/php-cgi") . ' -C '; } else { show_result('SKIP', $tested, $tested_file, "reason: CGI not available"); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_skip']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="0">'."\n"; + $JUNIT['result_xml'] .= '<skipped>CGI not available</skipped>'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'SKIPPED'; } } @@ -1459,7 +1503,14 @@ $env['USE_ZEND_ALLOC'] = '1'; } + if ($JUNIT) { + $test_started_at = microtime(true); + } $output = system_with_timeout("$extra $php $pass_options -q $ini_settings -d display_errors=0 $test_skipif", $env); + if ($JUNIT) { + $test_finished_at = microtime(true); + $test_execution_time= number_format($test_finished_at-$test_started_at, 2); + } if (!$cfg['keep']['skip']) { @unlink($test_skipif); @@ -1481,6 +1532,13 @@ @unlink($test_skipif); } + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_skip']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<skipped><![CDATA['."\n".$m[1]."\n".']]></skipped>'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'SKIPPED'; } @@ -1535,6 +1593,12 @@ // a redirected test never fails $IN_REDIRECT = false; + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'REDIR'; } else { @@ -1566,6 +1630,13 @@ 'diff' => '', 'info' => "$bork_info [$file]", ); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="'.$bork_info.'" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1619,6 +1690,13 @@ $env['REQUEST_METHOD'] = 'POST'; if (empty($request)) { + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '<error type="BORKED" message="empty $request" />'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'BORKED'; } @@ -1681,7 +1759,14 @@ COMMAND $cmd "; + if ($JUNIT) { + $test_started_at = microtime(true); + } $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null); + if ($JUNIT) { + $test_finished_at = microtime(true); + $test_execution_time= number_format($test_finished_at-$test_started_at, 2); + } if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { @@ -1870,6 +1955,12 @@ $info = " (warn: XFAIL section but test passes)"; }else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'PASSED'; } } @@ -1899,6 +1990,12 @@ $info = " (warn: XFAIL section but test passes)"; }else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); + if ($JUNIT) { + $JUNIT['test_total']++; + $JUNIT['test_pass']++; + $JUNIT['result_xml'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return 'PASSED'; } } @@ -1994,6 +2091,23 @@ if (isset($old_php)) { $php = $old_php; } + + if ($JUNIT) { + $JUNIT['result_xml'] .= '<testcase classname="'. str_replace($cwd . '/', '', $tested_file).'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n"; + $JUNIT['test_total']++; + if (in_array('XFAIL', $restype)) { + $JUNIT['test_pass']++; + } + elseif (in_array('FAIL', $restype)) { + $JUNIT['test_fail']++; + $JUNIT['result_xml'] .= '<failure type="'.$restype[0].'ED" message="'.$info.'"><![CDATA['."\n".$diff."\n".']]></failure>'."\n"; + } + else{ + $JUNIT['test_error']++; + $JUNIT['result_xml'] .= '<error type="'.$restype[0].'ED" message="'.$info.'"><![CDATA['."\n".$diff."\n".']]></error>'."\n"; + } + $JUNIT['result_xml'] .= '</testcase>'."\n"; + } return $restype[0] . 'ED'; } @@ -2481,6 +2595,20 @@ } } +function save_junit_xml() { + global $JUNIT; + $JUNIT['finished_at'] = microtime(true); + $JUNIT['execution_time']= number_format(($JUNIT['finished_at']-$JUNIT['started_at']), 2); + $JUNIT['result_xml'] = '<?xml version="1.0" encoding="UTF-8"?>'."\n". + '<testsuites>'."\n". + '<testsuite name="php-src" tests="'.$JUNIT['test_total'].'" failures="'.$JUNIT['test_fail'].'" errors="'.$JUNIT['test_error'].'" skip="'.$JUNIT['test_skip'].'" time="'.$JUNIT['execution_time'].'">'."\n". + $JUNIT['result_xml']. + '</testsuite>'."\n". + '</testsuites>'; + fwrite($JUNIT['fp'], $JUNIT['result_xml']); +} + + /* * Local variables: * tab-width: 4
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php