Skip to content

Commit

Permalink
Refactoring breadcrumb and time generation in the CLI reporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 10, 2010
1 parent d79bacd commit bcd7d34
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions cake/tests/lib/reporter/cake_cli_reporter.php
Expand Up @@ -57,10 +57,7 @@ function setFailDetailSeparator($separator) {
*/
function paintFail($message) {
parent::paintFail($message);
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
$message .= "\n\tin " . implode("\n\tin ", array_reverse($breadcrumb));
$message .= "\n\n";
$message .= $this->_getBreadcrumb();
fwrite(STDERR, 'FAIL' . $this->separator . $message);
}

Expand All @@ -73,10 +70,7 @@ function paintFail($message) {
*/
function paintError($message) {
parent::paintError($message);
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
$message .= "\n\tin " . implode("\n\tin ", array_reverse($breadcrumb));
$message .= "\n\n";
$message .= $this->_getBreadcrumb();
fwrite(STDERR, 'ERROR' . $this->separator . $message);
}

Expand All @@ -95,11 +89,32 @@ function paintException($exception) {
$exception->getFile(),
$exception->getLine()
);
$message .= $this->_getBreadcrumb();
fwrite(STDERR, 'EXCEPTION' . $this->separator . $message);
}

/**
* Get the breadcrumb trail for the current test method/case
*
* @return string The string for the breadcrumb
*/
function _getBreadcrumb() {
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
$message .= "\n\tin " . implode("\n\tin ", array_reverse($breadcrumb));
$message .= "\n\n";
fwrite(STDERR, 'EXCEPTION' . $this->separator . $message);
$out = "\n\tin " . implode("\n\tin ", array_reverse($breadcrumb));
$out .= "\n\n";
return $out;
}

/**
* Paint a test skip message
*
* @param string $message The message of the skip
* @return void
*/
function paintSkip($message) {
parent::paintSkip($message);
fwrite(STDOUT, 'SKIP' . $this->separator . $message . "\n\n");
}

/**
Expand All @@ -117,14 +132,25 @@ function paintFooter($test_name) {
$buffer .= ", " . $this->getExceptionCount() . " exceptions";
}
$buffer .= ".\n";
$buffer .= 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
if (function_exists('memory_get_peak_usage')) {
$buffer .= 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
}
$buffer .= $this->_timeStats();
fwrite(STDOUT, $buffer);
} else {
fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n");
fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n" . $this->_timeStats());
}
}

/**
* Get the time and memory stats for this test case/group
*
* @return string String content to display
* @access protected
*/
function _timeStats() {
$out = 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
if (function_exists('memory_get_peak_usage')) {
$out .= 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
}
return $out;
}
}
?>

0 comments on commit bcd7d34

Please sign in to comment.