@@ -24,9 +24,13 @@ class lime_test
24
24
protected $ options = array ();
25
25
26
26
static protected $ all_results = array ();
27
+ static private $ instanceCount = 0 ;
28
+ static private $ allExitCode = 0 ;
27
29
28
30
public function __construct ($ plan = null , $ options = array ())
29
31
{
32
+ ++self ::$ instanceCount ;
33
+
30
34
// for BC
31
35
if (!is_array ($ options ))
32
36
{
@@ -130,6 +134,8 @@ static public function to_xml($results = null)
130
134
131
135
public function __destruct ()
132
136
{
137
+ --self ::$ instanceCount ;
138
+
133
139
$ plan = $ this ->results ['stats ' ]['plan ' ];
134
140
$ passed = count ($ this ->results ['stats ' ]['passed ' ]);
135
141
$ failed = count ($ this ->results ['stats ' ]['failed ' ]);
@@ -155,6 +161,31 @@ public function __destruct()
155
161
}
156
162
157
163
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 ;
158
189
}
159
190
160
191
/**
0 commit comments