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

Side by Side Diff: PRESUBMIT_test.py

Issue 98143005: Adds PRESUBMIT.py check to look for unprefixed string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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
« 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/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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 self.assertTrue(':1 OS_WINDOWS' in errors[0]) 386 self.assertTrue(':1 OS_WINDOWS' in errors[0])
387 self.assertTrue('(did you mean OS_WIN?)' in errors[0]) 387 self.assertTrue('(did you mean OS_WIN?)' in errors[0])
388 388
389 def testValidOSMacroNames(self): 389 def testValidOSMacroNames(self):
390 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] 390 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS]
391 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( 391 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile(
392 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) 392 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
393 self.assertEqual(0, len(errors)) 393 self.assertEqual(0, len(errors))
394 394
395 395
396 class String16Test(unittest.TestCase):
397 def testUnprefixedGivesWarnings(self):
398 lines = ['string16 GetName() const;',
399 'void SetName(const string16& name) OVERRIDE {}',
400 'const string16& GetNameRef() const = 0;',
401 'string16 name;',
402 'string16 foo = ASCIIToUTF16("bar");',
403 'string16 blah(ASCIIToUTF16("blee"));',
404 'std::vector<string16> names;',
405 'string16 var_with_string16_in_name;']
406 warnings = PRESUBMIT._CheckForString16InFile(
407 MockInputApi(), MockFile('chrome/browser/name_getter_bad.cc', lines))
408 self.assertEqual(len(lines), len(warnings))
409
410 def testPrefixedSkipped(self):
411 lines = ['#include "base/strings/string16.h"',
412 'void SetName(const base::string16& name) OVERRIDE {}',
413 'const base::string16& GetNameRef() const = 0;',
414 'base::string16 name;',
415 'base::string16 foo = ASCIIToUTF16("bar");',
416 'base::string16 blah(ASCIIToUTF16("blee"));',
417 'std::vector<base::string16> names;',
418 'base::string16 var_with_string16_in_name;']
419 warnings = PRESUBMIT._CheckForString16InFile(
420 MockInputApi(), MockFile('chrome/browser/name_getter_good.cc', lines))
421 self.assertEqual(0, len(warnings))
422
423 def testUsingYieldsNoWarnings(self):
424 lines = ['#include "base/strings/string16.h',
425 'namespace {',
426 'using base::string16;',
427 'string16 SayHiOnlyToEd(const string16& name) {',
428 ' string16 first = name.substr(0, 2); // Only "Ed" gets a "Hi".',
429 ' return first == "Ed" ? first : string16();',
430 '}']
431 warnings = PRESUBMIT._CheckForString16InFile(
432 MockInputApi(), MockFile('chrome/browser/say_hi_to_ed.cc', lines))
433 self.assertEqual(0, len(warnings))
434
435
396 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): 436 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase):
397 def testDepsFilesToCheck(self): 437 def testDepsFilesToCheck(self):
398 changed_lines = [ 438 changed_lines = [
399 '"+breakpad",', 439 '"+breakpad",',
400 '"+chrome/installer",', 440 '"+chrome/installer",',
401 '"+chrome/plugin/chrome_content_plugin_client.h",', 441 '"+chrome/plugin/chrome_content_plugin_client.h",',
402 '"+chrome/utility/chrome_content_utility_client.h",', 442 '"+chrome/utility/chrome_content_utility_client.h",',
403 '"+chromeos/chromeos_paths.h",', 443 '"+chromeos/chromeos_paths.h",',
404 '"+components/breakpad",', 444 '"+components/breakpad",',
405 '"+components/nacl/common",', 445 '"+components/nacl/common",',
(...skipping 19 matching lines...) Expand all
425 'policy/DEPS', 465 'policy/DEPS',
426 'sandbox/DEPS', 466 'sandbox/DEPS',
427 'tools/memory_watcher/DEPS', 467 'tools/memory_watcher/DEPS',
428 'third_party/lss/DEPS', 468 'third_party/lss/DEPS',
429 ]) 469 ])
430 self.assertEqual(expected, files_to_check); 470 self.assertEqual(expected, files_to_check);
431 471
432 472
433 if __name__ == '__main__': 473 if __name__ == '__main__':
434 unittest.main() 474 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