@@ -7,7 +7,6 @@ package hx.doctest;
7
7
8
8
import haxe .PosInfos ;
9
9
import haxe .Timer ;
10
-
11
10
import hx .doctest .internal .DocTestUtils ;
12
11
import hx .doctest .internal .Logger ;
13
12
@@ -21,6 +20,8 @@ class DocTestRunner {
21
20
travix. Logger .exit (exitCode );
22
21
#else
23
22
#if sys
23
+ Sys .stderr ().flush ();
24
+ Sys .stdout ().flush ();
24
25
Sys .exit (exitCode );
25
26
#elseif js
26
27
final isPhantomJSDirectExecution = js. Syntax .code (" (typeof phantom !== 'undefined')" );
@@ -67,7 +68,10 @@ class DocTestRunner {
67
68
* look for functions starting with "test" and invoke them
68
69
*/
69
70
Logger .log (DEBUG , ' Looking for test cases in [ ${thisClassName }]...' );
70
- final funcNames = [ for (funcName in Type .getInstanceFields (thisClass )) if (funcName .startsWith (" test" )) funcName ];
71
+ final funcNames = [
72
+ for (funcName in Type .getInstanceFields (thisClass ))
73
+ if (funcName .startsWith (" test" )) funcName
74
+ ];
71
75
funcNames .sort ((a , b ) -> a < b ? - 1 : a > b ? 1 : 0 );
72
76
for (funcName in funcNames ) {
73
77
final func : Null <Dynamic > = Reflect .field (this , funcName );
@@ -113,7 +117,6 @@ class DocTestRunner {
113
117
return testsFailed ;
114
118
}
115
119
116
-
117
120
/**
118
121
* Runs the accumulated doc tests and exits the process with exit code 0 in case all
119
122
* tests were passed or 1 in case test failures occured.
@@ -123,15 +126,13 @@ class DocTestRunner {
123
126
exit (exitCode );
124
127
}
125
128
126
-
127
129
/**
128
130
* for use within manually created test method
129
131
*/
130
132
@:nullSafety (Off ) // TODO https://github.com/HaxeFoundation/haxe/issues/10272
131
133
function assertEquals (leftResult : Null <Dynamic >, rightResult : Null <Dynamic >, ? pos : PosInfos ): Void
132
134
results .add (DocTestUtils .deepEquals (leftResult , rightResult ), ' assertEquals( $leftResult , $rightResult )' , pos );
133
135
134
-
135
136
/**
136
137
* for use within manually created test method
137
138
*/
@@ -140,7 +141,6 @@ class DocTestRunner {
140
141
results .add (! result , ' assertFalse( $result )' , pos );
141
142
}
142
143
143
-
144
144
/**
145
145
* for use within manually created test method
146
146
*/
@@ -150,7 +150,6 @@ class DocTestRunner {
150
150
results .add (result >= min && result <= max , ' assertInRange( $result , $min , $max )' , pos );
151
151
}
152
152
153
-
154
153
/**
155
154
* for use within manually created test method
156
155
*/
@@ -159,7 +158,6 @@ class DocTestRunner {
159
158
results .add (result <= max , ' assertMax( $result , $max )' , pos );
160
159
}
161
160
162
-
163
161
/**
164
162
* for use within manually created test method
165
163
*/
@@ -168,31 +166,27 @@ class DocTestRunner {
168
166
results .add (result >= min , ' assertMin( $result , $min )' , pos );
169
167
}
170
168
171
-
172
169
/**
173
170
* for use within manually created test method
174
171
*/
175
172
@:nullSafety (Off ) // TODO https://github.com/HaxeFoundation/haxe/issues/10272
176
173
function assertNotSame (leftResult : Null <Dynamic >, rightResult : Null <Dynamic >, ? pos : PosInfos ): Void
177
174
results .add (leftResult != rightResult , ' assertNotSame( $leftResult , $rightResult )' , pos );
178
175
179
-
180
176
/**
181
177
* for use within manually created test method
182
178
*/
183
179
@:nullSafety (Off ) // TODO https://github.com/HaxeFoundation/haxe/issues/10272
184
180
function assertNotEquals (leftResult : Null <Dynamic >, rightResult : Null <Dynamic >, ? pos : PosInfos ): Void
185
181
results .add (! DocTestUtils .deepEquals (leftResult , rightResult ), ' assertNotEquals( $leftResult , $rightResult )' , pos );
186
182
187
-
188
183
/**
189
184
* for use within manually created test method
190
185
*/
191
186
@:nullSafety (Off ) // TODO https://github.com/HaxeFoundation/haxe/issues/10272
192
187
function assertSame (leftResult : Null <Dynamic >, rightResult : Null <Dynamic >, ? pos : PosInfos ): Void
193
188
results .add (leftResult == rightResult , ' assertSame( $leftResult , $rightResult )' , pos );
194
189
195
-
196
190
/**
197
191
* for use within manually created test method
198
192
*/
@@ -201,7 +195,6 @@ class DocTestRunner {
201
195
results .add (result , ' assertTrue( $result )' , pos );
202
196
}
203
197
204
-
205
198
/**
206
199
* for use within manually created test method
207
200
*/
@@ -210,7 +203,6 @@ class DocTestRunner {
210
203
results .add (false , msg , pos );
211
204
}
212
205
213
-
214
206
@:allow (hx.doctest. DocTestResults )
215
207
function onDocTestResult (result : DocTestResult ) {
216
208
final pos : PosInfosExt = {
@@ -233,8 +225,10 @@ interface DocTestResults {
233
225
var testsPassed (default , null ): Int ;
234
226
var testsFailed (default , null ): Int ;
235
227
228
+
236
229
function add (success : Bool , msg : String , pos : haxe. PosInfos ): Void ;
237
230
231
+
238
232
/**
239
233
* @deprecated use `DocTestResults#testsFailed`
240
234
*/
@@ -256,6 +250,7 @@ interface DocTestResults {
256
250
257
251
258
252
class DocTestResult {
253
+
259
254
public final date = Date .now ();
260
255
public final testPassed : Bool ;
261
256
public final msg : String ;
@@ -270,10 +265,9 @@ class DocTestResult {
270
265
271
266
272
267
public function toString (): String {
273
- return
274
- ' ${pos .fileName }: ${pos .lineNumber }: ' +
275
- (pos .charStart == null ? " " : ' characters ${pos .charStart }- ${pos .charEnd }: ' ) +
276
- ' [ ${testPassed ? " OK" : " ERROR" }] $msg ' ;
268
+ return ' ${pos .fileName }: ${pos .lineNumber }: '
269
+ + (pos .charStart == null ? " " : ' characters ${pos .charStart }- ${pos .charEnd }: ' )
270
+ + ' [ ${testPassed ? " OK" : " ERROR" }] $msg ' ;
277
271
}
278
272
}
279
273
@@ -284,6 +278,7 @@ class DefaultDocTestResults implements DocTestResults {
284
278
public var testsFailed (default , null ) = 0 ;
285
279
public var tests (default , null ): Array <DocTestResult > = [];
286
280
281
+
287
282
final runner : DocTestRunner ;
288
283
289
284
@@ -303,11 +298,13 @@ class DefaultDocTestResults implements DocTestResults {
303
298
304
299
305
300
@:deprecated
306
- public function getFailureCount (): Int return testsFailed ;
301
+ public function getFailureCount (): Int
302
+ return testsFailed ;
307
303
308
304
309
305
@:deprecated
310
- public function getSuccessCount (): Int return testsFailed ;
306
+ public function getSuccessCount (): Int
307
+ return testsFailed ;
311
308
312
309
313
310
public function logFailures (): Void
0 commit comments