mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FEATURE: Added coloured output to dev/tests/all
API CHANGE: Added SSCli class to help with outputting coloured text on the command line git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63637 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
13b7b4c4e7
commit
a79ab917c7
@ -14,7 +14,7 @@ class CliDebugView extends DebugView {
|
||||
/**
|
||||
* Render HTML header for development views
|
||||
*/
|
||||
public function writeHeader($httpRequest) {
|
||||
public function writeHeader($httpRequest = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,8 +28,8 @@ class CliDebugView extends DebugView {
|
||||
*/
|
||||
public function writeError($httpRequest, $errno, $errstr, $errfile, $errline, $errcontext) {
|
||||
$errorType = self::$error_types[$errno];
|
||||
echo "ERROR [" . $errorType['title'] . "]: $errstr\nIN $httpRequest\n";
|
||||
echo "Line $errline in $errfile\n\n";
|
||||
echo SSCli::text("ERROR [" . $errorType['title'] . "]: $errstr\nIN $httpRequest\n", "red", null, true);
|
||||
echo SSCli::text("Line $errline in $errfile\n\n", "red");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,18 +20,24 @@ class CliTestReporter extends SapphireTestReporter {
|
||||
($test['status'] == 1) ? $passCount++ : $failCount++;
|
||||
}
|
||||
}
|
||||
$result = ($failCount > 0) ? 'fail' : 'pass';
|
||||
echo "\n\n$testCount tests run: $passCount passes, $failCount fails, and 0 exceptions\n\n";
|
||||
|
||||
echo "\n\n";
|
||||
if ($failCount == 0) {
|
||||
echo SSCli::text(" ALL TESTS PASS ", "white", "green");
|
||||
} else {
|
||||
echo SSCli::text(" AT LEAST ONE FAILURE ", "white", "red");
|
||||
}
|
||||
echo "\n\n$testCount tests run: " . SSCli::text("$passCount passes", $passCount > 0 ? "green" : null) . ", ". SSCli::text("$failCount fails", $failCount > 0 ? "red" : null) . ", and 0 exceptions\n\n";
|
||||
}
|
||||
|
||||
public function endTest( PHPUnit_Framework_Test $test, $time) {
|
||||
// Status indicator, a la PHPUnit
|
||||
switch($this->currentTest['status']) {
|
||||
case TEST_FAILURE: echo "F"; break;
|
||||
case TEST_ERROR: echo "E"; break;
|
||||
case TEST_INCOMPLETE: echo "I"; break;
|
||||
case TEST_SUCCESS: echo "."; break;
|
||||
default: echo "?"; break;
|
||||
case TEST_FAILURE: echo SSCli::text("F","red", null, true); break;
|
||||
case TEST_ERROR: echo SSCli::text("E","red", null, true); break;
|
||||
case TEST_INCOMPLETE: echo SSCli::text("I","yellow"); break;
|
||||
case TEST_SUCCESS: echo SSCli::text(".","green"); break;
|
||||
default: echo SSCli::text("?", "yellow"); break;
|
||||
}
|
||||
|
||||
static $colCount = 0;
|
||||
@ -45,8 +51,8 @@ class CliTestReporter extends SapphireTestReporter {
|
||||
|
||||
protected function writeTest($test) {
|
||||
if ($test['status'] != 1) {
|
||||
echo $this->testNameToPhrase($test['name']) . "\n". $test['message'] . "\n";
|
||||
echo "In line {$test['exception']['line']} of {$test['exception']['file']}" . "\n\n";
|
||||
echo "\n\n" . SSCli::text($this->testNameToPhrase($test['name']) . "\n". $test['message'] . "\n", 'red', null, true);
|
||||
echo SSCli::text("In line {$test['exception']['line']} of {$test['exception']['file']}" . "\n\n", 'red ');
|
||||
echo Debug::get_rendered_backtrace($test['trace'], true);
|
||||
echo "\n--------------------\n";
|
||||
}
|
||||
|
50
dev/SSCli.php
Normal file
50
dev/SSCli.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class to facilitate command-line output.
|
||||
* Support less-trivial output stuff such as colours (on xterm-color)
|
||||
*/
|
||||
class SSCli extends Object {
|
||||
/**
|
||||
* Return text encoded for CLI output, optionally coloured
|
||||
* @param string $fgColour The foreground colour - black, red, green, yellow, blue, magenta, cyan, white. Null is default.
|
||||
* @param string $bgColour The foreground colour - black, red, green, yellow, blue, magenta, cyan, white. Null is default.
|
||||
* @param string $bold A boolean variable - bold or not.
|
||||
*/
|
||||
static function text($text, $fgColour = null, $bgColour = null, $bold = false) {
|
||||
if(!isset($_SERVER['TERM']) || $_SERVER['TERM'] != 'xterm-color') return $text;
|
||||
|
||||
$colours = array(
|
||||
'black' => 0,
|
||||
'red' => 1,
|
||||
'green' => 2,
|
||||
'yellow' => 3,
|
||||
'blue' => 4,
|
||||
'magenta' => 5,
|
||||
'cyan' => 6,
|
||||
'white' => 7,
|
||||
);
|
||||
|
||||
$prefix = $suffix = "";
|
||||
|
||||
if($fgColour || $bgColour || $bold) {
|
||||
$suffix .= "\033[0m";
|
||||
|
||||
if($fgColour || $bold) {
|
||||
if(!$fgColour) $fgColour = "white";
|
||||
$prefix .= "\033[" . ($bold ? "1;" :"") . "3" . $colours[$fgColour] . "m";
|
||||
}
|
||||
|
||||
|
||||
if($bgColour) {
|
||||
$prefix .= "\033[4" . $colours[$bgColour] . "m";
|
||||
}
|
||||
}
|
||||
|
||||
return $prefix . $text . $suffix;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user