Browse files

Introducting plain mode for test command.

Formatting output.
  • Loading branch information...
1 parent 4e2771f commit 52fc3a6c5d9eb3d80f5ad103c041d91ec6295320 @davidpersson davidpersson committed May 22, 2012
View
35 console/command/Test.php
@@ -59,6 +59,14 @@ class Test extends \lithium\console\Command {
public $verbose = false;
/**
+ * Enable plain to prevent any headers or similar decoration being output.
+ * Good for command calls embedded into other scripts.
+ *
+ * @var boolean
+ */
+ public $plain = false;
+
+ /**
* An array of closures, mapped by type, which are set up to handle different test output
* formats.
*
@@ -78,9 +86,10 @@ protected function _init() {
$this->_handlers += array(
'txt' => function($runner, $path) use ($command) {
- $command->header('Test');
- $command->out(null, 1);
-
+ if (!$command->plain) {
+ $command->header('Test');
+ $command->out(null, 1);
+ }
$colorize = function($result) {
switch (trim($result)) {
case '.':
@@ -133,15 +142,23 @@ protected function _init() {
}
};
}
-
$report = $runner(compact('reporter'));
- $command->out(null, 2);
- $command->out($report->render('stats', $report->stats()));
+ if (!$command->plain) {
+ $stats = $report->stats();
+
+ $command->out(null, 2);
+ $command->out($report->render('result', $stats));
+ $command->out($report->render('errors', $stats));
- foreach ($report->filters() as $filter => $options) {
- $data = $report->results['filters'][$filter];
- $command->out($report->render($options['name'], compact('data')));
+ if ($command->verbose) {
+ $command->out($report->render('skips', $stats));
+ }
+
+ foreach ($report->filters() as $filter => $options) {
+ $data = $report->results['filters'][$filter];
+ $command->out($report->render($options['name'], compact('data')));
+ }
}
return $report;
},
View
35 test/templates/errors.txt.php
@@ -0,0 +1,35 @@
+<?php
+
+$i = 0;
+foreach ((array) $stats['errors'] as $error) {
+ $i++;
+
+ if ($error['result'] == 'fail') {
+ echo "{:red}Failed{:end} assertion {$error['assertion']}.\n";
+ echo " File : {$error['file']}\n";
+ echo " Class : {$error['class']}\n";
+ echo " Method : {$error['method']}()\n";
+ echo " Line : {$error['line']}\n";
+ echo " ________\n";
+ echo "{$error['message']}";
+ echo " ________\n";
+ echo "\n";
+ } elseif ($error['result'] == 'exception') {
+ echo "{:purple}Exception{:end} thrown.\n";
+ echo " File : {$error['file']}\n";
+ echo " Class : {$error['class']}\n";
+ echo " Method : {$error['method']}()\n";
+ echo " Line : {$error['line']}\n";
+ echo " ________\n";
+ echo "{$error['message']}\n";
+ echo " ________\n";
+
+ if (isset($error['trace']) && !empty($error['trace'])) {
+ echo "{$error['trace']}\n";
+ echo " ________\n";
+ }
+ echo "\n";
+ }
+}
+
+?>
View
29 test/templates/result.txt.php
@@ -0,0 +1,29 @@
+<?php
+
+if ($success && $count['skips']) {
+ echo "{:green}OK, but skipped tests.{:end}\n";
+} elseif ($success) {
+ echo "{:green}OK{:end}\n";
+} else {
+ echo "{:red}FAIL{:end}\n";
+}
+echo "\n";
+
+printf(
+ "%d / %d %s\n",
+ $count['passes'],
+ $count['asserts'],
+ $count['passes'] == 1 ? 'pass' : 'passes'
+);
+printf(
+ '%d %s',
+ $count['fails'],
+ $count['fails'] == 1 ? 'fail' : 'fails'
+);
+printf(
+ " and %d %s\n",
+ $count['exceptions'],
+ $count['exceptions'] == 1 ? 'exception' : 'exceptions'
+);
+
+?>
View
12 test/templates/skips.txt.php
@@ -0,0 +1,12 @@
+<?php
+
+foreach ((array) $stats['skips'] as $skip) {
+ $trace = $skip['trace'][1];
+
+ echo "{:cyan}Skip{:end} `{$skip['message']}`.\n";
+ echo " Class : {$trace['class']}\n";
+ echo " Method : {$trace['function']}()\n";
+ echo "\n";
+}
+
+?>
View
40 test/templates/stats.txt.php
@@ -1,40 +0,0 @@
-<?php
-
-$passes = intval($count['passes']) ?: 0;
-$asserts = intval($count['asserts']) ?: 0;
-$fails = intval($count['fails']) ?: 0;
-$exceptions = intval($count['exceptions']) ?: 0;
-
-if ($success) {
- echo "{:green}OK{:end}\n";
-} else {
- echo "{:red}FAIL{:end}\n";
-}
-echo "\n";
-
-echo "{$passes} / {$asserts} passes\n";
-echo "{$fails} " . ($fails == 1 ? 'fail' : 'fails');
-echo " and {$exceptions} ";
-echo ($exceptions == 1 ? 'exception' : 'exceptions') . "\n";
-
-foreach ((array) $stats['errors'] as $error) {
- if ($error['result'] == 'fail') {
- echo "\nAssertion `{$error['assertion']}` failed in ";
- echo "`{$error['class']}::{$error['method']}()` on line ";
- echo "{$error['line']}:\n{$error['message']}";
- } elseif ($error['result'] == 'exception') {
- echo "Exception thrown in `{$error['class']}::{$error['method']}()` ";
- echo "on line {$error['line']}:\n{$error['message']}";
- if (isset($error['trace']) && !empty($error['trace'])) {
- echo "Trace: {$error['trace']}\n";
- }
- }
-}
-foreach ((array) $stats['skips'] as $skip) {
- $trace = $skip['trace'][1];
- echo "Skip `{$trace['class']}::{$trace['function']}()` ";
- echo "on line {$trace['line']}:\n";
- echo "{$skip['message']}\n";
-}
-
-?>
View
10 tests/cases/console/command/TestTest.php
@@ -99,7 +99,7 @@ public function testRunSingleTestWithAbsolutePath() {
$path = LITHIUM_LIBRARY_PATH . '/lithium/tests/mocks/test/cases/MockTest.php';
$command->run($path);
- $expected = "1 passes\n0 fails and 0 exceptions\n";
+ $expected = "1 pass\n0 fails and 0 exceptions\n";
$expected = preg_quote($expected);
$result = $command->response->output;
$this->assertPattern("/{$expected}/", $result);
@@ -113,7 +113,7 @@ public function testRunSingleTestWithRelativePath() {
$path = 'tests/mocks/test/cases/MockTest.php';
$command->run($path);
- $expected = "1 passes\n0 fails and 0 exceptions\n";
+ $expected = "1 pass\n0 fails and 0 exceptions\n";
$expected = preg_quote($expected);
$result = $command->response->output;
$this->assertPattern("/{$expected}/", $result);
@@ -126,7 +126,7 @@ public function testRunSingleTestWithRelativePath() {
$path = "../{$current}/tests/mocks/test/cases/MockTest.php";
$command->run($path);
- $expected = "1 passes\n0 fails and 0 exceptions\n";
+ $expected = "1 pass\n0 fails and 0 exceptions\n";
$expected = preg_quote($expected);
$result = $command->response->output;
$this->assertPattern("/{$expected}/", $result);
@@ -135,7 +135,7 @@ public function testRunSingleTestWithRelativePath() {
$path = "{$current}/tests/mocks/test/cases/MockTest.php";
$command->run($path);
- $expected = "1 passes\n0 fails and 0 exceptions\n";
+ $expected = "1 pass\n0 fails and 0 exceptions\n";
$expected = preg_quote($expected);
$result = $command->response->output;
$this->assertPattern("/{$expected}/", $result);
@@ -148,7 +148,7 @@ public function testRunMultipleTestsWithAbsolutePath() {
$path = LITHIUM_LIBRARY_PATH . '/lithium/tests/mocks/test/cases';
$command->run($path);
- $expected = "1 / 1 passes\n0 fails and 2 exceptions\n";
+ $expected = "1 / 1 pass\n0 fails and 2 exceptions\n";
$expected = preg_quote($expected, '/');
$result = $command->response->output;
$this->assertPattern("/{$expected}/", $result);

0 comments on commit 52fc3a6

Please sign in to comment.