29
29
30
30
31
31
import imp
32
+ import logging
32
33
import optparse
33
34
import os
34
35
import platform
47
48
from datetime import datetime
48
49
from Queue import Queue , Empty
49
50
51
+ logger = logging .getLogger ('testrunner' )
52
+
50
53
VERBOSE = False
51
54
52
55
@@ -237,7 +240,7 @@ def HasRun(self, output):
237
240
class TapProgressIndicator (SimpleProgressIndicator ):
238
241
239
242
def Starting (self ):
240
- print '1..%i' % len (self .cases )
243
+ logger . info ( '1..%i' % len (self .cases ) )
241
244
self ._done = 0
242
245
243
246
def AboutToRun (self , case ):
@@ -247,23 +250,23 @@ def HasRun(self, output):
247
250
self ._done += 1
248
251
command = basename (output .command [- 1 ])
249
252
if output .UnexpectedOutput ():
250
- print 'not ok %i - %s' % (self ._done , command )
253
+ logger . info ( 'not ok %i - %s' % (self ._done , command ) )
251
254
for l in output .output .stderr .splitlines ():
252
- print '#' + l
255
+ logger . info ( '#' + l )
253
256
for l in output .output .stdout .splitlines ():
254
- print '#' + l
257
+ logger . info ( '#' + l )
255
258
else :
256
- print 'ok %i - %s' % (self ._done , command )
259
+ logger . info ( 'ok %i - %s' % (self ._done , command ) )
257
260
258
261
duration = output .test .duration
259
262
260
263
# total_seconds() was added in 2.7
261
264
total_seconds = (duration .microseconds +
262
265
(duration .seconds + duration .days * 24 * 3600 ) * 10 ** 6 ) / 10 ** 6
263
266
264
- print ' ---'
265
- print ' duration_ms: %d.%d' % (total_seconds , duration .microseconds / 1000 )
266
- print ' ...'
267
+ logger . info ( ' ---' )
268
+ logger . info ( ' duration_ms: %d.%d' % (total_seconds , duration .microseconds / 1000 ) )
269
+ logger . info ( ' ...' )
267
270
268
271
def Done (self ):
269
272
pass
@@ -1216,6 +1219,8 @@ def BuildOptions():
1216
1219
default = 'release' )
1217
1220
result .add_option ("-v" , "--verbose" , help = "Verbose output" ,
1218
1221
default = False , action = "store_true" )
1222
+ result .add_option ('--logfile' , dest = 'logfile' ,
1223
+ help = 'write test output to file. NOTE: this only applies the tap progress indicator' )
1219
1224
result .add_option ("-S" , dest = "scons_flags" , help = "Flag to pass through to scons" ,
1220
1225
default = [], action = "append" )
1221
1226
result .add_option ("-p" , "--progress" ,
@@ -1359,6 +1364,13 @@ def Main():
1359
1364
parser .print_help ()
1360
1365
return 1
1361
1366
1367
+ ch = logging .StreamHandler (sys .stdout )
1368
+ logger .addHandler (ch )
1369
+ logger .setLevel ('INFO' )
1370
+ if options .logfile :
1371
+ fh = logging .FileHandler (options .logfile )
1372
+ logger .addHandler (fh )
1373
+
1362
1374
workspace = abspath (join (dirname (sys .argv [0 ]), '..' ))
1363
1375
suites = GetSuites (join (workspace , 'test' ))
1364
1376
repositories = [TestRepository (join (workspace , 'test' , name )) for name in suites ]
0 commit comments