summaryrefslogtreecommitdiffstats
path: root/PRESUBMIT_unittest.py
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-05 14:03:14 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-05 14:03:14 +0000
commit3347870323d0366168c1ddf11a484b30207bea05 (patch)
tree96163352e7030d90fc17d0f4ff4ae4312876e74d /PRESUBMIT_unittest.py
parentf0a51fb571f46531025fa09240bbc3e1af925e84 (diff)
downloadchromium_src-3347870323d0366168c1ddf11a484b30207bea05.zip
chromium_src-3347870323d0366168c1ddf11a484b30207bea05.tar.gz
chromium_src-3347870323d0366168c1ddf11a484b30207bea05.tar.bz2
- Add «no trailing whitespace» and <=80 cols rules.
- Remove the invalid import os statement (PRESUBMIT.py shouldn't import anything). - Add excluded paths. Mostly third parties. - Increase what is considered a source file. - Don't check for DO NOT SUBMIT on upload. Review URL: http://codereview.chromium.org/28219 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10983 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT_unittest.py')
-rwxr-xr-xPRESUBMIT_unittest.py48
1 files changed, 30 insertions, 18 deletions
diff --git a/PRESUBMIT_unittest.py b/PRESUBMIT_unittest.py
index 5a2c514..b8183c2 100755
--- a/PRESUBMIT_unittest.py
+++ b/PRESUBMIT_unittest.py
@@ -7,14 +7,21 @@
"""
+import os
import PRESUBMIT
+import re
import unittest
class MockInputApi(object):
def __init__(self):
self.affected_files = []
-
+ self.re = re
+ self.os_path = os.path
+
+ def AffectedFiles(self):
+ return self.affected_files
+
def AffectedTextFiles(self, include_deletes=True):
return self.affected_files
@@ -22,14 +29,14 @@ class MockInputApi(object):
class MockAffectedFile(object):
def __init__(self, path):
self.path = path
-
+
def LocalPath(self):
return self.path
class MockOutputApi(object):
class PresubmitError(object):
- def __init__(self, msg, items):
+ def __init__(self, msg, items=[], long_text=''):
self.msg = msg
self.items = items
@@ -41,34 +48,39 @@ class PresubmitUnittest(unittest.TestCase):
self.failIf(path.endswith('notsource'))
return self.file_contents
PRESUBMIT._ReadFile = MockReadFile
-
+
def tearDown(self):
PRESUBMIT._ReadFile = PRESUBMIT.ReadFile
-
- def testCheckNoCrLfOrTabs(self):
+
+ def testLocalChecks(self):
api = MockInputApi()
api.affected_files = [
MockAffectedFile('foo/blat/yoo.notsource'),
+ MockAffectedFile('third_party/blat/source.cc'),
MockAffectedFile('foo/blat/source.h'),
MockAffectedFile('foo/blat/source.mm'),
MockAffectedFile('foo/blat/source.py'),
]
- self.file_contents = 'file with\nerror\nhere\r\nyes there'
- self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 1)
- self.failUnless(
- len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)[0].items) == 3)
-
+ self.file_contents = 'file with \n\terror\nhere\r\nyes there'
+ # 3 source files, 2 errors by file + 1 global CR error.
+ self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 7)
+
self.file_contents = 'file\twith\ttabs'
- self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 1)
-
+ # 3 source files, 1 error by file.
+ self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 3)
+
self.file_contents = 'file\rusing\rCRs'
- self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 1)
-
+ # One global CR error.
+ self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 1)
+ self.failUnless(
+ len(PRESUBMIT.LocalChecks(api, MockOutputApi)[0].items) == 3)
+
self.file_contents = 'both\ttabs and\r\nCRLF'
- self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 2)
-
+ # 3 source files, 1 error by file + 1 global CR error.
+ self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 4)
+
self.file_contents = 'file with\nzero \\t errors \\r\\n'
- self.failIf(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi))
+ self.failIf(PRESUBMIT.LocalChecks(api, MockOutputApi))
if __name__ == '__main__':