summaryrefslogtreecommitdiffstats
path: root/PRESUBMIT_test.py
diff options
context:
space:
mode:
authortnagel@chromium.org <tnagel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-25 11:55:21 +0000
committertnagel@chromium.org <tnagel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-25 11:55:21 +0000
commit264246a7e8ab75ef208ff9b10a33e72facba61d3 (patch)
tree1e98c41989a9f70b825a4842d404f1625fd4569b /PRESUBMIT_test.py
parent3e9b1984836264a07fe568fefd99a767a66de3ff (diff)
downloadchromium_src-264246a7e8ab75ef208ff9b10a33e72facba61d3.zip
chromium_src-264246a7e8ab75ef208ff9b10a33e72facba61d3.tar.gz
chromium_src-264246a7e8ab75ef208ff9b10a33e72facba61d3.tar.bz2
Add PRESUBMIT.py warning for contradictory NOTREACHED() use.
As recently discussed on chromium-dev [1] and subsequently incorporated into the Chromium Coding Style [2], NOTREACHED() followed by code is an anti-pattern. This CL lets PRESUBMIT.py detect most of these cases and print a warning to the developer. [1] https://groups.google.com/a/chromium.org/d/msg/chromium-dev/c2X0D1Z6X2o/ddkFLqQP0P0J [2] http://www.chromium.org/developers/coding-style#TOC-CHECK-DCHECK-and-NOTREACHED- BUG=none Review URL: https://codereview.chromium.org/344563003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT_test.py')
-rwxr-xr-xPRESUBMIT_test.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index f81b316..760d70b 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -413,6 +413,52 @@ class InvalidOSMacroNamesTest(unittest.TestCase):
self.assertEqual(0, len(errors))
+class CheckContradictoryNotreachedUseTest(unittest.TestCase):
+ def testValid(self):
+ lines = ['{',
+ ' // NOTREACHED();',
+ ' /* NOTREACHED(); */',
+ " char a = '\\\\', b = '\\0', c = '\\'';",
+ ' char d[] = "NOTREACHED();";',
+ ' NOTREACHED(); // blah',
+ ' /* comment */',
+ ' // line continuation \\',
+ ' still inside comment',
+ ' // comment followed by empty line',
+ '',
+ ' ;; ; ;;;',
+ '}',
+ 'switch (i) {',
+ ' case 7: NOTREACHED(); break;',
+ '}']
+ output = PRESUBMIT._CheckContradictoryNotreachedUseInFile(
+ MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
+ self.assertEqual(0, len(output))
+
+ def testInvalid(self):
+ lines = ['{',
+ ' NOTREACHED();',
+ ' return;',
+ '}',
+ '{',
+ ' NOTREACHED();',
+ ' /* */',
+ ' return;',
+ ' /* */',
+ '}',
+ '{',
+ ' NOTREACHED();',
+ ' // trailing space, not a line continuation \\ ',
+ ' return;',
+ '}',
+ 'switch (i) {',
+ ' case 7: NOTREACHED(); some_thing(); break;',
+ '}']
+ output = PRESUBMIT._CheckContradictoryNotreachedUseInFile(
+ MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
+ self.assertEqual(4, len(output))
+
+
class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase):
def testFilesToCheckForIncomingDeps(self):
changed_lines = [