summaryrefslogtreecommitdiffstats
path: root/PRESUBMIT_test.py
diff options
context:
space:
mode:
authormcasas <mcasas@chromium.org>2014-12-02 07:37:23 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-02 15:37:48 +0000
commit2ece5270462346b1ac3bccd3bfe5e68d024b98b5 (patch)
tree84619842df85160e66c4bda5ba9a5b2d6122e165 /PRESUBMIT_test.py
parent1e519da432ee8cbedd0926765f8967db2f8c88e4 (diff)
downloadchromium_src-2ece5270462346b1ac3bccd3bfe5e68d024b98b5.zip
chromium_src-2ece5270462346b1ac3bccd3bfe5e68d024b98b5.tar.gz
chromium_src-2ece5270462346b1ac3bccd3bfe5e68d024b98b5.tar.bz2
Add PRESUBMIT check if modified UMA histogram name can be found
This Presubmit checks if some diffs affect any UMA_HISTOGRAM_* macro and, if so, checks if the histogram name is to be found in either tools/metrics/histograms/histograms.xml or in the CL diffs. Addresses the problem of someone modifying code and inadvertently forgetting a corresponding histograms.xml adaptation, that has happened in the past. BUG=434420 Review URL: https://codereview.chromium.org/766713004 Cr-Commit-Position: refs/heads/master@{#306388}
Diffstat (limited to 'PRESUBMIT_test.py')
-rwxr-xr-xPRESUBMIT_test.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 2f37708..1c97191 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -346,6 +346,28 @@ class VersionControlConflictsTest(unittest.TestCase):
self.assertTrue('3' in errors[1])
self.assertTrue('5' in errors[2])
+class UmaHistogramChangeMatchedOrNotTest(unittest.TestCase):
+ def testTypicalNotMatchedChange(self):
+ diff = ['UMA_HISTOGRAM_BOOL("Bla.Foo.Dummy", true)']
+ mock_input_api = MockInputApi()
+ mock_input_api.files = [MockFile('some/path/foo.cc', diff)]
+ warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api,
+ MockOutputApi())
+ self.assertEqual(1, len(warnings))
+ self.assertEqual('warning', warnings[0].type)
+
+ def testTypicalCorrectlyMatchedChange(self):
+ diff_cc = ['UMA_HISTOGRAM_BOOL("Bla.Foo.Dummy", true)']
+ diff_xml = ['<histogram name="Bla.Foo.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 = []
+ warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api,
+ MockOutputApi())
+ self.assertEqual(0, len(warnings))
class BadExtensionsTest(unittest.TestCase):
def testBadRejFile(self):