Skip to content

Commit b48639b

Browse files
committed
test: support writing test output to file
This is a minimal effort to support test output written both to stdout and file in order to get our buildbots understanding test output. Cherry picked from jbergstroem@3194073 Original commit message follows: PR-URL: #934 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Conflicts: tools/test.py Reviewed-By: Julien Gilli <julien.gilli@joyent.com> PR-URL: nodejs/node-v0.x-archive#25653
1 parent b8ac658 commit b48639b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tools/test.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
import imp
32+
import logging
3233
import optparse
3334
import os
3435
import platform
@@ -45,6 +46,8 @@
4546
from datetime import datetime
4647
from Queue import Queue, Empty
4748

49+
logger = logging.getLogger('testrunner')
50+
4851
VERBOSE = False
4952

5053

@@ -225,7 +228,7 @@ def HasRun(self, output):
225228
class TapProgressIndicator(SimpleProgressIndicator):
226229

227230
def Starting(self):
228-
print '1..%i' % len(self.cases)
231+
logger.info('1..%i' % len(self.cases))
229232
self._done = 0
230233

231234
def AboutToRun(self, case):
@@ -238,26 +241,26 @@ def HasRun(self, output):
238241
status_line = 'not ok %i - %s' % (self._done, command)
239242
if FLAKY in output.test.outcomes and self.flaky_tests_mode == "dontcare":
240243
status_line = status_line + " # TODO : Fix flaky test"
241-
print status_line
244+
logger.info(status_line)
242245
for l in output.output.stderr.splitlines():
243-
print '#' + l
246+
logger.info('#' + l)
244247
for l in output.output.stdout.splitlines():
245-
print '#' + l
248+
logger.info('#' + l)
246249
else:
247250
status_line = 'ok %i - %s' % (self._done, command)
248251
if FLAKY in output.test.outcomes:
249252
status_line = status_line + " # TODO : Fix flaky test"
250-
print status_line
253+
logger.info(status_line)
251254

252255
duration = output.test.duration
253256

254257
# total_seconds() was added in 2.7
255258
total_seconds = (duration.microseconds +
256259
(duration.seconds + duration.days * 24 * 3600) * 10**6) / 10**6
257260

258-
print ' ---'
259-
print ' duration_ms: %d.%d' % (total_seconds, duration.microseconds / 1000)
260-
print ' ...'
261+
logger.info(' ---')
262+
logger.info(' duration_ms: %d.%d' % (total_seconds, duration.microseconds / 1000))
263+
logger.info(' ...')
261264

262265
def Done(self):
263266
pass
@@ -1192,6 +1195,8 @@ def BuildOptions():
11921195
default='release')
11931196
result.add_option("-v", "--verbose", help="Verbose output",
11941197
default=False, action="store_true")
1198+
result.add_option('--logfile', dest='logfile',
1199+
help='write test output to file. NOTE: this only applies the tap progress indicator')
11951200
result.add_option("-S", dest="scons_flags", help="Flag to pass through to scons",
11961201
default=[], action="append")
11971202
result.add_option("-p", "--progress",
@@ -1368,6 +1373,13 @@ def Main():
13681373
parser.print_help()
13691374
return 1
13701375

1376+
ch = logging.StreamHandler(sys.stdout)
1377+
logger.addHandler(ch)
1378+
logger.setLevel('INFO')
1379+
if options.logfile:
1380+
fh = logging.FileHandler(options.logfile)
1381+
logger.addHandler(fh)
1382+
13711383
workspace = abspath(join(dirname(sys.argv[0]), '..'))
13721384
suites = GetSuites(join(workspace, 'test'))
13731385
repositories = [TestRepository(join(workspace, 'test', name)) for name in suites]

0 commit comments

Comments
 (0)