|
52 | 52 | import string
|
53 | 53 | import sys
|
54 | 54 | import unicodedata
|
| 55 | +import itertools |
55 | 56 |
|
56 | 57 |
|
57 | 58 | _USAGE = """
|
|
252 | 253 | 'runtime/string',
|
253 | 254 | 'runtime/threadsafe_fn',
|
254 | 255 | 'runtime/vlog',
|
| 256 | + 'runtime/catch_test_tags', |
255 | 257 | 'whitespace/blank_line',
|
256 | 258 | 'whitespace/braces',
|
257 | 259 | 'whitespace/comma',
|
@@ -1745,6 +1747,9 @@ def CloseExpression(clean_lines, linenum, pos):
|
1745 | 1747 | and have CloseExpression be just a simple lookup, but due to preprocessor
|
1746 | 1748 | tricks, this is not so easy.
|
1747 | 1749 |
|
| 1750 | + Note this operates on the *elided lines* - the position will be wrong if you |
| 1751 | + want strings (or comments) to be included. |
| 1752 | +
|
1748 | 1753 | Args:
|
1749 | 1754 | clean_lines: A CleansedLines instance containing the file.
|
1750 | 1755 | linenum: The number of the line to check.
|
@@ -6118,6 +6123,50 @@ def CheckMakePairUsesDeduction(filename, clean_lines, linenum, error):
|
6118 | 6123 | 'For C++11-compatibility, omit template arguments from make_pair'
|
6119 | 6124 | ' OR use pair directly OR if appropriate, construct a pair directly')
|
6120 | 6125 |
|
| 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])) |
6121 | 6170 |
|
6122 | 6171 | def CheckRedundantVirtual(filename, clean_lines, linenum, error):
|
6123 | 6172 | """Check if line contains a redundant "virtual" function-specifier.
|
@@ -6312,6 +6361,7 @@ def ProcessLine(filename, file_extension, clean_lines, line,
|
6312 | 6361 | CheckInvalidIncrement(filename, clean_lines, line, error)
|
6313 | 6362 | CheckMakePairUsesDeduction(filename, clean_lines, line, error)
|
6314 | 6363 | CheckRedundantVirtual(filename, clean_lines, line, error)
|
| 6364 | + CheckCatchTestHasTags(filename, clean_lines, line, error) |
6315 | 6365 | CheckNamespaceOrUsing(filename, clean_lines, line, error)
|
6316 | 6366 | CheckForEndl(filename, clean_lines, line, error)
|
6317 | 6367 | for check_fn in extra_check_functions:
|
|
0 commit comments