diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-19 16:33:12 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-19 16:33:12 +0000 |
commit | ca8d1984ce76d0048e630dccdbf19492e9a87fd2 (patch) | |
tree | cdb01edbf3d7b420aaf32efd7f36883e06044fd8 /PRESUBMIT_unittest.py | |
parent | 1402c866adcaa4cc07d1da980141e3b0db5a3e01 (diff) | |
download | chromium_src-ca8d1984ce76d0048e630dccdbf19492e9a87fd2.zip chromium_src-ca8d1984ce76d0048e630dccdbf19492e9a87fd2.tar.gz chromium_src-ca8d1984ce76d0048e630dccdbf19492e9a87fd2.tar.bz2 |
Very basic starter presubmit script for Chromium, as requested by maruel.
At present this checks the following:
- No tabs in source files
- The words "DO-NOT-SUBMIT" (without the dashes) do not appear in the CL
description or in files in the change
- No CRLF in source files (.cc, .h, .mm, .py)
Limitations:
- The general limitations of the current presubmit API implementation
apply. One of these is that gcl only walks up to the checkout root
searching for presubmit files, so if you've mapped stuff into your
client using DEPS, it will only walk up to where the root of that
mapping.
Patch contributed by Jói.
Review: http://codereview.chromium.org/20474
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT_unittest.py')
-rwxr-xr-x | PRESUBMIT_unittest.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/PRESUBMIT_unittest.py b/PRESUBMIT_unittest.py new file mode 100755 index 0000000..5a2c514 --- /dev/null +++ b/PRESUBMIT_unittest.py @@ -0,0 +1,75 @@ +#!/usr/bin/python +# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Unit tests for top-level Chromium presubmit script. +""" + + +import PRESUBMIT +import unittest + + +class MockInputApi(object): + def __init__(self): + self.affected_files = [] + + def AffectedTextFiles(self, include_deletes=True): + return self.affected_files + + +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): + self.msg = msg + self.items = items + + +class PresubmitUnittest(unittest.TestCase): + def setUp(self): + self.file_contents = '' + def MockReadFile(path): + self.failIf(path.endswith('notsource')) + return self.file_contents + PRESUBMIT._ReadFile = MockReadFile + + def tearDown(self): + PRESUBMIT._ReadFile = PRESUBMIT.ReadFile + + def testCheckNoCrLfOrTabs(self): + api = MockInputApi() + api.affected_files = [ + MockAffectedFile('foo/blat/yoo.notsource'), + 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\twith\ttabs' + self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 1) + + self.file_contents = 'file\rusing\rCRs' + self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 1) + + self.file_contents = 'both\ttabs and\r\nCRLF' + self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 2) + + self.file_contents = 'file with\nzero \\t errors \\r\\n' + self.failIf(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) + + +if __name__ == '__main__': + unittest.main() |