Browse Source

tools: add tap output to cpplint

Implement a crude TAP13 writer for cpplint. Does its job and
not much else. Only supports writing TAP output to file,
not vs7 or emacs formats.

PR-URL: https://github.com/nodejs/node/pull/3448
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
v5.x
Johan Bergström 10 years ago
committed by Rod Vagg
parent
commit
bea35424a2
  1. 47
      tools/cpplint.py

47
tools/cpplint.py

@ -1,4 +1,4 @@
#!/usr/bin/python2.4 #!/usr/bin/env python
# #
# Copyright (c) 2009 Google Inc. All rights reserved. # Copyright (c) 2009 Google Inc. All rights reserved.
# #
@ -88,7 +88,8 @@ import sre_compile
import string import string
import sys import sys
import unicodedata import unicodedata
import logging
logger = logging.getLogger('testrunner')
_USAGE = """ _USAGE = """
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...] Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
@ -139,6 +140,9 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
the top-level categories like 'build' and 'whitespace' will the top-level categories like 'build' and 'whitespace' will
also be printed. If 'detailed' is provided, then a count also be printed. If 'detailed' is provided, then a count
is provided for each category like 'build/class'. is provided for each category like 'build/class'.
logfile=filename
Write TAP output to a logfile.
""" """
# We categorize each error message we print. Here are the categories. # We categorize each error message we print. Here are the categories.
@ -541,6 +545,11 @@ class _CppLintState(object):
raise ValueError('Every filter in --filters must start with + or -' raise ValueError('Every filter in --filters must start with + or -'
' (%s does not)' % filt) ' (%s does not)' % filt)
def setOutputFile(self, filename):
"""attempts to create a file which we write output to."""
fh = logging.FileHandler(filename, mode='wb')
logger.addHandler(fh)
def ResetErrorCounts(self): def ResetErrorCounts(self):
"""Sets the module's error statistic back to zero.""" """Sets the module's error statistic back to zero."""
self.error_count = 0 self.error_count = 0
@ -558,6 +567,7 @@ class _CppLintState(object):
def PrintErrorCounts(self): def PrintErrorCounts(self):
"""Print a summary of errors by category, and the total.""" """Print a summary of errors by category, and the total."""
if not _cpplint_state.output_format == 'tap':
for category, count in self.errors_by_category.iteritems(): for category, count in self.errors_by_category.iteritems():
sys.stderr.write('Category \'%s\' errors found: %d\n' % sys.stderr.write('Category \'%s\' errors found: %d\n' %
(category, count)) (category, count))
@ -608,6 +618,9 @@ def _SetFilters(filters):
""" """
_cpplint_state.SetFilters(filters) _cpplint_state.SetFilters(filters)
def _setOutputFile(filename):
_cpplint_state.setOutputFile(filename)
class _FunctionState(object): class _FunctionState(object):
"""Tracks current function name and the number of lines in its body.""" """Tracks current function name and the number of lines in its body."""
@ -786,6 +799,15 @@ def Error(filename, linenum, category, confidence, message):
if _cpplint_state.output_format == 'vs7': if _cpplint_state.output_format == 'vs7':
sys.stderr.write('%s(%s): %s [%s] [%d]\n' % ( sys.stderr.write('%s(%s): %s [%s] [%d]\n' % (
filename, linenum, message, category, confidence)) filename, linenum, message, category, confidence))
elif _cpplint_state.output_format == 'tap':
template = ('not ok %s\n'
' ---\n'
' message: %s\n'
' data:\n'
' line: %d\n'
' ruleId: %s\n'
' ...')
logger.info(template % (filename, message, linenum, category))
else: else:
sys.stderr.write('%s:%s: %s [%s] [%d]\n' % ( sys.stderr.write('%s:%s: %s [%s] [%d]\n' % (
filename, linenum, message, category, confidence)) filename, linenum, message, category, confidence))
@ -3002,6 +3024,7 @@ def ProcessFile(filename, vlevel):
'One or more unexpected \\r (^M) found;' 'One or more unexpected \\r (^M) found;'
'better to use only a \\n') 'better to use only a \\n')
if not _cpplint_state.output_format == 'tap':
sys.stderr.write('Done processing %s\n' % filename) sys.stderr.write('Done processing %s\n' % filename)
@ -3041,7 +3064,8 @@ def ParseArguments(args):
try: try:
(opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=',
'counting=', 'counting=',
'filter=']) 'filter=',
'logfile='])
except getopt.GetoptError: except getopt.GetoptError:
PrintUsage('Invalid arguments.') PrintUsage('Invalid arguments.')
@ -3049,13 +3073,14 @@ def ParseArguments(args):
output_format = _OutputFormat() output_format = _OutputFormat()
filters = '' filters = ''
counting_style = '' counting_style = ''
output_filename = ''
for (opt, val) in opts: for (opt, val) in opts:
if opt == '--help': if opt == '--help':
PrintUsage(None) PrintUsage(None)
elif opt == '--output': elif opt == '--output':
if not val in ('emacs', 'vs7'): if not val in ('emacs', 'vs7', 'tap'):
PrintUsage('The only allowed output formats are emacs and vs7.') PrintUsage('The only allowed output formats are emacs, vs7 and tap.')
output_format = val output_format = val
elif opt == '--verbose': elif opt == '--verbose':
verbosity = int(val) verbosity = int(val)
@ -3067,6 +3092,8 @@ def ParseArguments(args):
if val not in ('total', 'toplevel', 'detailed'): if val not in ('total', 'toplevel', 'detailed'):
PrintUsage('Valid counting options are total, toplevel, and detailed') PrintUsage('Valid counting options are total, toplevel, and detailed')
counting_style = val counting_style = val
elif opt == '--logfile':
output_filename = val
if not filenames: if not filenames:
PrintUsage('No files were specified.') PrintUsage('No files were specified.')
@ -3075,6 +3102,8 @@ def ParseArguments(args):
_SetVerboseLevel(verbosity) _SetVerboseLevel(verbosity)
_SetFilters(filters) _SetFilters(filters)
_SetCountingStyle(counting_style) _SetCountingStyle(counting_style)
if output_filename:
_setOutputFile(output_filename)
return filenames return filenames
@ -3089,6 +3118,14 @@ def main():
codecs.getwriter('utf8'), codecs.getwriter('utf8'),
'replace') 'replace')
ch = logging.StreamHandler(sys.stdout)
logger.addHandler(ch)
logger.setLevel(logging.INFO)
if _cpplint_state.output_format == 'tap':
logger.info('TAP version 13')
_cpplint_state.ResetErrorCounts() _cpplint_state.ResetErrorCounts()
for filename in filenames: for filename in filenames:
ProcessFile(filename, _cpplint_state.verbose_level) ProcessFile(filename, _cpplint_state.verbose_level)

Loading…
Cancel
Save