Permalink
Browse files

Exit with status 1 if error occurs

  • Loading branch information...
1 parent 01d7d5c commit 997ab8f7f9333143dcd3855b02a261a51a86feaa Amjad Mohamed committed Oct 23, 2011
View
@@ -23,6 +23,7 @@
use \PHPSpec\Runner\Runner,
\PHPSpec\Runner\Reporter,
+ \PHPSpec\Runner\ReporterEvent,
\PHPSpec\Runner\Parser,
\PHPSpec\World,
\PHPSpec\Runner\Cli\Parser as CliParser,
@@ -142,7 +143,7 @@ protected function loadAndRun()
protected function output()
{
$this->makeSureWeHaveAFormatter();
- $this->_reporter->getFormatter()->output();
+ $this->_reporter->notify(new ReporterEvent('exit', '', ''));
}
/**
@@ -55,13 +55,14 @@ public function update(\SplSubject $method, $reporterEvent = null)
break;
case 'exit':
$this->output();
- exit(0);
+ $this->_onExit();
break;
}
}
abstract protected function _startRenderingExampleGroup($reporterEvent);
abstract protected function _finishRenderingExampleGroup();
abstract protected function _renderExamples($reporterEvent);
+ abstract protected function _onExit();
}
@@ -50,6 +50,7 @@ class Junit extends Progress
private $_pending = 0;
private $_total = 0;
private $_complete = 0;
+ private $_errorOnExit = false;
public function __construct (Reporter $reporter)
{
@@ -88,6 +89,10 @@ protected function _finishRenderingExampleGroup()
$this->_result .= $output;
$this->_examples = '';
+ if ($this->_errors > 0 || $this->_failures > 0) {
+ $this->_errorOnExit = true;
+ }
+
$this->_total = 0;
$this->_failures = 0;
$this->_errors = 0;
@@ -207,6 +212,14 @@ protected function getLine($traceline, $relativePosition, $style = 'normal')
return ' ' . $code . PHP_EOL;
}
+ protected function _onExit()
+ {
+ if ($this->_errorOnExit) {
+ exit(1);
+ }
+ exit(0);
+ }
+
/**
* @return SimpleXMLElement
* <testcase name="testNothing" class="TestDummy"
@@ -57,6 +57,8 @@ class Progress extends FormatterAbstract
*/
protected $_enableBacktrace = false;
+ private $_errorOnExit = false;
+
/**
* Creates a progress formatter, decorates a reporter
*
@@ -344,6 +346,10 @@ protected function getTotals()
$total = $failures + $errors + $pending + $exceptions + $passing;
+ if (($failures + $errors + $pending + $exceptions) > 0) {
+ $this->_errorOnExit = true;
+ }
+
$totals = "$total example" . ($total !== 1 ? "s" : "");
if ($failures) {
$plural = $failures !== 1 ? "s" : "";
@@ -465,6 +471,14 @@ public function yellow($output)
return $output;
}
+ protected function _onExit()
+ {
+ if ($this->_errorOnExit) {
+ exit(1);
+ }
+ exit(0);
+ }
+
/**
* Outputs to standard output
*

0 comments on commit 997ab8f

Please sign in to comment.