Skip to content

Commit 7a96ab7

Browse files
committed
Rework junit output
- testcase classname attribute is closest to put the filename - if tests run from php checkout, don't include the full path - remove filename from the testcase description, as it's included into classname
1 parent 0b44af5 commit 7a96ab7

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

run-tests.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,7 +2748,7 @@ function junit_init() {
27482748
} else {
27492749
$JUNIT = array(
27502750
'fp' => $fp,
2751-
'name' => 'php-src',
2751+
'name' => 'PHP',
27522752
'test_total' => 0,
27532753
'test_pass' => 0,
27542754
'test_fail' => 0,
@@ -2768,7 +2768,7 @@ function junit_save_xml() {
27682768
global $JUNIT;
27692769
if (!junit_enabled()) return;
27702770

2771-
$xml = '<?xml version="1.0" encoding="UTF-8"?>'. PHP_EOL .
2771+
$xml = '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>'. PHP_EOL .
27722772
'<testsuites>' . PHP_EOL;
27732773
$xml .= junit_get_suite_xml();
27742774
$xml .= '</testsuites>';
@@ -2833,8 +2833,8 @@ function junit_mark_test_as($type, $file_name, $test_name, $time = null, $messag
28332833
}, $escaped_details);
28342834
$escaped_message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');
28352835

2836-
$escaped_test_name = basename($file_name) . ' - ' . htmlspecialchars($test_name, ENT_QUOTES);
2837-
$JUNIT['files'][$file_name]['xml'] = "<testcase classname='$suite' name='$escaped_test_name' time='$time'>\n";
2836+
$escaped_test_name = htmlspecialchars($test_name, ENT_QUOTES);
2837+
$JUNIT['files'][$file_name]['xml'] = "<testcase classname='" . $suite . "." . basename($file_name) . "' name='$escaped_test_name' time='$time'>\n";
28382838

28392839
if (is_array($type)) {
28402840
$output_type = $type[0] . 'ED';
@@ -2904,7 +2904,33 @@ function junit_get_suitename_for($file_name) {
29042904

29052905
function junit_path_to_classname($file_name) {
29062906
global $JUNIT;
2907-
return $JUNIT['name'] . '.' . str_replace(DIRECTORY_SEPARATOR, '.', $file_name);
2907+
2908+
$ret = $JUNIT['name'];
2909+
$_tmp = array();
2910+
2911+
// lookup whether we're in the PHP source checkout
2912+
$max = 5;
2913+
if (is_file($file_name)) {
2914+
$dir = dirname(realpath($file_name));
2915+
} else {
2916+
$dir = realpath($file_name);
2917+
}
2918+
do {
2919+
array_unshift($_tmp, basename($dir));
2920+
$chk = $dir . DIRECTORY_SEPARATOR . "main" . DIRECTORY_SEPARATOR . "php_version.h";
2921+
$dir = dirname($dir);
2922+
} while (!file_exists($chk) && --$max > 0);
2923+
if (file_exists($chk)) {
2924+
if ($max) {
2925+
array_shift($_tmp);
2926+
}
2927+
foreach ($_tmp as $p) {
2928+
$ret = $ret . "." . preg_replace(",[^a-z0-9]+,i", ".", $p);
2929+
}
2930+
return $ret;
2931+
}
2932+
2933+
return $JUNIT['name'] . '.' . str_replace(array(DIRECTORY_SEPARATOR, '-'), '.', $file_name);
29082934
}
29092935

29102936
function junit_init_suite($suite_name) {

0 commit comments

Comments
 (0)