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