Skip to content

Commit

Permalink
tools: add back --mode=tap to cpplint
Browse files Browse the repository at this point in the history
This commit reimplements commit 7b45163 ("tools: add tap output to
cpplint") on top of the upgraded copy of cpplint.

PR-URL: #7462
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis authored and Myles Borins committed Jul 14, 2016
1 parent e74f199 commit 09e98a4
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import codecs
import copy
import getopt
import logging
import math # for log
import os
import re
Expand All @@ -53,10 +54,13 @@
import unicodedata


logger = logging.getLogger('testrunner')


_USAGE = """
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
[--counting=total|toplevel|detailed] [--root=subdir]
[--linelength=digits]
[--linelength=digits] [--logfile=filename]
<file> [file] ...
The style guidelines this tries to follow are those in
Expand Down Expand Up @@ -134,6 +138,9 @@
Examples:
--extensions=hpp,cpp
logfile=filename
Write TAP output to a logfile.
cpplint.py supports per-directory configurations specified in CPPLINT.cfg
files. CPPLINT.cfg file can contain a number of key=value pairs.
Currently the following options are supported:
Expand Down Expand Up @@ -1190,6 +1197,15 @@ def Error(filename, linenum, category, confidence, message):
elif _cpplint_state.output_format == 'eclipse':
sys.stderr.write('%s:%s: warning: %s [%s] [%d]\n' % (
filename, linenum, message, category, confidence))
elif _cpplint_state.output_format == 'tap':
template = ('not ok %(filename)s\n'
' ---\n'
' message: %(message)s\n'
' data:\n'
' line: %(linenum)d\n'
' ruleId: %(category)s\n'
' ...')
logger.info(template % locals())
else:
sys.stderr.write('%s:%s: %s [%s] [%d]\n' % (
filename, linenum, message, category, confidence))
Expand Down Expand Up @@ -5980,7 +5996,6 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
Error(filename, linenum, 'whitespace/newline', 1,
'Unexpected \\r (^M) found; better to use only \\n')

sys.stderr.write('Done processing %s\n' % filename)
_RestoreFilters()


Expand Down Expand Up @@ -6021,6 +6036,7 @@ def ParseArguments(args):
(opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=',
'counting=',
'filter=',
'logfile=',
'root=',
'linelength=',
'extensions='])
Expand All @@ -6036,8 +6052,9 @@ def ParseArguments(args):
if opt == '--help':
PrintUsage(None)
elif opt == '--output':
if val not in ('emacs', 'vs7', 'eclipse'):
PrintUsage('The only allowed output formats are emacs, vs7 and eclipse.')
if val not in ('emacs', 'vs7', 'eclipse', 'tap'):
PrintUsage(
'The only allowed output formats are emacs, vs7, eclipse and tap.')
output_format = val
elif opt == '--verbose':
verbosity = int(val)
Expand All @@ -6064,6 +6081,8 @@ def ParseArguments(args):
_valid_extensions = set(val.split(','))
except ValueError:
PrintUsage('Extensions must be comma seperated list.')
elif opt == '--logfile':
logger.addHandler(logging.FileHandler(val, mode='wb'))

if not filenames:
PrintUsage('No files were specified.')
Expand All @@ -6086,6 +6105,12 @@ def main():
codecs.getwriter('utf8'),
'replace')

logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)

if _cpplint_state.output_format == 'tap':
logger.info('TAP version 13')

_cpplint_state.ResetErrorCounts()
for filename in filenames:
ProcessFile(filename, _cpplint_state.verbose_level)
Expand Down

0 comments on commit 09e98a4

Please sign in to comment.