Skip to content

Commit 05ac333

Browse files
alquercithePanz
authored andcommitted
fix(test): exit code of lime test
1 parent b88d698 commit 05ac333

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/vendor/lime/lime.php

+31
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class lime_test
2525
protected $options = array();
2626

2727
static protected $all_results = array();
28+
static private $instanceCount = 0;
29+
static private $allExitCode = 0;
2830

2931
public function __construct($plan = null, $options = array())
3032
{
33+
++self::$instanceCount;
34+
3135
// for BC
3236
if (!is_array($options))
3337
{
@@ -131,6 +135,8 @@ static public function to_xml($results = null)
131135

132136
public function __destruct()
133137
{
138+
--self::$instanceCount;
139+
134140
$plan = $this->results['stats']['plan'];
135141
$passed = count($this->results['stats']['passed']);
136142
$failed = count($this->results['stats']['failed']);
@@ -156,6 +162,31 @@ public function __destruct()
156162
}
157163

158164
flush();
165+
166+
self::$allExitCode |= $this->getExitCode();
167+
168+
if (0 === self::$instanceCount) {
169+
exit(self::$allExitCode);
170+
}
171+
}
172+
173+
private function getExitCode()
174+
{
175+
$plan = $this->results['stats']['plan'];
176+
$failed = count($this->results['stats']['failed']);
177+
$total = $this->results['stats']['total'];
178+
is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan));
179+
180+
if ($failed)
181+
{
182+
return 1;
183+
}
184+
else if ($total == $plan)
185+
{
186+
return 0;
187+
}
188+
189+
return 1;
159190
}
160191

161192
/**

0 commit comments

Comments
 (0)