Skip to content

Commit 65c209d

Browse files
committed
Fix junit XML format
The junit XML format is purely documented, some existings spec like http://llg.cubic.org/docs/junit/ also provide an XSD. The testsuite tag included into itself doesn't seems to be correct, instead only a flat list is included into "testsuites" tag.
1 parent 7a96ab7 commit 65c209d

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

run-tests.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,8 +2768,12 @@ function junit_save_xml() {
27682768
global $JUNIT;
27692769
if (!junit_enabled()) return;
27702770

2771-
$xml = '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>'. PHP_EOL .
2772-
'<testsuites>' . PHP_EOL;
2771+
$xml = '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>'. PHP_EOL;
2772+
$xml .= sprintf(
2773+
'<testsuites name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL,
2774+
$JUNIT['name'], $JUNIT['test_total'], $JUNIT['test_fail'], $JUNIT['test_error'], $JUNIT['test_skip'],
2775+
$JUNIT['execution_time']
2776+
);
27732777
$xml .= junit_get_suite_xml();
27742778
$xml .= '</testsuites>';
27752779
fwrite($JUNIT['fp'], $xml);
@@ -2778,26 +2782,23 @@ function junit_save_xml() {
27782782
function junit_get_suite_xml($suite_name = '') {
27792783
global $JUNIT;
27802784

2781-
$suite = $suite_name ? $JUNIT['suites'][$suite_name] : $JUNIT;
2782-
2783-
$result = sprintf(
2784-
'<testsuite name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL,
2785-
$suite['name'], $suite['test_total'], $suite['test_fail'], $suite['test_error'], $suite['test_skip'],
2786-
$suite['execution_time']
2787-
);
2785+
$result = "";
27882786

2789-
foreach($suite['suites'] as $sub_suite) {
2790-
$result .= junit_get_suite_xml($sub_suite['name']);
2791-
}
2787+
foreach ($JUNIT['suites'] as $suite_name => $suite) {
2788+
$result .= sprintf(
2789+
'<testsuite name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL,
2790+
$suite['name'], $suite['test_total'], $suite['test_fail'], $suite['test_error'], $suite['test_skip'],
2791+
$suite['execution_time']
2792+
);
27922793

2793-
// Output files only in subsuites
2794-
if (!empty($suite_name)) {
2795-
foreach($suite['files'] as $file) {
2796-
$result .= $JUNIT['files'][$file]['xml'];
2794+
if (!empty($suite_name)) {
2795+
foreach($suite['files'] as $file) {
2796+
$result .= $JUNIT['files'][$file]['xml'];
2797+
}
27972798
}
2798-
}
27992799

2800-
$result .= '</testsuite>' . PHP_EOL;
2800+
$result .= '</testsuite>' . PHP_EOL;
2801+
}
28012802

28022803
return $result;
28032804
}

0 commit comments

Comments
 (0)