Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 136b3c1

Browse files
committedMar 4, 2024·
fix(test): exit code of lime test
1 parent edb850f commit 136b3c1

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
@@ -24,9 +24,13 @@ class lime_test
2424
protected $options = array();
2525

2626
static protected $all_results = array();
27+
static private $instanceCount = 0;
28+
static private $allExitCode = 0;
2729

2830
public function __construct($plan = null, $options = array())
2931
{
32+
++self::$instanceCount;
33+
3034
// for BC
3135
if (!is_array($options))
3236
{
@@ -130,6 +134,8 @@ static public function to_xml($results = null)
130134

131135
public function __destruct()
132136
{
137+
--self::$instanceCount;
138+
133139
$plan = $this->results['stats']['plan'];
134140
$passed = count($this->results['stats']['passed']);
135141
$failed = count($this->results['stats']['failed']);
@@ -155,6 +161,31 @@ public function __destruct()
155161
}
156162

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

160191
/**

0 commit comments

Comments
 (0)
Please sign in to comment.