Chromium Code Reviews| 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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after 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): | 663 def testRecursedepsOverride(self): |
| 664 """Verifies gclient respects the |recurselist| var syntax. | 664 """Verifies gclient respects the |recursedeps| var syntax. |
| 665 | 665 |
| 666 This is what we mean to check here: | 666 This is what we mean to check here: |
| 667 - |recurselist| = [...] on 2 levels means we pull exactly 3 deps | 667 - |recursedeps| = {...} on 2 levels means we pull exactly 3 deps |
| 668 (up to /fizz, but not /fuzz) | 668 (up to /fizz, but not /fuzz) |
| 669 - pulling foo/bar with no recursion (in .gclient) is overriden by | 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) | 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 | 671 - pulling foo/tar with no recursion (in .gclient) is no recursively |
| 672 pulled (taz is left out) | 672 pulled (taz is left out) |
| 673 """ | 673 """ |
| 674 write( | 674 write( |
| 675 '.gclient', | 675 '.gclient', |
| 676 'solutions = [\n' | 676 'solutions = [\n' |
| 677 ' { "name": "foo", "url": "svn://example.com/foo" },\n' | 677 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
| 678 ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' | 678 ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' |
| 679 ' { "name": "foo/tar", "url": "svn://example.com/tar" },\n' | 679 ' { "name": "foo/tar", "url": "svn://example.com/tar" },\n' |
| 680 ']') | 680 ']') |
| 681 write( | 681 write( |
| 682 os.path.join('foo', 'DEPS'), | 682 os.path.join('foo', 'DEPS'), |
| 683 'deps = {\n' | 683 'deps = {\n' |
| 684 ' "bar": "/bar",\n' | 684 ' "bar": "/bar",\n' |
| 685 '}\n' | 685 '}\n' |
| 686 'recurselist = ["bar"]') | 686 'recursedeps = {"bar"}') |
|
iannucci
2014/07/03 18:55:59
Note that the {'foo'} syntax is actually python 2.
| |
| 687 write( | 687 write( |
| 688 os.path.join('bar', 'DEPS'), | 688 os.path.join('bar', 'DEPS'), |
| 689 'deps = {\n' | 689 'deps = {\n' |
| 690 ' "baz": "/baz",\n' | 690 ' "baz": "/baz",\n' |
| 691 '}\n' | 691 '}\n' |
| 692 'recurselist = ["baz"]') | 692 'recursedeps = {"baz"}') |
| 693 write( | 693 write( |
| 694 os.path.join('baz', 'DEPS'), | 694 os.path.join('baz', 'DEPS'), |
| 695 'deps = {\n' | 695 'deps = {\n' |
| 696 ' "fizz": "/fizz",\n' | 696 ' "fizz": "/fizz",\n' |
| 697 '}') | 697 '}') |
| 698 write( | 698 write( |
| 699 os.path.join('fizz', 'DEPS'), | 699 os.path.join('fizz', 'DEPS'), |
| 700 'deps = {\n' | 700 'deps = {\n' |
| 701 ' "fuzz": "/fuzz",\n' | 701 ' "fuzz": "/fuzz",\n' |
| 702 '}') | 702 '}') |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 713 [ | 713 [ |
| 714 'svn://example.com/foo', | 714 'svn://example.com/foo', |
| 715 'svn://example.com/bar', | 715 'svn://example.com/bar', |
| 716 'svn://example.com/tar', | 716 'svn://example.com/tar', |
| 717 'svn://example.com/foo/bar', | 717 'svn://example.com/foo/bar', |
| 718 'svn://example.com/foo/bar/baz', | 718 'svn://example.com/foo/bar/baz', |
| 719 'svn://example.com/foo/bar/baz/fizz', | 719 'svn://example.com/foo/bar/baz/fizz', |
| 720 ], | 720 ], |
| 721 self._get_processed()) | 721 self._get_processed()) |
| 722 | 722 |
| 723 def testRecursionOverridesRecurselist(self): | 723 def testRecursionOverridesRecursedeps(self): |
| 724 """Verifies gclient respects |recursion| over |recurselist|. | 724 """Verifies gclient respects |recursion| over |recursedeps|. |
| 725 | 725 |
| 726 |recursion| is set in a top-level DEPS file. That value is meant | 726 |recursion| is set in a top-level DEPS file. That value is meant |
| 727 to affect how many subdeps are parsed via recursion. | 727 to affect how many subdeps are parsed via recursion. |
| 728 | 728 |
| 729 |recurselist| is set in each DEPS file to control whether or not | 729 |recursedeps| is set in each DEPS file to control whether or not |
| 730 to recurse into the immediate next subdep. | 730 to recurse into the immediate next subdep. |
| 731 | 731 |
| 732 This test verifies that if both syntaxes are mixed in a DEPS file, | 732 This test verifies that if both syntaxes are mixed in a DEPS file, |
| 733 we disable |recurselist| support and only obey |recursion|. | 733 we disable |recursedeps| support and only obey |recursion|. |
| 734 | 734 |
| 735 Since this setting is evaluated per DEPS file, recursed DEPS | 735 Since this setting is evaluated per DEPS file, recursed DEPS |
| 736 files will each be re-evaluated according to the per DEPS rules. | 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 | 737 So a DEPS that only contains |recursedeps| could then override any |
| 738 previous |recursion| setting. There is extra processing to ensure | 738 previous |recursion| setting. There is extra processing to ensure |
| 739 this does not happen. | 739 this does not happen. |
| 740 | 740 |
| 741 For this test to work correctly, we need to use a DEPS chain that | 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. | 742 only contains recursion controls in the top DEPS file. |
| 743 | 743 |
| 744 In foo, |recursion| and |recurselist| are specified. When we see | 744 In foo, |recursion| and |recursedeps| are specified. When we see |
| 745 |recursion|, we stop trying to use |recurselist|. | 745 |recursion|, we stop trying to use |recursedeps|. |
| 746 | 746 |
| 747 There are 2 constructions of DEPS here that are key to this test: | 747 There are 2 constructions of DEPS here that are key to this test: |
| 748 | 748 |
| 749 (1) In foo, if we used |recurselist| instead of |recursion|, we | 749 (1) In foo, if we used |recursedeps| instead of |recursion|, we |
| 750 would also pull in bar. Since bar's DEPS doesn't contain any | 750 would also pull in bar. Since bar's DEPS doesn't contain any |
| 751 recursion statements, we would stop processing at bar. | 751 recursion statements, we would stop processing at bar. |
| 752 | 752 |
| 753 (2) In fizz, if we used |recurselist| at all, we should pull in | 753 (2) In fizz, if we used |recursedeps| at all, we should pull in |
| 754 fuzz. | 754 fuzz. |
| 755 | 755 |
| 756 We expect to keep going past bar (satisfying 1) and we don't | 756 We expect to keep going past bar (satisfying 1) and we don't |
| 757 expect to pull in fuzz (satisfying 2). | 757 expect to pull in fuzz (satisfying 2). |
| 758 """ | 758 """ |
| 759 write( | 759 write( |
| 760 '.gclient', | 760 '.gclient', |
| 761 'solutions = [\n' | 761 'solutions = [\n' |
| 762 ' { "name": "foo", "url": "svn://example.com/foo" },\n' | 762 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
| 763 ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' | 763 ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' |
| 764 ']') | 764 ']') |
| 765 write( | 765 write( |
| 766 os.path.join('foo', 'DEPS'), | 766 os.path.join('foo', 'DEPS'), |
| 767 'deps = {\n' | 767 'deps = {\n' |
| 768 ' "bar": "/bar",\n' | 768 ' "bar": "/bar",\n' |
| 769 '}\n' | 769 '}\n' |
| 770 'recursion = 3\n' | 770 'recursion = 3\n' |
| 771 'recurselist = ["bar"]') | 771 'recursedeps = {"bar"}') |
| 772 write( | 772 write( |
| 773 os.path.join('bar', 'DEPS'), | 773 os.path.join('bar', 'DEPS'), |
| 774 'deps = {\n' | 774 'deps = {\n' |
| 775 ' "baz": "/baz",\n' | 775 ' "baz": "/baz",\n' |
| 776 '}') | 776 '}') |
| 777 write( | 777 write( |
| 778 os.path.join('baz', 'DEPS'), | 778 os.path.join('baz', 'DEPS'), |
| 779 'deps = {\n' | 779 'deps = {\n' |
| 780 ' "fizz": "/fizz",\n' | 780 ' "fizz": "/fizz",\n' |
| 781 '}') | 781 '}') |
| 782 write( | 782 write( |
| 783 os.path.join('fizz', 'DEPS'), | 783 os.path.join('fizz', 'DEPS'), |
| 784 'deps = {\n' | 784 'deps = {\n' |
| 785 ' "fuzz": "/fuzz",\n' | 785 ' "fuzz": "/fuzz",\n' |
| 786 '}\n' | 786 '}\n' |
| 787 'recurselist = ["fuzz"]') | 787 'recursedeps = {"fuzz"}') |
| 788 write( | 788 write( |
| 789 os.path.join('fuzz', 'DEPS'), | 789 os.path.join('fuzz', 'DEPS'), |
| 790 'deps = {\n' | 790 'deps = {\n' |
| 791 ' "tar": "/tar",\n' | 791 ' "tar": "/tar",\n' |
| 792 '}') | 792 '}') |
| 793 | 793 |
| 794 options, _ = gclient.OptionParser().parse_args([]) | 794 options, _ = gclient.OptionParser().parse_args([]) |
| 795 obj = gclient.GClient.LoadCurrentConfig(options) | 795 obj = gclient.GClient.LoadCurrentConfig(options) |
| 796 obj.RunOnDeps('None', []) | 796 obj.RunOnDeps('None', []) |
| 797 self.assertEquals( | 797 self.assertEquals( |
| 798 [ | 798 [ |
| 799 'svn://example.com/foo', | 799 'svn://example.com/foo', |
| 800 'svn://example.com/bar', | 800 'svn://example.com/bar', |
| 801 'svn://example.com/foo/bar', | 801 'svn://example.com/foo/bar', |
| 802 # Deps after this would have been skipped if we were obeying | 802 # Deps after this would have been skipped if we were obeying |
| 803 # |recurselist|. | 803 # |recursedeps|. |
| 804 'svn://example.com/foo/bar/baz', | 804 'svn://example.com/foo/bar/baz', |
| 805 'svn://example.com/foo/bar/baz/fizz', | 805 'svn://example.com/foo/bar/baz/fizz', |
| 806 # And this dep would have been picked up if we were obeying | 806 # And this dep would have been picked up if we were obeying |
| 807 # |recurselist|. | 807 # |recursedeps|. |
| 808 # 'svn://example.com/foo/bar/baz/fuzz', | 808 # 'svn://example.com/foo/bar/baz/fuzz', |
| 809 ], | 809 ], |
| 810 self._get_processed()) | 810 self._get_processed()) |
| 811 | 811 |
| 812 def testGitDeps(self): | 812 def testGitDeps(self): |
| 813 """Verifies gclient respects a .DEPS.git deps file. | 813 """Verifies gclient respects a .DEPS.git deps file. |
| 814 | 814 |
| 815 Along the way, we also test that if both DEPS and .DEPS.git are present, | 815 Along the way, we also test that if both DEPS and .DEPS.git are present, |
| 816 that gclient does not read the DEPS file. This will reliably catch bugs | 816 that gclient does not read the DEPS file. This will reliably catch bugs |
| 817 where gclient is always hitting the wrong file (DEPS). | 817 where gclient is always hitting the wrong file (DEPS). |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 874 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
| 875 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 875 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
| 876 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 876 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
| 877 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 877 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
| 878 logging.basicConfig( | 878 logging.basicConfig( |
| 879 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 879 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 880 min(sys.argv.count('-v'), 3)], | 880 min(sys.argv.count('-v'), 3)], |
| 881 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 881 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
| 882 '%(lineno)d) %(message)s') | 882 '%(lineno)d) %(message)s') |
| 883 unittest.main() | 883 unittest.main() |
| OLD | NEW |