Skip to content

Commit 09e98a4

Browse files
bnoordhuisMyles Borins
authored and
Myles Borins
committed
tools: add back --mode=tap to cpplint
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 <[email protected]>
1 parent e74f199 commit 09e98a4

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

tools/cpplint.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import codecs
4545
import copy
4646
import getopt
47+
import logging
4748
import math # for log
4849
import os
4950
import re
@@ -53,10 +54,13 @@
5354
import unicodedata
5455

5556

57+
logger = logging.getLogger('testrunner')
58+
59+
5660
_USAGE = """
5761
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
5862
[--counting=total|toplevel|detailed] [--root=subdir]
59-
[--linelength=digits]
63+
[--linelength=digits] [--logfile=filename]
6064
<file> [file] ...
6165
6266
The style guidelines this tries to follow are those in
@@ -134,6 +138,9 @@
134138
Examples:
135139
--extensions=hpp,cpp
136140
141+
logfile=filename
142+
Write TAP output to a logfile.
143+
137144
cpplint.py supports per-directory configurations specified in CPPLINT.cfg
138145
files. CPPLINT.cfg file can contain a number of key=value pairs.
139146
Currently the following options are supported:
@@ -1190,6 +1197,15 @@ def Error(filename, linenum, category, confidence, message):
11901197
elif _cpplint_state.output_format == 'eclipse':
11911198
sys.stderr.write('%s:%s: warning: %s [%s] [%d]\n' % (
11921199
filename, linenum, message, category, confidence))
1200+
elif _cpplint_state.output_format == 'tap':
1201+
template = ('not ok %(filename)s\n'
1202+
' ---\n'
1203+
' message: %(message)s\n'
1204+
' data:\n'
1205+
' line: %(linenum)d\n'
1206+
' ruleId: %(category)s\n'
1207+
' ...')
1208+
logger.info(template % locals())
11931209
else:
11941210
sys.stderr.write('%s:%s: %s [%s] [%d]\n' % (
11951211
filename, linenum, message, category, confidence))
@@ -5980,7 +5996,6 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
59805996
Error(filename, linenum, 'whitespace/newline', 1,
59815997
'Unexpected \\r (^M) found; better to use only \\n')
59825998

5983-
sys.stderr.write('Done processing %s\n' % filename)
59845999
_RestoreFilters()
59856000

59866001

@@ -6021,6 +6036,7 @@ def ParseArguments(args):
60216036
(opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=',
60226037
'counting=',
60236038
'filter=',
6039+
'logfile=',
60246040
'root=',
60256041
'linelength=',
60266042
'extensions='])
@@ -6036,8 +6052,9 @@ def ParseArguments(args):
60366052
if opt == '--help':
60376053
PrintUsage(None)
60386054
elif opt == '--output':
6039-
if val not in ('emacs', 'vs7', 'eclipse'):
6040-
PrintUsage('The only allowed output formats are emacs, vs7 and eclipse.')
6055+
if val not in ('emacs', 'vs7', 'eclipse', 'tap'):
6056+
PrintUsage(
6057+
'The only allowed output formats are emacs, vs7, eclipse and tap.')
60416058
output_format = val
60426059
elif opt == '--verbose':
60436060
verbosity = int(val)
@@ -6064,6 +6081,8 @@ def ParseArguments(args):
60646081
_valid_extensions = set(val.split(','))
60656082
except ValueError:
60666083
PrintUsage('Extensions must be comma seperated list.')
6084+
elif opt == '--logfile':
6085+
logger.addHandler(logging.FileHandler(val, mode='wb'))
60676086

60686087
if not filenames:
60696088
PrintUsage('No files were specified.')
@@ -6086,6 +6105,12 @@ def main():
60866105
codecs.getwriter('utf8'),
60876106
'replace')
60886107

6108+
logger.addHandler(logging.StreamHandler(sys.stdout))
6109+
logger.setLevel(logging.INFO)
6110+
6111+
if _cpplint_state.output_format == 'tap':
6112+
logger.info('TAP version 13')
6113+
60896114
_cpplint_state.ResetErrorCounts()
60906115
for filename in filenames:
60916116
ProcessFile(filename, _cpplint_state.verbose_level)

0 commit comments

Comments
 (0)