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

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: Fixed indentation issues Created 6 years, 1 month 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
« 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 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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 def testInvalidOverrideConstructsInMm(self): 466 def testInvalidOverrideConstructsInMm(self):
467 mock_input_api = MockInputApi() 467 mock_input_api = MockInputApi()
468 lines_mm = ['foo4() OVERRIDE final;'] 468 lines_mm = ['foo4() OVERRIDE final;']
469 mock_file_mm = MockFile('something.mm', lines_mm) 469 mock_file_mm = MockFile('something.mm', lines_mm)
470 mock_input_api.files = [mock_file_mm] 470 mock_input_api.files = [mock_file_mm]
471 errors = PRESUBMIT._CheckForOverrideAndFinalRules(mock_input_api, 471 errors = PRESUBMIT._CheckForOverrideAndFinalRules(mock_input_api,
472 MockOutputApi()) 472 MockOutputApi())
473 self.assertEqual(1, len(errors)) 473 self.assertEqual(1, len(errors))
474 474
475 475
476 class InvalidWeakPtrOrderCheck(unittest.TestCase):
477 def testForValidWeakPtrOrderBeingLastMember(self):
478 mock_input_api = MockInputApi()
479 lines_h = ['#include "base/memory/weak_ptr.h"',
480 'class A {',
481 ' int a;',
482 ' float b;',
483 ' char c;',
484 '',
485 ' //WeakPtrFactory should be last one,',
486 ' //all the member variables should appear above it.',
487 ' base::WeakPtrFactory<A> weak_factory_;',
488 '};']
489 mock_file_h = MockFile('something.h', lines_h)
490 mock_input_api.files = [mock_file_h]
491 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
492 self.assertEqual(0, len(errors))
493
494 def testForValidWeakPtrOrderBeingMemberBeforeDisallowMacro(self):
495 mock_input_api = MockInputApi()
496 lines_h = ['#include "base/memory/weak_ptr.h"',
497 'class A {',
498 ' int a;',
499 ' float b;',
500 ' char c;',
501 '',
502 ' //WeakPtrFactory should be last one,',
503 ' //all the member variables should appear above it.',
504 ' base::WeakPtrFactory<A> weak_factory_;',
505 ' DISALLOW_COPY_AND_ASSIGN(A);',
506 '};']
507 mock_file_h = MockFile('something.h', lines_h)
508 mock_input_api.files = [mock_file_h]
509 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
510 self.assertEqual(0, len(errors))
511
512 def testForValidWeakPtrOrderNestedWeakPtrMember(self):
513 mock_input_api = MockInputApi()
514 lines_h = ['#include "base/memory/weak_ptr.h"',
515 'class A {',
516 ' int a;',
517 ' float b;',
518 ' char c;',
519 '',
520 ' //WeakPtrFactory should be last one,',
521 ' //all the member variables should appear above it.',
522 ' base::WeakPtrFactory<A> weak_factory_;',
523 ' base::WeakPtrFactory<A> weak_factory_1;',
524 ' DISALLOW_COPY_AND_ASSIGN(A);',
525 '};']
526 mock_file_h = MockFile('something.h', lines_h)
527 mock_input_api.files = [mock_file_h]
528 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
529 self.assertEqual(0, len(errors))
530
531 def testForInvalidWeakPtrOrderBeingFirstMember(self):
532 mock_input_api = MockInputApi()
533 lines_cc = ['#include "base/memory/weak_ptr.h"',
534 'class A {',
535 ' //WeakPtrFactory should be last one,',
536 ' //all the member variables should appear above it.',
537 ' base::WeakPtrFactory<A> weak_factory_;',
538 '',
539 ' int a;',
540 ' float b;',
541 ' char c;',
542 '',
543 ' DISALLOW_COPY_AND_ASSIGN(A);',
544 '};']
545 mock_file_cc = MockFile('something.cc', lines_cc)
546 mock_input_api.files = [mock_file_cc]
547 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
548 self.assertEqual(1, len(errors))
549
550 def testForInvalidWeakPtrOrderBeingInMiddle(self):
551 mock_input_api = MockInputApi()
552 lines_cpp = ['#include "base/memory/weak_ptr.h"',
553 'class A {',
554 ' int a;',
555 ' float b;',
556 '',
557 ' //WeakPtrFactory should be last one,',
558 ' //all the member variables should appear above it.',
559 ' base::WeakPtrFactory<A> weak_factory_;',
560 '',
561 ' char c;',
562 ' long d;',
563 '',
564 ' //WeakPtrFactory should be last one,',
565 ' //all the member variables should appear above it.',
566 ' base::WeakPtrFactory<A> weak_factory_1;',
567 ' DISALLOW_COPY_AND_ASSIGN(A);',
568 '};']
569 mock_file_cpp = MockFile('something.cpp', lines_cpp)
570 mock_input_api.files = [mock_file_cpp]
571 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
572 self.assertEqual(1, len(errors))
573
574 def testForInvalidWeakPtrOrderVaribleAfterWeakptr(self):
575 mock_input_api = MockInputApi()
576 lines_mm = ['#include "base/memory/weak_ptr.h"',
577 'class A {',
578 ' int a;',
579 ' float b;',
580 '',
581 ' //WeakPtrFactory should be last one,',
582 ' //all the member variables should appear above it.',
583 ' base::WeakPtrFactory<A> weak_factory_;',
584 ' char c;',
585 ' DISALLOW_COPY_AND_ASSIGN(A);',
586 '};']
587 mock_file_mm = MockFile('something.mm', lines_mm)
588 mock_input_api.files = [mock_file_mm]
589 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
590 self.assertEqual(1, len(errors))
591
592 def testForInvalidWeakPtrOrderMultipleFiles(self):
593 mock_input_api = MockInputApi()
594 lines_cc = ['#include "base/memory/weak_ptr.h"',
595 'class B {',
596 ' //WeakPtrFactory should be last one,',
597 ' //all the member variables should appear above it.',
598 ' base::WeakPtrFactory<B> weak_factory_;',
599 '',
600 ' int a;',
601 ' float b;',
602 ' char c;',
603 ' DISALLOW_COPY_AND_ASSIGN(B);',
604 '};']
605 lines_cpp = ['#include "base/memory/weak_ptr.h"',
606 'class C {',
607 ' int a;',
608 ' float b;',
609 '',
610 ' //WeakPtrFactory should be last one,',
611 ' //all the member variables should appear above it.',
612 ' base::WeakPtrFactory<C> weak_factory_;',
613 ' char c;',
614 ' DISALLOW_COPY_AND_ASSIGN(C);',
615 '};']
616 lines_h = ['#include "base/memory/weak_ptr.h"',
617 'class A {',
618 ' int a;',
619 ' float b;',
620 ' char c;',
621 '',
622 ' //WeakPtrFactory should be last one,',
623 ' //all the member variables should appear above it.',
624 ' base::WeakPtrFactory<A> weak_factory_;',
625 ' DISALLOW_COPY_AND_ASSIGN(A);',
626 '};']
627 lines_mm = ['#include "base/memory/weak_ptr.h"',
628 'class D {',
629 ' int a;',
630 ' float b;',
631 '',
632 ' //WeakPtrFactory should be last one,',
633 ' //all the member variables should appear above it.',
634 ' base::WeakPtrFactory<D> weak_factory_;',
635 ' char c;',
636 ' long abc;',
637 ' DISALLOW_COPY_AND_ASSIGN(D);',
638 '};']
639 mock_file_cc = MockFile('something.cc', lines_cc)
640 mock_file_cpp = MockFile('something.cpp', lines_cpp)
641 mock_file_h = MockFile('something.h', lines_h)
642 mock_file_mm = MockFile('something.mm', lines_mm)
643 mock_input_api.files = [mock_file_cc,
644 mock_file_cpp,
645 mock_file_h,
646 mock_file_mm]
647 errors = PRESUBMIT._CheckForWeakPtrOrder(mock_input_api, MockOutputApi())
648 self.assertEqual(1, len(errors))
649
650
476 class InvalidIfDefinedMacroNamesTest(unittest.TestCase): 651 class InvalidIfDefinedMacroNamesTest(unittest.TestCase):
477 def testInvalidIfDefinedMacroNames(self): 652 def testInvalidIfDefinedMacroNames(self):
478 lines = ['#if defined(TARGET_IPHONE_SIMULATOR)', 653 lines = ['#if defined(TARGET_IPHONE_SIMULATOR)',
479 '#if !defined(TARGET_IPHONE_SIMULATOR)', 654 '#if !defined(TARGET_IPHONE_SIMULATOR)',
480 '#elif defined(TARGET_IPHONE_SIMULATOR)', 655 '#elif defined(TARGET_IPHONE_SIMULATOR)',
481 '#ifdef TARGET_IPHONE_SIMULATOR', 656 '#ifdef TARGET_IPHONE_SIMULATOR',
482 ' # ifdef TARGET_IPHONE_SIMULATOR', 657 ' # ifdef TARGET_IPHONE_SIMULATOR',
483 '# if defined(VALID) || defined(TARGET_IPHONE_SIMULATOR)', 658 '# if defined(VALID) || defined(TARGET_IPHONE_SIMULATOR)',
484 '# else // defined(TARGET_IPHONE_SIMULATOR)', 659 '# else // defined(TARGET_IPHONE_SIMULATOR)',
485 '#endif // defined(TARGET_IPHONE_SIMULATOR)',] 660 '#endif // defined(TARGET_IPHONE_SIMULATOR)',]
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 } 1013 }
839 for master, bots in bots.iteritems(): 1014 for master, bots in bots.iteritems():
840 for bot in bots: 1015 for bot in bots:
841 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), 1016 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot),
842 'bot=%s: expected %s, computed %s' % ( 1017 'bot=%s: expected %s, computed %s' % (
843 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) 1018 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot)))
844 1019
845 1020
846 if __name__ == '__main__': 1021 if __name__ == '__main__':
847 unittest.main() 1022 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