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

Side by Side Diff: PRESUBMIT_test.py

Issue 669853003: Adding presubmit check for WeakPtrFactory in the code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch on latest code Created 6 years, 2 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
« 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 glob 6 import glob
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 import subprocess 10 import subprocess
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 self.assertTrue(':1 OS_WINDOWS' in errors[0]) 406 self.assertTrue(':1 OS_WINDOWS' in errors[0])
407 self.assertTrue('(did you mean OS_WIN?)' in errors[0]) 407 self.assertTrue('(did you mean OS_WIN?)' in errors[0])
408 408
409 def testValidOSMacroNames(self): 409 def testValidOSMacroNames(self):
410 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] 410 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS]
411 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( 411 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile(
412 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) 412 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
413 self.assertEqual(0, len(errors)) 413 self.assertEqual(0, len(errors))
414 414
415 415
416 class InvalidWeakPtrOrderCheck(unittest.TestCase):
417 def testForValidWeakPtrOrderBeingLastMember(self):
418 mock_input_api = MockInputApi()
419 lines_h = ['#include "base/memory/weak_ptr.h"',
420 'class A {',
421 ' int a;',
422 ' float b;',
423 ' char c;',
424 '',
425 ' //WeakPtrFactory should be last one,',
426 ' //all the member variables should appear above it.',
427 ' base::WeakPtrFactory<A> weak_factory_;',
428 '};']
429 mock_file_h = MockFile('something.h', lines_h)
430 mock_input_api.files = [mock_file_h]
431 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
432 self.assertEqual(0, len(errors))
433
434 def testForValidWeakPtrOrderBeingMemberBeforeDisallowMacro(self):
435 mock_input_api = MockInputApi()
436 lines_h = ['#include "base/memory/weak_ptr.h"',
437 'class A {',
438 ' int a;',
439 ' float b;',
440 ' char c;',
441 '',
442 ' //WeakPtrFactory should be last one,',
443 ' //all the member variables should appear above it.',
444 ' base::WeakPtrFactory<A> weak_factory_;',
445 ' DISALLOW_COPY_AND_ASSIGN(A);',
446 '};']
447 mock_file_h = MockFile('something.h', lines_h)
448 mock_input_api.files = [mock_file_h]
449 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
450 self.assertEqual(0, len(errors))
451
452 def testForValidWeakPtrOrderNestedWeakPtrMember(self):
453 mock_input_api = MockInputApi()
454 lines_h = ['#include "base/memory/weak_ptr.h"',
455 'class A {',
456 ' int a;',
457 ' float b;',
458 ' char c;',
459 '',
460 ' //WeakPtrFactory should be last one,',
461 ' //all the member variables should appear above it.',
462 ' base::WeakPtrFactory<A> weak_factory_;',
463 ' base::WeakPtrFactory<A> weak_factory_1;',
464 ' DISALLOW_COPY_AND_ASSIGN(A);',
465 '};']
466 mock_file_h = MockFile('something.h', lines_h)
467 mock_input_api.files = [mock_file_h]
468 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
469 self.assertEqual(0, len(errors))
470
471 def testForInvalidWeakPtrOrderBeingFirstMember(self):
472 mock_input_api = MockInputApi()
473 lines_cc = ['#include "base/memory/weak_ptr.h"',
474 'class A {',
475 ' //WeakPtrFactory should be last one,',
476 ' //all the member variables should appear above it.',
477 ' base::WeakPtrFactory<A> weak_factory_;',
478 '',
479 ' int a;',
480 ' float b;',
481 ' char c;',
482 '',
483 ' DISALLOW_COPY_AND_ASSIGN(A);',
484 '};']
485 mock_file_cc = MockFile('something.cc', lines_cc)
486 mock_input_api.files = [mock_file_cc]
487 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
488 self.assertEqual(1, len(errors))
489
490 def testForInvalidWeakPtrOrderBeingInMiddle(self):
491 mock_input_api = MockInputApi()
492 lines_cpp = ['#include "base/memory/weak_ptr.h"',
493 'class A {',
494 ' int a;',
495 ' float b;',
496 '',
497 ' //WeakPtrFactory should be last one,',
498 ' //all the member variables should appear above it.',
499 ' base::WeakPtrFactory<A> weak_factory_;',
500 '',
501 ' char c;',
502 ' long d;',
503 '',
504 ' //WeakPtrFactory should be last one,',
505 ' //all the member variables should appear above it.',
506 ' base::WeakPtrFactory<A> weak_factory_1;',
507 ' DISALLOW_COPY_AND_ASSIGN(A);',
508 '};']
509 mock_file_cpp = MockFile('something.cpp', lines_cpp)
510 mock_input_api.files = [mock_file_cpp]
511 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
512 self.assertEqual(1, len(errors))
513
514 def testForInvalidWeakPtrOrderVaribleAfterWeakptr(self):
515 mock_input_api = MockInputApi()
516 lines_mm = ['#include "base/memory/weak_ptr.h"',
517 'class A {',
518 ' int a;',
519 ' float b;',
520 '',
521 ' //WeakPtrFactory should be last one,',
522 ' //all the member variables should appear above it.',
523 ' base::WeakPtrFactory<A> weak_factory_;',
524 ' char c;',
525 ' DISALLOW_COPY_AND_ASSIGN(A);',
526 '};']
527 mock_file_mm = MockFile('something.mm', lines_mm)
528 mock_input_api.files = [mock_file_mm]
529 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
530 self.assertEqual(1, len(errors))
531
532 def testForInvalidWeakPtrOrderMultipleFiles(self):
533 mock_input_api = MockInputApi()
534 lines_cc = ['#include "base/memory/weak_ptr.h"',
535 'class B {',
536 ' //WeakPtrFactory should be last one,',
537 ' //all the member variables should appear above it.',
538 ' base::WeakPtrFactory<B> weak_factory_;',
539 '',
540 ' int a;',
541 ' float b;',
542 ' char c;',
543 ' DISALLOW_COPY_AND_ASSIGN(B);',
544 '};']
545 lines_cpp = ['#include "base/memory/weak_ptr.h"',
546 'class C {',
547 ' int a;',
548 ' float b;',
549 '',
550 ' //WeakPtrFactory should be last one,',
551 ' //all the member variables should appear above it.',
552 ' base::WeakPtrFactory<C> weak_factory_;',
553 ' char c;',
554 ' DISALLOW_COPY_AND_ASSIGN(C);',
555 '};']
556 lines_h = ['#include "base/memory/weak_ptr.h"',
557 'class A {',
558 ' int a;',
559 ' float b;',
560 ' char c;',
561 '',
562 ' //WeakPtrFactory should be last one,',
563 ' //all the member variables should appear above it.',
564 ' base::WeakPtrFactory<A> weak_factory_;',
565 ' DISALLOW_COPY_AND_ASSIGN(A);',
566 '};']
567 lines_mm = ['#include "base/memory/weak_ptr.h"',
568 'class D {',
569 ' int a;',
570 ' float b;',
571 '',
572 ' //WeakPtrFactory should be last one,',
573 ' //all the member variables should appear above it.',
574 ' base::WeakPtrFactory<D> weak_factory_;',
575 ' char c;',
576 ' long abc;',
577 ' DISALLOW_COPY_AND_ASSIGN(D);',
578 '};']
579 mock_file_cc = MockFile('something.cc', lines_cc)
580 mock_file_cpp = MockFile('something.cpp', lines_cpp)
581 mock_file_h = MockFile('something.h', lines_h)
582 mock_file_mm = MockFile('something.mm', lines_mm)
583 mock_input_api.files = [mock_file_cc,
584 mock_file_cpp,
585 mock_file_h,
586 mock_file_mm]
587 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
588 self.assertEqual(1, len(errors))
589
590
416 class InvalidIfDefinedMacroNamesTest(unittest.TestCase): 591 class InvalidIfDefinedMacroNamesTest(unittest.TestCase):
417 def testInvalidIfDefinedMacroNames(self): 592 def testInvalidIfDefinedMacroNames(self):
418 lines = ['#if defined(TARGET_IPHONE_SIMULATOR)', 593 lines = ['#if defined(TARGET_IPHONE_SIMULATOR)',
419 '#if !defined(TARGET_IPHONE_SIMULATOR)', 594 '#if !defined(TARGET_IPHONE_SIMULATOR)',
420 '#elif defined(TARGET_IPHONE_SIMULATOR)', 595 '#elif defined(TARGET_IPHONE_SIMULATOR)',
421 '#ifdef TARGET_IPHONE_SIMULATOR', 596 '#ifdef TARGET_IPHONE_SIMULATOR',
422 ' # ifdef TARGET_IPHONE_SIMULATOR', 597 ' # ifdef TARGET_IPHONE_SIMULATOR',
423 '# if defined(VALID) || defined(TARGET_IPHONE_SIMULATOR)', 598 '# if defined(VALID) || defined(TARGET_IPHONE_SIMULATOR)',
424 '# else // defined(TARGET_IPHONE_SIMULATOR)', 599 '# else // defined(TARGET_IPHONE_SIMULATOR)',
425 '#endif // defined(TARGET_IPHONE_SIMULATOR)',] 600 '#endif // defined(TARGET_IPHONE_SIMULATOR)',]
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 } 947 }
773 for master, bots in bots.iteritems(): 948 for master, bots in bots.iteritems():
774 for bot in bots: 949 for bot in bots:
775 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), 950 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot),
776 'bot=%s: expected %s, computed %s' % ( 951 'bot=%s: expected %s, computed %s' % (
777 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) 952 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot)))
778 953
779 954
780 if __name__ == '__main__': 955 if __name__ == '__main__':
781 unittest.main() 956 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