OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 import os | 6 import os |
7 import re | 7 import re |
8 import unittest | 8 import unittest |
9 | 9 |
10 import PRESUBMIT | 10 import PRESUBMIT |
11 | 11 |
12 | 12 |
13 class MockInputApi(object): | 13 class MockInputApi(object): |
14 def __init__(self): | 14 def __init__(self): |
15 self.re = re | 15 self.re = re |
16 self.os_path = os.path | 16 self.os_path = os.path |
17 | 17 |
18 | 18 |
19 class MockFile(object): | 19 class MockFile(object): |
20 def __init__(self, local_path, new_contents): | 20 def __init__(self, local_path, new_contents): |
21 self._local_path = local_path | 21 self._local_path = local_path |
22 self._new_contents = new_contents | 22 self._new_contents = new_contents |
| 23 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] |
| 24 |
| 25 def ChangedContents(self): |
| 26 return self._changed_contents |
23 | 27 |
24 def NewContents(self): | 28 def NewContents(self): |
25 return self._new_contents | 29 return self._new_contents |
26 | 30 |
27 def LocalPath(self): | 31 def LocalPath(self): |
28 return self._local_path | 32 return self._local_path |
29 | 33 |
30 | 34 |
31 class IncludeOrderTest(unittest.TestCase): | 35 class IncludeOrderTest(unittest.TestCase): |
32 def testSystemHeaderOrder(self): | 36 def testSystemHeaderOrder(self): |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 '#else', | 169 '#else', |
166 '#include "b.h"', | 170 '#include "b.h"', |
167 '#endif', | 171 '#endif', |
168 '#include "a.h"'] | 172 '#include "a.h"'] |
169 mock_file = MockFile('', contents) | 173 mock_file = MockFile('', contents) |
170 warnings = PRESUBMIT._CheckIncludeOrderInFile( | 174 warnings = PRESUBMIT._CheckIncludeOrderInFile( |
171 mock_input_api, mock_file, True, range(1, len(contents) + 1)) | 175 mock_input_api, mock_file, True, range(1, len(contents) + 1)) |
172 self.assertEqual(0, len(warnings)) | 176 self.assertEqual(0, len(warnings)) |
173 | 177 |
174 | 178 |
| 179 class VersionControlerConflictsTest(unittest.TestCase): |
| 180 def testTypicalConflict(self): |
| 181 lines = ['<<<<<<< HEAD', |
| 182 ' base::ScopedTempDir temp_dir_;', |
| 183 '=======', |
| 184 ' ScopedTempDir temp_dir_;', |
| 185 '>>>>>>> master'] |
| 186 errors = PRESUBMIT._CheckForVersionControlConflictsInFile( |
| 187 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
| 188 self.assertEqual(3, len(errors)) |
| 189 self.assertTrue('1' in errors[0]) |
| 190 self.assertTrue('3' in errors[1]) |
| 191 self.assertTrue('5' in errors[2]) |
| 192 |
| 193 |
175 if __name__ == '__main__': | 194 if __name__ == '__main__': |
176 unittest.main() | 195 unittest.main() |
OLD | NEW |