MCPcopy Index your code
hub / github.com/cpplint/cpplint / ErrorCollector

Class ErrorCollector

cpplint_unittest.py:57–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55# function for the unit tests. We also verify each category we see
56# is in cpplint._ERROR_CATEGORIES, to help keep that list up to date.
57class ErrorCollector:
58 # These are a global list, covering all categories seen ever.
59 _ERROR_CATEGORIES = cpplint._ERROR_CATEGORIES
60 _SEEN_ERROR_CATEGORIES: set[str] = set()
61
62 def __init__(self, assert_fn):
63 """assert_fn: a function to call when we notice a problem."""
64 self._assert_fn = assert_fn
65 self._errors = []
66 cpplint.ResetNolintSuppressions()
67
68 def __call__(self, filename, linenum, category, confidence, message):
69 self._assert_fn(
70 category in self._ERROR_CATEGORIES,
71 'Message "%s" has category "%s",'
72 " which is not in _ERROR_CATEGORIES" % (message, category),
73 )
74 self._SEEN_ERROR_CATEGORIES.add(category)
75 if cpplint._ShouldPrintError(category, confidence, filename, linenum):
76 self._errors.append("%s [%s] [%d]" % (message, category, confidence))
77
78 def Results(self):
79 if len(self._errors) < 2:
80 return "".join(self._errors) # Most tests expect to have a string.
81 return self._errors # Let's give a list if there is more than one.
82
83 def ResultList(self):
84 return self._errors
85
86 def VerifyAllCategoriesAreSeen(self):
87 """Fails if there&#x27;s a category in _ERROR_CATEGORIES~_SEEN_ERROR_CATEGORIES.
88
89 This should only be called after all tests are run, so
90 _SEEN_ERROR_CATEGORIES has had a chance to fully populate. Since
91 this isn&#x27;t called from within the normal unittest framework, we
92 can&#x27;t use the normal unittest assert macros. Instead we just exit
93 when we see an error. Good thing this test is always run last!
94 """
95 for category in self._ERROR_CATEGORIES:
96 if category not in self._SEEN_ERROR_CATEGORIES:
97 sys.exit('FATAL ERROR: There are no tests for category "%s"' % category)
98
99 def RemoveIfPresent(self, substr):
100 for index, error in enumerate(self._errors):
101 if error.find(substr) != -1:
102 self._errors = self._errors[0:index] + self._errors[(index + 1) :]
103 break
104
105
106# This class is a lame mock of codecs. We do not verify filename, mode, or

Callers 15

PerformSingleLineLintMethod · 0.85
PerformMultiLineLintMethod · 0.85
doTestBlankLinesCheckMethod · 0.85
GetNamespaceResultsMethod · 0.85
testErrorSuppressionMethod · 0.85
testDeprecatedCastMethod · 0.85
testMockMethodMethod · 0.85
testMultilineStringsMethod · 0.85

Calls

no outgoing calls

Tested by 15

PerformSingleLineLintMethod · 0.68
PerformMultiLineLintMethod · 0.68
doTestBlankLinesCheckMethod · 0.68
GetNamespaceResultsMethod · 0.68
testErrorSuppressionMethod · 0.68
testDeprecatedCastMethod · 0.68
testMockMethodMethod · 0.68
testMultilineStringsMethod · 0.68