Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Unified Diff: PRESUBMIT_test.py

Issue 11448014: Add a presubmit check to prevent committing .rej/.orig patch files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address all comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT_test.py
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 183ec6e54c839f71ad98827228ce195faa71819e..debe33b899bae74da065b2f5d14e5e875127cd01 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()
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698