| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-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 """Generic presubmit checks that can be reused by other presubmit checks.""" | 6 """Generic presubmit checks that can be reused by other presubmit checks.""" |
| 7 | 7 |
| 8 | 8 |
| 9 ### Description checks | 9 ### Description checks |
| 10 | 10 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 tabs = [] | 137 tabs = [] |
| 138 for f, line_num, line in input_api.RightHandSideLines(source_file_filter): | 138 for f, line_num, line in input_api.RightHandSideLines(source_file_filter): |
| 139 if '\t' in line: | 139 if '\t' in line: |
| 140 tabs.append("%s, line %s" % (f.LocalPath(), line_num)) | 140 tabs.append("%s, line %s" % (f.LocalPath(), line_num)) |
| 141 if tabs: | 141 if tabs: |
| 142 return [output_api.PresubmitPromptWarning("Found a tab character in:", | 142 return [output_api.PresubmitPromptWarning("Found a tab character in:", |
| 143 long_text="\n".join(tabs))] | 143 long_text="\n".join(tabs))] |
| 144 return [] | 144 return [] |
| 145 | 145 |
| 146 | 146 |
| 147 def CheckChangeHasNoStrayWhitespace(input_api, output_api, |
| 148 source_file_filter=None): |
| 149 """Checks that there is no stray whitespace at source lines end.""" |
| 150 errors = [] |
| 151 for f, line_num, line in input_api.RightHandSideLines(source_file_filter): |
| 152 if line.rstrip() != line: |
| 153 errors.append("%s, line %s" % (f.LocalPath(), line_num)) |
| 154 if errors: |
| 155 return [output_api.PresubmitPromptWarning( |
| 156 "Found line ending with white spaces in:", |
| 157 long_text="\n".join(errors))] |
| 158 return [] |
| 159 |
| 160 |
| 147 def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None): | 161 def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None): |
| 148 """Checks that there aren't any lines longer than maxlen characters in any of | 162 """Checks that there aren't any lines longer than maxlen characters in any of |
| 149 the text files to be submitted. | 163 the text files to be submitted. |
| 150 """ | 164 """ |
| 151 bad = [] | 165 bad = [] |
| 152 for f, line_num, line in input_api.RightHandSideLines(source_file_filter): | 166 for f, line_num, line in input_api.RightHandSideLines(source_file_filter): |
| 153 # Allow lines with http://, https:// and #define/#pragma/#include/#if/#endif | 167 # Allow lines with http://, https:// and #define/#pragma/#include/#if/#endif |
| 154 # to exceed the maxlen rule. | 168 # to exceed the maxlen rule. |
| 155 if (len(line) > maxlen and | 169 if (len(line) > maxlen and |
| 156 not 'http://' in line and | 170 not 'http://' in line and |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 long_text=input_api.traceback.format_exc())) | 252 long_text=input_api.traceback.format_exc())) |
| 239 | 253 |
| 240 buffer = input_api.cStringIO.StringIO() | 254 buffer = input_api.cStringIO.StringIO() |
| 241 results = input_api.unittest.TextTestRunner(stream=buffer, verbosity=0).run( | 255 results = input_api.unittest.TextTestRunner(stream=buffer, verbosity=0).run( |
| 242 input_api.unittest.TestSuite(tests_suite)) | 256 input_api.unittest.TestSuite(tests_suite)) |
| 243 if not results.wasSuccessful(): | 257 if not results.wasSuccessful(): |
| 244 outputs.append(message_type("%d unit tests failed." % | 258 outputs.append(message_type("%d unit tests failed." % |
| 245 (len(results.failures) + len(results.errors)), | 259 (len(results.failures) + len(results.errors)), |
| 246 long_text=buffer.getvalue())) | 260 long_text=buffer.getvalue())) |
| 247 return outputs | 261 return outputs |
| OLD | NEW |