Commit bba13749 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

[Presubmit] When checking include guards, replace + with _.

+ is an invalid character for include guard, so for a file
named "foo+bar.h", include guard should be FOO_BAR_H_

Bug: 856548
Change-Id: I39a2d01e328b9352620d0d0e9548e40f1b57150a
Reviewed-on: https://chromium-review.googlesource.com/1152971
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579010}
parent f2fefd3a
...@@ -3081,7 +3081,7 @@ def _CheckForIncludeGuards(input_api, output_api): ...@@ -3081,7 +3081,7 @@ def _CheckForIncludeGuards(input_api, output_api):
input_api.os_path.join('third_party', 'blink')))) input_api.os_path.join('third_party', 'blink'))))
def replace_special_with_underscore(string): def replace_special_with_underscore(string):
return input_api.re.sub(r'[\\/.-]', '_', string) return input_api.re.sub(r'[+\\/.-]', '_', string)
errors = [] errors = []
......
...@@ -890,6 +890,13 @@ class IncludeGuardTest(unittest.TestCase): ...@@ -890,6 +890,13 @@ class IncludeGuardTest(unittest.TestCase):
'struct McBoatFace;', 'struct McBoatFace;',
'#endif // CONTENT_BROWSER_SPLLEING_H_', '#endif // CONTENT_BROWSER_SPLLEING_H_',
]), ]),
# New files don't allow + in include guards.
MockAffectedFile('content/browser/foo+bar.h', [
'#ifndef CONTENT_BROWSER_FOO+BAR_H_',
'#define CONTENT_BROWSER_FOO+BAR_H_',
'struct McBoatFace;',
'#endif // CONTENT_BROWSER_FOO+BAR_H_',
]),
# Old files allow misspelled include guards (for now). # Old files allow misspelled include guards (for now).
MockAffectedFile('chrome/old.h', [ MockAffectedFile('chrome/old.h', [
'// New contents', '// New contents',
...@@ -949,7 +956,7 @@ class IncludeGuardTest(unittest.TestCase): ...@@ -949,7 +956,7 @@ class IncludeGuardTest(unittest.TestCase):
] ]
msgs = PRESUBMIT._CheckForIncludeGuards( msgs = PRESUBMIT._CheckForIncludeGuards(
mock_input_api, mock_output_api) mock_input_api, mock_output_api)
expected_fail_count = 7 expected_fail_count = 8
self.assertEqual(expected_fail_count, len(msgs), self.assertEqual(expected_fail_count, len(msgs),
'Expected %d items, found %d: %s' 'Expected %d items, found %d: %s'
% (expected_fail_count, len(msgs), msgs)) % (expected_fail_count, len(msgs), msgs))
...@@ -972,18 +979,22 @@ class IncludeGuardTest(unittest.TestCase): ...@@ -972,18 +979,22 @@ class IncludeGuardTest(unittest.TestCase):
'Header using the wrong include guard name ' 'Header using the wrong include guard name '
'CONTENT_BROWSER_SPLLEING_H_') 'CONTENT_BROWSER_SPLLEING_H_')
self.assertEqual(msgs[4].items, ['content/NotInBlink.h:1']) self.assertEqual(msgs[4].items, ['content/browser/foo+bar.h'])
self.assertEqual(msgs[4].message, self.assertEqual(msgs[4].message,
'Missing include guard CONTENT_BROWSER_FOO_BAR_H_')
self.assertEqual(msgs[5].items, ['content/NotInBlink.h:1'])
self.assertEqual(msgs[5].message,
'Header using the wrong include guard name ' 'Header using the wrong include guard name '
'NotInBlink_h') 'NotInBlink_h')
self.assertEqual(msgs[5].items, ['third_party/blink/InBlink.h:1']) self.assertEqual(msgs[6].items, ['third_party/blink/InBlink.h:1'])
self.assertEqual(msgs[5].message, self.assertEqual(msgs[6].message,
'Header using the wrong include guard name ' 'Header using the wrong include guard name '
'InBlink_h') 'InBlink_h')
self.assertEqual(msgs[6].items, ['third_party/blink/AlsoInBlink.h:1']) self.assertEqual(msgs[7].items, ['third_party/blink/AlsoInBlink.h:1'])
self.assertEqual(msgs[6].message, self.assertEqual(msgs[7].message,
'Header using the wrong include guard name ' 'Header using the wrong include guard name '
'WrongInBlink_h') 'WrongInBlink_h')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment