From 940df072ba1d09a1095d3c67bb5d06d6b1a4ba02 Mon Sep 17 00:00:00 2001 From: gayane Date: Tue, 24 Feb 2015 06:28:30 -0800 Subject: Presubmit for chrome/browser/resources matches multiline metric type. Also added a testcase for it and a nice print of errors. BUG=443026 Review URL: https://codereview.chromium.org/809053003 Cr-Commit-Position: refs/heads/master@{#317794} --- PRESUBMIT_test_mocks.py | 3 +++ chrome/browser/resources/PRESUBMIT.py | 6 +++--- chrome/browser/resources/PRESUBMIT_test.py | 12 ++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/PRESUBMIT_test_mocks.py b/PRESUBMIT_test_mocks.py index 5caa156..03d9232 100644 --- a/PRESUBMIT_test_mocks.py +++ b/PRESUBMIT_test_mocks.py @@ -58,6 +58,9 @@ class MockOutputApi(object): self.items = items self.long_text = long_text + def __repr__(self): + return self.message + class PresubmitError(PresubmitResult): def __init__(self, message, items, long_text=''): MockOutputApi.PresubmitResult.__init__(self, message, items, long_text) diff --git a/chrome/browser/resources/PRESUBMIT.py b/chrome/browser/resources/PRESUBMIT.py index 9d6dfaa..502d47a 100644 --- a/chrome/browser/resources/PRESUBMIT.py +++ b/chrome/browser/resources/PRESUBMIT.py @@ -79,10 +79,10 @@ def IsBoolean(new_content_lines, metric_name, input_api): new_content = '\n'.join(new_content_lines) html_element_re = r'<(.*?)(^|\s+)metric\s*=\s*"%s"(.*?)>' % (metric_name) - type_re = (r'datatype="boolean"|type="checkbox"|type="radio".*?' - 'value=("true"|"false")') + type_re = (r'datatype\s*=\s*"boolean"|type\s*=\s*"checkbox"|' + 'type\s*=\s*"radio".*?value\s*=\s*("true"|"false")') - match = input_api.re.search(html_element_re, new_content) + match = input_api.re.search(html_element_re, new_content, input_api.re.DOTALL) return (match and any(input_api.re.search(type_re, match.group(i)) for i in (1, 3))) diff --git a/chrome/browser/resources/PRESUBMIT_test.py b/chrome/browser/resources/PRESUBMIT_test.py index d46f3b7..923f2be 100644 --- a/chrome/browser/resources/PRESUBMIT_test.py +++ b/chrome/browser/resources/PRESUBMIT_test.py @@ -56,13 +56,21 @@ class HTMLActionAdditionTest(unittest.TestCase): lines = [''] warnings = self._testChange(lines) - self.assertEqual(1, len(warnings)) + self.assertEqual(1, len(warnings), warnings) def testInValidChange_Radio(self): lines = [''] warnings = self._testChange(lines) - self.assertEqual(1, len(warnings)) + self.assertEqual(1, len(warnings), warnings) + + def testValidChange_MultilineType(self): + lines = [''] + warnings = self._testChange(lines) + self.assertEqual([], self._testChange(lines)) def _testChange(self, lines): mock_input_api = MockInputApi() -- cgit v1.1