Skip to content

Commit a31ffb6

Browse files
author
Thomas Kiley
authored
Merge pull request #3733 from thk123/lint-scenario-has-tags
Make linter check scenario has tags
2 parents 9f632e2 + 1b14892 commit a31ffb6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

scripts/cpplint.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import string
5353
import sys
5454
import unicodedata
55+
import itertools
5556

5657

5758
_USAGE = """
@@ -252,6 +253,7 @@
252253
'runtime/string',
253254
'runtime/threadsafe_fn',
254255
'runtime/vlog',
256+
'runtime/catch_test_tags',
255257
'whitespace/blank_line',
256258
'whitespace/braces',
257259
'whitespace/comma',
@@ -1745,6 +1747,9 @@ def CloseExpression(clean_lines, linenum, pos):
17451747
and have CloseExpression be just a simple lookup, but due to preprocessor
17461748
tricks, this is not so easy.
17471749
1750+
Note this operates on the *elided lines* - the position will be wrong if you
1751+
want strings (or comments) to be included.
1752+
17481753
Args:
17491754
clean_lines: A CleansedLines instance containing the file.
17501755
linenum: The number of the line to check.
@@ -6118,6 +6123,50 @@ def CheckMakePairUsesDeduction(filename, clean_lines, linenum, error):
61186123
'For C++11-compatibility, omit template arguments from make_pair'
61196124
' OR use pair directly OR if appropriate, construct a pair directly')
61206125

6126+
def AssembleString(clean_lines, start_lineno, start_linepos, end_lineno, end_linepos):
6127+
"""
6128+
Concatenates all the strings between the starting line position and
6129+
the ending line position.
6130+
6131+
Note: this operated on the elided (no strings and comments) view of the
6132+
code.
6133+
6134+
Args:
6135+
clean_lines: All the lines
6136+
start_lineno: The starting line number
6137+
start_linepos: The index of the first character to include
6138+
end_lineno: The last line
6139+
end_linepos: The index of the first character not to include
6140+
"""
6141+
if end_lineno < start_lineno:
6142+
return ''
6143+
6144+
if start_lineno == end_lineno:
6145+
return clean_lines.elided[start_lineno][start_linepos : end_linepos]
6146+
6147+
full_string = clean_lines.elided[start_lineno][start_linepos:]
6148+
for line in itertools.islice(clean_lines.elided, start_lineno + 1, end_lineno):
6149+
full_string += line
6150+
full_string += clean_lines.elided[end_lineno][:end_linepos]
6151+
return full_string
6152+
6153+
def CheckCatchTestHasTags(filename, clean_lines, linenum, error):
6154+
line = clean_lines.elided[linenum]
6155+
test = Match(r'^(SCENARIO|TEST_CASE)\(', line)
6156+
if not test: return
6157+
6158+
closing_line, closing_linenum, closing_pos = CloseExpression(clean_lines, linenum, line.find('('))
6159+
6160+
if closing_pos == -1:
6161+
error(filename, linenum,
6162+
'runtime/catch_test_tags', 4, "Can't find closing bracket for catch test")
6163+
6164+
full_string = AssembleString(
6165+
clean_lines, linenum, line.find('(') + 1, closing_linenum, closing_pos - 1)
6166+
6167+
if(full_string.find(',') == -1):
6168+
error(filename, linenum,
6169+
'runtime/catch_test_tags', 4, "Can't find `,\' seperating test name and the tags: " + str(clean_lines.lines[linenum]))
61216170

61226171
def CheckRedundantVirtual(filename, clean_lines, linenum, error):
61236172
"""Check if line contains a redundant "virtual" function-specifier.
@@ -6312,6 +6361,7 @@ def ProcessLine(filename, file_extension, clean_lines, line,
63126361
CheckInvalidIncrement(filename, clean_lines, line, error)
63136362
CheckMakePairUsesDeduction(filename, clean_lines, line, error)
63146363
CheckRedundantVirtual(filename, clean_lines, line, error)
6364+
CheckCatchTestHasTags(filename, clean_lines, line, error)
63156365
CheckNamespaceOrUsing(filename, clean_lines, line, error)
63166366
CheckForEndl(filename, clean_lines, line, error)
63176367
for check_fn in extra_check_functions:

0 commit comments

Comments
 (0)