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 """Unit tests for gclient.py. | 6 """Unit tests for gclient.py. |
7 | 7 |
8 See gclient_smoketest.py for integration tests. | 8 See gclient_smoketest.py for integration tests. |
9 """ | 9 """ |
10 | 10 |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 self.assertEquals( | 604 self.assertEquals( |
605 [ | 605 [ |
606 'svn://example.com/foo', | 606 'svn://example.com/foo', |
607 'svn://example.com/foo/baz', | 607 'svn://example.com/foo/baz', |
608 'svn://example.com/foo/src_unix', | 608 'svn://example.com/foo/src_unix', |
609 'svn://example.com/foo/unix', | 609 'svn://example.com/foo/unix', |
610 ], | 610 ], |
611 sorted(self._get_processed())) | 611 sorted(self._get_processed())) |
612 | 612 |
613 def testRecursionOverride(self): | 613 def testRecursionOverride(self): |
614 """Verifies gclient respects the recursion var syntax. | 614 """Verifies gclient respects the |recursion| var syntax. |
615 | 615 |
616 We check several things here: | 616 We check several things here: |
617 - recursion = 3 sets recursion on the foo dep to exactly 3 | 617 - |recursion| = 3 sets recursion on the foo dep to exactly 3 |
618 (we pull /fizz, but not /fuzz) | 618 (we pull /fizz, but not /fuzz) |
619 - pulling foo/bar at recursion level 1 (in .gclient) is overriden by | 619 - pulling foo/bar at recursion level 1 (in .gclient) is overriden by |
620 a later pull of foo/bar at recursion level 2 (in the dep tree) | 620 a later pull of foo/bar at recursion level 2 (in the dep tree) |
621 """ | 621 """ |
622 write( | 622 write( |
623 '.gclient', | 623 '.gclient', |
624 'solutions = [\n' | 624 'solutions = [\n' |
625 ' { "name": "foo", "url": "svn://example.com/foo" },\n' | 625 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
626 ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' | 626 ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' |
627 ']') | 627 ']') |
(...skipping 25 matching lines...) Expand all Loading... |
653 self.assertEquals( | 653 self.assertEquals( |
654 [ | 654 [ |
655 'svn://example.com/foo', | 655 'svn://example.com/foo', |
656 'svn://example.com/bar', | 656 'svn://example.com/bar', |
657 'svn://example.com/foo/bar', | 657 'svn://example.com/foo/bar', |
658 'svn://example.com/foo/bar/baz', | 658 'svn://example.com/foo/bar/baz', |
659 'svn://example.com/foo/bar/baz/fizz', | 659 'svn://example.com/foo/bar/baz/fizz', |
660 ], | 660 ], |
661 self._get_processed()) | 661 self._get_processed()) |
662 | 662 |
| 663 def testRecurselistOverride(self): |
| 664 """Verifies gclient respects the |recurselist| var syntax. |
| 665 |
| 666 This is what we mean to check here: |
| 667 - |recurselist| = [...] on 2 levels means we pull exactly 3 deps |
| 668 (up to /fizz, but not /fuzz) |
| 669 - pulling foo/bar with no recursion (in .gclient) is overriden by |
| 670 a later pull of foo/bar with recursion (in the dep tree) |
| 671 - pulling foo/tar with no recursion (in .gclient) is no recursively |
| 672 pulled (taz is left out) |
| 673 """ |
| 674 write( |
| 675 '.gclient', |
| 676 'solutions = [\n' |
| 677 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
| 678 ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' |
| 679 ' { "name": "foo/tar", "url": "svn://example.com/tar" },\n' |
| 680 ']') |
| 681 write( |
| 682 os.path.join('foo', 'DEPS'), |
| 683 'deps = {\n' |
| 684 ' "bar": "/bar",\n' |
| 685 '}\n' |
| 686 'recurselist = ["bar"]') |
| 687 write( |
| 688 os.path.join('bar', 'DEPS'), |
| 689 'deps = {\n' |
| 690 ' "baz": "/baz",\n' |
| 691 '}\n' |
| 692 'recurselist = ["baz"]') |
| 693 write( |
| 694 os.path.join('baz', 'DEPS'), |
| 695 'deps = {\n' |
| 696 ' "fizz": "/fizz",\n' |
| 697 '}') |
| 698 write( |
| 699 os.path.join('fizz', 'DEPS'), |
| 700 'deps = {\n' |
| 701 ' "fuzz": "/fuzz",\n' |
| 702 '}') |
| 703 write( |
| 704 os.path.join('tar', 'DEPS'), |
| 705 'deps = {\n' |
| 706 ' "taz": "/taz",\n' |
| 707 '}') |
| 708 |
| 709 options, _ = gclient.OptionParser().parse_args([]) |
| 710 obj = gclient.GClient.LoadCurrentConfig(options) |
| 711 obj.RunOnDeps('None', []) |
| 712 self.assertEquals( |
| 713 [ |
| 714 'svn://example.com/foo', |
| 715 'svn://example.com/bar', |
| 716 'svn://example.com/tar', |
| 717 'svn://example.com/foo/bar', |
| 718 'svn://example.com/foo/bar/baz', |
| 719 'svn://example.com/foo/bar/baz/fizz', |
| 720 ], |
| 721 self._get_processed()) |
| 722 |
| 723 def testRecursionOverridesRecurselist(self): |
| 724 """Verifies gclient respects |recursion| over |recurselist|. |
| 725 |
| 726 |recursion| is set in a top-level DEPS file. That value is meant |
| 727 to affect how many subdeps are parsed via recursion. |
| 728 |
| 729 |recurselist| is set in each DEPS file to control whether or not |
| 730 to recurse into the immediate next subdep. |
| 731 |
| 732 This test verifies that if both syntaxes are mixed in a DEPS file, |
| 733 we disable |recurselist| support and only obey |recursion|. |
| 734 |
| 735 Since this setting is evaluated per DEPS file, recursed DEPS |
| 736 files will each be re-evaluated according to the per DEPS rules. |
| 737 So a DEPS that only contains |recurselist| could then override any |
| 738 previous |recursion| setting. There is extra processing to ensure |
| 739 this does not happen. |
| 740 |
| 741 For this test to work correctly, we need to use a DEPS chain that |
| 742 only contains recursion controls in the top DEPS file. |
| 743 |
| 744 In foo, |recursion| and |recurselist| are specified. When we see |
| 745 |recursion|, we stop trying to use |recurselist|. |
| 746 |
| 747 There are 2 constructions of DEPS here that are key to this test: |
| 748 |
| 749 (1) In foo, if we used |recurselist| instead of |recursion|, we |
| 750 would also pull in bar. Since bar's DEPS doesn't contain any |
| 751 recursion statements, we would stop processing at bar. |
| 752 |
| 753 (2) In fizz, if we used |recurselist| at all, we should pull in |
| 754 fuzz. |
| 755 |
| 756 We expect to keep going past bar (satisfying 1) and we don't |
| 757 expect to pull in fuzz (satisfying 2). |
| 758 """ |
| 759 write( |
| 760 '.gclient', |
| 761 'solutions = [\n' |
| 762 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
| 763 ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' |
| 764 ']') |
| 765 write( |
| 766 os.path.join('foo', 'DEPS'), |
| 767 'deps = {\n' |
| 768 ' "bar": "/bar",\n' |
| 769 '}\n' |
| 770 'recursion = 3\n' |
| 771 'recurselist = ["bar"]') |
| 772 write( |
| 773 os.path.join('bar', 'DEPS'), |
| 774 'deps = {\n' |
| 775 ' "baz": "/baz",\n' |
| 776 '}') |
| 777 write( |
| 778 os.path.join('baz', 'DEPS'), |
| 779 'deps = {\n' |
| 780 ' "fizz": "/fizz",\n' |
| 781 '}') |
| 782 write( |
| 783 os.path.join('fizz', 'DEPS'), |
| 784 'deps = {\n' |
| 785 ' "fuzz": "/fuzz",\n' |
| 786 '}\n' |
| 787 'recurselist = ["fuzz"]') |
| 788 write( |
| 789 os.path.join('fuzz', 'DEPS'), |
| 790 'deps = {\n' |
| 791 ' "tar": "/tar",\n' |
| 792 '}') |
| 793 |
| 794 options, _ = gclient.OptionParser().parse_args([]) |
| 795 obj = gclient.GClient.LoadCurrentConfig(options) |
| 796 obj.RunOnDeps('None', []) |
| 797 self.assertEquals( |
| 798 [ |
| 799 'svn://example.com/foo', |
| 800 'svn://example.com/bar', |
| 801 'svn://example.com/foo/bar', |
| 802 # Deps after this would have been skipped if we were obeying |
| 803 # |recurselist|. |
| 804 'svn://example.com/foo/bar/baz', |
| 805 'svn://example.com/foo/bar/baz/fizz', |
| 806 # And this dep would have been picked up if we were obeying |
| 807 # |recurselist|. |
| 808 # 'svn://example.com/foo/bar/baz/fuzz', |
| 809 ], |
| 810 self._get_processed()) |
| 811 |
663 | 812 |
664 if __name__ == '__main__': | 813 if __name__ == '__main__': |
665 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 814 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
666 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 815 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
667 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 816 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
668 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 817 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
669 logging.basicConfig( | 818 logging.basicConfig( |
670 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 819 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
671 min(sys.argv.count('-v'), 3)], | 820 min(sys.argv.count('-v'), 3)], |
672 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 821 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
673 '%(lineno)d) %(message)s') | 822 '%(lineno)d) %(message)s') |
674 unittest.main() | 823 unittest.main() |
OLD | NEW |