From 154bc18df5e0500597d39d5cb85a87fbf7bf98cc Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Mon, 1 Jan 2024 10:37:31 +0100 Subject: [PATCH] fix(test): exit code of lime test --- lib/vendor/lime/lime.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/vendor/lime/lime.php b/lib/vendor/lime/lime.php index 2d5f8986e..b5dad340f 100644 --- a/lib/vendor/lime/lime.php +++ b/lib/vendor/lime/lime.php @@ -25,9 +25,13 @@ class lime_test protected $options = array(); static protected $all_results = array(); + static private $instanceCount = 0; + static private $allExitCode = 0; public function __construct($plan = null, $options = array()) { + ++self::$instanceCount; + // for BC if (!is_array($options)) { @@ -131,6 +135,8 @@ static public function to_xml($results = null) public function __destruct() { + --self::$instanceCount; + $plan = $this->results['stats']['plan']; $passed = count($this->results['stats']['passed']); $failed = count($this->results['stats']['failed']); @@ -156,6 +162,31 @@ public function __destruct() } flush(); + + self::$allExitCode |= $this->getExitCode(); + + if (0 === self::$instanceCount) { + exit(self::$allExitCode); + } + } + + private function getExitCode() + { + $plan = $this->results['stats']['plan']; + $failed = count($this->results['stats']['failed']); + $total = $this->results['stats']['total']; + is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan)); + + if ($failed) + { + return 1; + } + else if ($total == $plan) + { + return 0; + } + + return 1; } /**