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

Side by Side Diff: PRESUBMIT_unittest.py

Issue 43017: Add end of file newline checks to PRESUBMIT.py. (Closed)
Patch Set: Only check for \n if the file isn't empty. Created 11 years, 9 months 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 unified diff | Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for top-level Chromium presubmit script. 6 """Unit tests for top-level Chromium presubmit script.
7 """ 7 """
8 8
9 9
10 import os 10 import os
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 def testLocalChecks(self): 55 def testLocalChecks(self):
56 api = MockInputApi() 56 api = MockInputApi()
57 api.affected_files = [ 57 api.affected_files = [
58 MockAffectedFile('foo/blat/yoo.notsource'), 58 MockAffectedFile('foo/blat/yoo.notsource'),
59 MockAffectedFile('third_party/blat/source.cc'), 59 MockAffectedFile('third_party/blat/source.cc'),
60 MockAffectedFile('foo/blat/source.h'), 60 MockAffectedFile('foo/blat/source.h'),
61 MockAffectedFile('foo/blat/source.mm'), 61 MockAffectedFile('foo/blat/source.mm'),
62 MockAffectedFile('foo/blat/source.py'), 62 MockAffectedFile('foo/blat/source.py'),
63 ] 63 ]
64 self.file_contents = 'file with \n\terror\nhere\r\nyes there' 64 self.file_contents = 'file with \n\terror\nhere\r\nyes there'
65 # 3 source files, 2 errors by file + 1 global CR error. 65 # 3 source files, 2 errors by file + 1 global CR + 1 global EOF error.
66 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 7) 66 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 8)
67 67
68 self.file_contents = 'file\twith\ttabs' 68 self.file_contents = 'file\twith\ttabs\n'
69 # 3 source files, 1 error by file. 69 # 3 source files, 1 error by file.
70 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 3) 70 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 3)
71 71
72 self.file_contents = 'file\rusing\rCRs' 72 self.file_contents = 'file\rusing\rCRs\n'
73 # One global CR error. 73 # One global CR error.
74 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 1) 74 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 1)
75 self.failUnless( 75 self.failUnless(
76 len(PRESUBMIT.LocalChecks(api, MockOutputApi)[0].items) == 3) 76 len(PRESUBMIT.LocalChecks(api, MockOutputApi)[0].items) == 3)
77 77
78 self.file_contents = 'both\ttabs and\r\nCRLF' 78 self.file_contents = 'both\ttabs and\r\nCRLF\n'
79 # 3 source files, 1 error by file + 1 global CR error. 79 # 3 source files, 1 error by file + 1 global CR error.
80 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 4) 80 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 4)
81 81
82 self.file_contents = 'file with\nzero \\t errors \\r\\n' 82 self.file_contents = 'file with\nzero \\t errors \\r\\n\n'
83 self.failIf(PRESUBMIT.LocalChecks(api, MockOutputApi)) 83 self.failIf(PRESUBMIT.LocalChecks(api, MockOutputApi))
84 84
85 85
86 if __name__ == '__main__': 86 if __name__ == '__main__':
87 unittest.main() 87 unittest.main()
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698