Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add junit xml output to test script #7966

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions hphp/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ function get_options($argv) {
'verbose' => 'v',
'fbmake' => '',
'testpilot' => '',
'xml' => '',
'threads:' => '',
'args:' => 'a:',
'log' => 'l',
Expand Down Expand Up @@ -1118,6 +1119,7 @@ class Status {
private static $mode = 0;

private static $use_color = false;
private static $xml = false;

private static $queue = null;
private static $killed = false;
Expand Down Expand Up @@ -1188,10 +1190,18 @@ class Status {
self::$use_color = $use;
}

public static function setXml($xml) {
self::$xml = $xml;
}

public static function getMode() {
return self::$mode;
}

public static function getXml() {
return self::$xml;
}

public static function getOverallStartTime() {
return self::$overall_start_time;
}
Expand Down Expand Up @@ -2207,6 +2217,15 @@ function make_header($str) {
return "\n\033[0;33m".$str."\033[0m\n";
}

function print_xml_name($fp, $test) {
fputs($fp,
sprintf(" <testcase classname='%s' name='%s'>\n",
dirname($test), # directory, specifiying a package of tests
basename($test) # test name inside of that package
)
);
}

function print_commands($tests, $options) {
print make_header("Run these by hand:");

Expand Down Expand Up @@ -2272,6 +2291,11 @@ function msg_loop($num_tests, $queue) {
}
}

if (Status::getXml()) {
$fp = fopen('/tmp/hphp-tests.xml', "w");
fputs($fp, sprintf("<testsuite tests='%d'>\n", $num_tests));
}

while (true) {
if (!msg_receive($queue, 0, $type, 1024, $message)) {
error("msg_receive failed");
Expand Down Expand Up @@ -2338,6 +2362,9 @@ function msg_loop($num_tests, $queue) {
case Status::MODE_RECORD_FAILURES:
break;
}
if (Status::getXml()) {
print_xml_name($fp, $test);
}
break;

case Status::MSG_TEST_SKIP:
Expand Down Expand Up @@ -2371,6 +2398,11 @@ function msg_loop($num_tests, $queue) {
case Status::MODE_RECORD_FAILURES:
break;
}
if (Status::getXml()) {
print_xml_name($fp, $test);
fputs($fp," <skipped/>\n");
fputs($fp," </testcase>\n");
}
break;

case Status::MSG_TEST_FAIL:
Expand Down Expand Up @@ -2402,6 +2434,11 @@ function msg_loop($num_tests, $queue) {
case Status::MODE_RECORD_FAILURES:
break;
}
if (Status::getXml()) {
print_xml_name($fp, $test);
fputs($fp," <failure/>\n");
fputs($fp," </testcase>\n");
}
break;

default:
Expand Down Expand Up @@ -2434,6 +2471,11 @@ function msg_loop($num_tests, $queue) {
}
}

if (Status::getXml()) {
fputs($fp, "</testsuite>\n");
$fp = fclose($fp);
}

if ($do_progress) {
print "\033[2K\033[1G";
if ($skipped > 0) {
Expand Down Expand Up @@ -2933,6 +2975,7 @@ function main($argv) {
Status::setMode(Status::MODE_RECORD_FAILURES);
}
Status::setUseColor(isset($options['color']) ? true : posix_isatty(STDOUT));
Status::setXml(isset($options['xml']));

Status::$key = rand();
$queue = Status::getQueue();
Expand Down