Permalink
Browse files

unit tests: MDL-22175 Improve unit test failure display.

When you are using helper funcitions, show all the interesting bits of the stack trace,
rather that just the line in the helper function where the failed asset was called.
  • Loading branch information...
1 parent 9476acf commit 80f752acf4364e7a460432a753975917d3449abe @timhunt timhunt committed Apr 23, 2010
Showing with 21 additions and 2 deletions.
  1. +21 −2 admin/report/unittest/ex_reporter.php
@@ -66,7 +66,7 @@ function paintPass($message) {
function paintFail($message) {
// Explicitly call grandparent, not parent::paintFail.
SimpleScorer::paintFail($message);
- $this->_paintPassFail('fail', $message);
+ $this->_paintPassFail('fail', $message, debug_backtrace());
}
/**
@@ -81,7 +81,7 @@ function paintError($message) {
/**
* Private method. Used by printPass/Fail/Error.
*/
- function _paintPassFail($passorfail, $message) {
+ function _paintPassFail($passorfail, $message, $stacktrace = null) {
global $FULLME, $CFG;
print_simple_box_start('', '100%', '', 5, $passorfail . ' generalbox');
@@ -100,6 +100,25 @@ function _paintPassFail($passorfail, $message) {
echo "<a href=\"{$url}path=$folder$file\" title=\"$this->strrunonlyfile\">$file</a>";
echo $this->strseparator, implode($this->strseparator, $breadcrumb);
echo $this->strseparator, '<br />', $this->_htmlEntities($message), "\n\n";
+ if ($stacktrace) {
+ $dotsadded = false;
+ $interestinglines = 0;
+ $filteredstacktrace = array();
+ foreach ($stacktrace as $frame) {
+ if (empty($frame['file']) || (strpos($frame['file'], 'simpletestlib') === false
+ && strpos($frame['file'], 'report/unittest') === false)) {
+ $filteredstacktrace[] = $frame;
+ $interestinglines += 1;
+ $dotsadded = false;
+ } else if (!$dotsadded) {
+ $filteredstacktrace[] = array('line' => '...', 'file' => '...');
+ $dotsadded = true;
+ }
+ }
+ if ($interestinglines > 1) {
+ echo print_object($filteredstacktrace);
+ }
+ }
print_simple_box_end();
flush();
}

0 comments on commit 80f752a

Please sign in to comment.