Improve _CheckUmaHistogramChanges presubmit
The _CheckUmaHistogramChanges checks whether newly added
UMA_HISTOGRAM_* calls only use defined histogram names.
This CL removes two ways to introduce false positives:
* Unrelated macro names which contain UMA_HISTOGRAM as a continuous
substring
* More than one string literal on the line with the histogram name.
While those cases are rare, there seems no downside to fixing them.
Bug: 821981
Change-Id: Ie1a803f562883f567d577e742ed2ed87fd0dfe66
Reviewed-on: https://chromium-review.googlesource.com/978245
Commit-Queue: Vaclav Brozek <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#545583}
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 5aa17a1..4532042 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -106,6 +106,30 @@
MockOutputApi())
self.assertEqual(0, len(warnings))
+ def testNameMatch(self):
+ # Check that the detected histogram name is "Dummy" and not, e.g.,
+ # "Dummy\", true); // The \"correct"
+ diff_cc = ['UMA_HISTOGRAM_BOOL("Dummy", true); // The "correct" histogram']
+ diff_xml = ['<histogram name="Dummy"> </histogram>']
+ mock_input_api = MockInputApi()
+ mock_input_api.files = [
+ MockFile('some/path/foo.cc', diff_cc),
+ MockFile('tools/metrics/histograms/histograms.xml', diff_xml),
+ ]
+ warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api,
+ MockOutputApi())
+ self.assertEqual(0, len(warnings))
+
+ def testSimilarMacroNames(self):
+ diff_cc = ['PUMA_HISTOGRAM_BOOL("Mountain Lion", 42)']
+ mock_input_api = MockInputApi()
+ mock_input_api.files = [
+ MockFile('some/path/foo.cc', diff_cc),
+ ]
+ warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api,
+ MockOutputApi())
+ self.assertEqual(0, len(warnings))
+
class BadExtensionsTest(unittest.TestCase):
def testBadRejFile(self):
mock_input_api = MockInputApi()