diff options
-rw-r--r-- | PRESUBMIT.py | 11 | ||||
-rwxr-xr-x | PRESUBMIT_test.py | 59 |
2 files changed, 70 insertions, 0 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 6ab4491..f16d273 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -669,6 +669,7 @@ def _CommonChecks(input_api, output_api): results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) results.extend(_CheckIncludeOrder(input_api, output_api)) results.extend(_CheckForVersionControlConflicts(input_api, output_api)) + results.extend(_CheckPatchFiles(input_api, output_api)) if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): results.extend(input_api.canned_checks.RunUnitTestsInDirectory( @@ -752,6 +753,16 @@ def _CheckAuthorizedAuthor(input_api, output_api): return [] +def _CheckPatchFiles(input_api, output_api): + problems = [f.LocalPath() for f in input_api.AffectedFiles() + if f.LocalPath().endswith(('.orig', '.rej'))] + if problems: + return [output_api.PresubmitError( + "Don't commit .rej and .orig files.", problems)] + else: + return [] + + def CheckChangeOnUpload(input_api, output_api): results = [] results.extend(_CommonChecks(input_api, output_api)) diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index 183ec6e..debe33b 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py @@ -14,6 +14,27 @@ class MockInputApi(object): def __init__(self): self.re = re self.os_path = os.path + self.files = [] + + def AffectedFiles(self): + return self.files + + +class MockOutputApi(object): + class PresubmitResult(object): + def __init__(self, message, items=None, long_text=''): + self.message = message + self.items = items + self.long_text = long_text + + class PresubmitError(PresubmitResult): + pass + + class PresubmitPromptWarning(PresubmitResult): + pass + + class PresubmitNotifyResult(PresubmitResult): + pass class MockFile(object): @@ -201,5 +222,43 @@ class VersionControlerConflictsTest(unittest.TestCase): self.assertTrue('5' in errors[2]) +class BadExtensionsTest(unittest.TestCase): + def testBadRejFile(self): + mock_input_api = MockInputApi() + mock_input_api.files = [ + MockFile('some/path/foo.cc', ''), + MockFile('some/path/foo.cc.rej', ''), + MockFile('some/path2/bar.h.rej', ''), + ] + + results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi()) + self.assertEqual(1, len(results)) + self.assertEqual(2, len(results[0].items)) + self.assertTrue('foo.cc.rej' in results[0].items[0]) + self.assertTrue('bar.h.rej' in results[0].items[1]) + + def testBadOrigFile(self): + mock_input_api = MockInputApi() + mock_input_api.files = [ + MockFile('other/path/qux.h.orig', ''), + MockFile('other/path/qux.h', ''), + MockFile('other/path/qux.cc', ''), + ] + + results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi()) + self.assertEqual(1, len(results)) + self.assertEqual(1, len(results[0].items)) + self.assertTrue('qux.h.orig' in results[0].items[0]) + + def testGoodFiles(self): + mock_input_api = MockInputApi() + mock_input_api.files = [ + MockFile('other/path/qux.h', ''), + MockFile('other/path/qux.cc', ''), + ] + results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi()) + self.assertEqual(0, len(results)) + + if __name__ == '__main__': unittest.main() |