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

Side by Side Diff: PRESUBMIT_test.py

Issue 12845013: Adding _Check* function for invalid OS_MACROs in src/PRESUBMIT.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
« PRESUBMIT.py ('K') | « 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/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
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 288
289 contents = ['#include "ipc/some_macros.h"', 289 contents = ['#include "ipc/some_macros.h"',
290 '#include "b.h"' 290 '#include "b.h"'
291 '#include "a.h"'] 291 '#include "a.h"']
292 mock_file = MockFile('', contents) 292 mock_file = MockFile('', contents)
293 warnings = PRESUBMIT._CheckIncludeOrderInFile( 293 warnings = PRESUBMIT._CheckIncludeOrderInFile(
294 mock_input_api, mock_file, range(1, len(contents) + 1)) 294 mock_input_api, mock_file, range(1, len(contents) + 1))
295 self.assertEqual(0, len(warnings)) 295 self.assertEqual(0, len(warnings))
296 296
297 297
298 class VersionControlerConflictsTest(unittest.TestCase): 298 class VersionControlConflictsTest(unittest.TestCase):
299 def testTypicalConflict(self): 299 def testTypicalConflict(self):
300 lines = ['<<<<<<< HEAD', 300 lines = ['<<<<<<< HEAD',
301 ' base::ScopedTempDir temp_dir_;', 301 ' base::ScopedTempDir temp_dir_;',
302 '=======', 302 '=======',
303 ' ScopedTempDir temp_dir_;', 303 ' ScopedTempDir temp_dir_;',
304 '>>>>>>> master'] 304 '>>>>>>> master']
305 errors = PRESUBMIT._CheckForVersionControlConflictsInFile( 305 errors = PRESUBMIT._CheckForVersionControlConflictsInFile(
306 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) 306 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
307 self.assertEqual(3, len(errors)) 307 self.assertEqual(3, len(errors))
308 self.assertTrue('1' in errors[0]) 308 self.assertTrue('1' in errors[0])
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 def testOnlyOwnersFiles(self): 350 def testOnlyOwnersFiles(self):
351 mock_change = MockChange([ 351 mock_change = MockChange([
352 'some/path/OWNERS', 352 'some/path/OWNERS',
353 'A\Windows\Path\OWNERS', 353 'A\Windows\Path\OWNERS',
354 ]) 354 ])
355 results = PRESUBMIT.GetPreferredTrySlaves(None, mock_change) 355 results = PRESUBMIT.GetPreferredTrySlaves(None, mock_change)
356 self.assertEqual(0, len(results)) 356 self.assertEqual(0, len(results))
357 357
358 358
359 class InvalidOSMacroNamesTest(unittest.TestCase):
360 def testInvalidOSMacroNames(self):
361 lines = ['#if defined(OS_WINDOWS)',
362 '#elif defined(OS_WINDOW)',
363 '#if defined(OS_MACOSX) || defined(OS_CHROME)',
364 '#else // defined(OS_MAC)',
365 '#endif // defined(OS_MACOS)']
366 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile(
367 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
368 self.assertEqual(len(lines), len(errors))
369 self.assertTrue('1' in errors[0] and 'OS_WINDOWS' in errors[0])
370
371 def testValidOSMacroNames(self):
372 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS]
373 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile(
374 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
375 self.assertEqual(0, len(errors))
376
377
359 if __name__ == '__main__': 378 if __name__ == '__main__':
360 unittest.main() 379 unittest.main()
OLDNEW
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698