Merge lp:~smerrill/pressflow/simpletest-xml-junit into lp:pressflow

Proposed by Steven Merrill
Status: Merged
Merged at revision: not available
Proposed branch: lp:~smerrill/pressflow/simpletest-xml-junit
Merge into: lp:pressflow
Diff against target: 127 lines
1 file modified
scripts/run-tests.sh (+85/-4)
To merge this branch: bzr merge lp:~smerrill/pressflow/simpletest-xml-junit
Reviewer Review Type Date Requested Status
David Strauss Approve
Josh Koenig Approve
Review via email: mp+13224@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Steven Merrill (smerrill) wrote :

This is an implementation of d.o #602332, which extends the work done on http://www.computerminds.co.uk/hudson-and-simpletest and brings it up to sync with Pressflow r49+ / SimpleTest 6.x-2.9+.

Revision history for this message
Steven Merrill (smerrill) wrote :

As an example, this is our after build script in Hudson that leverages this script to output XML test results into the scripts/tests directory:

/usr/bin/php scripts/run-tests.sh --url http://example.com --xml scripts/tests --all

Revision history for this message
David Strauss (davidstrauss) wrote :

I'm going to run this past the folks working on Hudson at The Economist (which includes me). We're certainly using jUnit XML results with Pressflow, and I'll see how this proposed merge differs from what we're using.

Revision history for this message
David Strauss (davidstrauss) wrote :

One note, though. This needs to stay in the Pressflow version because Pressflow uses the D7 CLI detection method:
simpletest_script_init(NULL);

Revision history for this message
Josh Koenig (joshkoenig) wrote :

This looks quite good to me, and is actually somewhat better than the legacy script we are using now.

I like the notion of reading test results from the database after they're complete rather than building in real-time.

I also like using DomDocument rather than SimpleXML as I've seen SimpleXML choke in some cases by being unreasonably strict.

I approve of this merge. I would also like to get Jimmy (boombatower) to think about including something like this in D7, but am happy if Pressflow leads on this. :)

review: Approve
Revision history for this message
Josh Koenig (joshkoenig) wrote :

Ah, I see it's on d.o already. Duh. +1'ed it there also.

Nice Work!

> This looks quite good to me, and is actually somewhat better than the legacy
> script we are using now.
>
> I like the notion of reading test results from the database after they're
> complete rather than building in real-time.
>
> I also like using DomDocument rather than SimpleXML as I've seen SimpleXML
> choke in some cases by being unreasonably strict.
>
> I approve of this merge. I would also like to get Jimmy (boombatower) to think
> about including something like this in D7, but am happy if Pressflow leads on
> this. :)

60. By Steven Merrill

Code style cleanups.

61. By Steven Merrill

A few more small style tweaks.

62. By Steven Merrill

Change to use Pressflow/D7-style cli detection.

Revision history for this message
Steven Merrill (smerrill) wrote :

I've updated this branch to use the D7-style CLI detection and cleaned up the code style a bit, including removing the commented-out code.

I just double-checked it on a full Hudson-initiated run of all of our SimpleTests and it's working fine.

Revision history for this message
David Strauss (davidstrauss) wrote :

Merging now...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'scripts/run-tests.sh'
--- scripts/run-tests.sh 2009-09-20 21:01:42 +0000
+++ scripts/run-tests.sh 2009-10-15 00:29:09 +0000
@@ -98,8 +98,16 @@
98list($last_prefix, $last_test_class) = simpletest_last_test_get($test_id);98list($last_prefix, $last_test_class) = simpletest_last_test_get($test_id);
99simpletest_log_read($test_id, $last_prefix, $last_test_class);99simpletest_log_read($test_id, $last_prefix, $last_test_class);
100100
101// Display results before database is cleared.101if ($args['xml']) {
102simpletest_script_reporter_display_results();102 echo $args['xml'];
103 // Save results as xml before database is cleared.
104 simpletest_script_reporter_xml_results();
105
106}
107else {
108 // Display results before database is cleared.
109 simpletest_script_reporter_display_results();
110}
103111
104// Cleanup our test results.112// Cleanup our test results.
105simpletest_clean_results_table($test_id);113simpletest_clean_results_table($test_id);
@@ -149,6 +157,9 @@
149157
150 --verbose Output detailed assertion messages in addition to summary.158 --verbose Output detailed assertion messages in addition to summary.
151159
160 --xml Output verbose test results to a specified directory using the JUnit
161 test reporting format. Useful for integrating with Hudson.
162
152 <test1>[,<test2>[,<test3> ...]]163 <test1>[,<test2>[,<test3> ...]]
153164
154 One or more tests to be run. By default, these are interpreted165 One or more tests to be run. By default, these are interpreted
@@ -194,7 +205,8 @@
194 'test_names' => array(),205 'test_names' => array(),
195 // Used internally.206 // Used internally.
196 'test-id' => NULL,207 'test-id' => NULL,
197 'execute-batch' => FALSE208 'execute-batch' => FALSE,
209 'xml' => '',
198 );210 );
199211
200 // Override with set values.212 // Override with set values.
@@ -274,7 +286,7 @@
274 if (!empty($args['url'])) {286 if (!empty($args['url'])) {
275 $parsed_url = parse_url($args['url']);287 $parsed_url = parse_url($args['url']);
276 $host = $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '');288 $host = $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '');
277 $path = $parsed_url['path'];289 $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
278 }290 }
279291
280 $_SERVER['HTTP_HOST'] = $host;292 $_SERVER['HTTP_HOST'] = $host;
@@ -482,6 +494,75 @@
482 echo "\n";494 echo "\n";
483}495}
484496
497/*
498 * Display test results.
499 */
500function simpletest_script_reporter_xml_results() {
501 global $args, $test_id, $results_map;
502
503 echo "\n";
504 $end = timer_stop('run-tests');
505 echo "XML Test run duration: " . format_interval($end['time'] / 1000);
506 echo "\n";
507
508 // Report results.
509 echo "Detailed test results:\n";
510 echo "----------------------\n";
511 echo "\n";
512
513 $results_map = array(
514 'pass' => 'Pass',
515 'fail' => 'Fail',
516 'exception' => 'Exception',
517 );
518
519 $results = db_query("SELECT * FROM {simpletest} WHERE test_id = %d ORDER BY test_class, message_id", $test_id);
520
521 $test_class = '';
522 $xml_files = array();
523
524 while ($result = db_fetch_object($results)) {
525 if (isset($results_map[$result->status])) {
526 if ($result->test_class != $test_class) {
527 // Display test class every time results are for new test class.
528 if (isset($xml_files[$test_class])) {
529 file_put_contents($args['xml'] . '/' . $test_class . '.xml', $xml_files[$test_class]['doc']->saveXML());
530 unset($xml_files[$test_class]);
531 }
532 $test_class = $result->test_class;
533 if (!isset($xml_files[$test_class])) {
534 $doc = new DomDocument('1.0');
535 $root = $doc->createElement('testsuite');
536 $root = $doc->appendChild($root);
537 $xml_files[$test_class] = array('doc' => $doc, 'suite' => $root);
538 }
539 }
540 // Save the result into the XML:
541 $case = $xml_files[$test_class]['doc']->createElement('testcase');
542 $case->setAttribute('classname', $test_class);
543 list($class, $name) = explode('->', $result->function, 2);
544 $case->setAttribute('name', $name);
545
546 if ($result->status == 'fail') {
547 $fail = $xml_files[$test_class]['doc']->createElement('failure');
548 $fail->setAttribute('type', 'failure');
549 $fail->setAttribute('message', $result->message_group);
550 $text = $xml_files[$test_class]['doc']->createTextNode($result->message);
551 $fail->appendChild($text);
552 $case->appendChild($fail);
553 }
554
555 $xml_files[$test_class]['suite']->appendChild($case);
556 }
557 }
558
559 // Save the last one:
560 if (isset($xml_files[$test_class])) {
561 file_put_contents($args['xml'] . '/' . $test_class . '.xml', $xml_files[$test_class]['doc']->saveXML());
562 unset($xml_files[$test_class]);
563 }
564}
565
485/**566/**
486 * Display test results.567 * Display test results.
487 */568 */

Subscribers

People subscribed via source and target branches

to status/vote changes: