Chromium Code Reviews| 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 def CheckChangeHasTestField(input_api, output_api): | 9 def CheckChangeHasTestField(input_api, output_api): |
| 10 """Requires that the changelist have a TEST= field.""" | 10 """Requires that the changelist have a TEST= field.""" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 (f.LocalPath(), line_num))] | 91 (f.LocalPath(), line_num))] |
| 92 return [] | 92 return [] |
| 93 | 93 |
| 94 | 94 |
| 95 def CheckLongLines(input_api, output_api, maxlen=80): | 95 def CheckLongLines(input_api, output_api, maxlen=80): |
| 96 """Checks that there aren't any lines longer than maxlen characters in any of | 96 """Checks that there aren't any lines longer than maxlen characters in any of |
| 97 the text files to be submitted. | 97 the text files to be submitted. |
| 98 """ | 98 """ |
| 99 bad = [] | 99 bad = [] |
| 100 for f, line_num, line in input_api.RightHandSideLines(): | 100 for f, line_num, line in input_api.RightHandSideLines(): |
| 101 if len(line) > maxlen: | 101 # Allow lines with http://, https:// and #define/#pragma/#include/#if/#endif |
| 102 # to exceed the maxlen rule. | |
| 103 if (len(line) > maxlen and | |
| 104 not 'http://' in line and | |
|
Jói Sigurðsson
2009/06/09 01:39:16
a regexp combining all of these cases would be fas
M-A Ruel
2009/06/09 01:44:37
Yes it's slightly verbose but I thought it was mor
| |
| 105 not 'https://' in line and | |
| 106 not line.startswith('#define') and | |
| 107 not line.startswith('#include') and | |
| 108 not line.startswith('#pragma') and | |
| 109 not line.startswith('#if') and | |
| 110 not line.startswith('#endif')): | |
| 102 bad.append( | 111 bad.append( |
| 103 '%s, line %s, %s chars' % | 112 '%s, line %s, %s chars' % |
| 104 (f.LocalPath(), line_num, len(line))) | 113 (f.LocalPath(), line_num, len(line))) |
| 105 if len(bad) == 5: # Just show the first 5 errors. | 114 if len(bad) == 5: # Just show the first 5 errors. |
| 106 break | 115 break |
| 107 | 116 |
| 108 if bad: | 117 if bad: |
| 109 msg = "Found lines longer than %s characters (first 5 shown)." % maxlen | 118 msg = "Found lines longer than %s characters (first 5 shown)." % maxlen |
| 110 return [output_api.PresubmitPromptWarning(msg, items=bad)] | 119 return [output_api.PresubmitPromptWarning(msg, items=bad)] |
| 111 else: | 120 else: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 except ImportError: | 160 except ImportError: |
| 152 outputs.append(message_type("Failed to load %s" % unit_test, | 161 outputs.append(message_type("Failed to load %s" % unit_test, |
| 153 long_text=input_api.traceback.format_exc())) | 162 long_text=input_api.traceback.format_exc())) |
| 154 | 163 |
| 155 results = input_api.unittest.TextTestRunner(verbosity=0).run( | 164 results = input_api.unittest.TextTestRunner(verbosity=0).run( |
| 156 input_api.unittest.TestSuite(tests_suite)) | 165 input_api.unittest.TestSuite(tests_suite)) |
| 157 if not results.wasSuccessful(): | 166 if not results.wasSuccessful(): |
| 158 outputs.append(message_type("%d unit tests failed." % | 167 outputs.append(message_type("%d unit tests failed." % |
| 159 (len(results.failures) + len(results.errors)))) | 168 (len(results.failures) + len(results.errors)))) |
| 160 return outputs | 169 return outputs |
| OLD | NEW |