OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 """Smoke tests for gclient.py. | 6 """Smoke tests for gclient.py. |
7 | 7 |
8 Shell out 'gclient' and run basic conformance tests. | 8 Shell out 'gclient' and run basic conformance tests. |
9 | 9 |
10 This test assumes GClientSmokeBase.URL_BASE is valid. | 10 This test assumes GClientSmokeBase.URL_BASE is valid. |
11 """ | 11 """ |
12 | 12 |
13 import logging | 13 import logging |
14 import os | 14 import os |
15 import re | 15 import re |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 import unittest | 18 import unittest |
19 | 19 |
20 from fake_repos import join, write, FakeReposTestBase | 20 from fake_repos import check_call, join, write, FakeReposTestBase |
21 | 21 |
22 GCLIENT_PATH = join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | 22 GCLIENT_PATH = join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), |
23 'gclient') | 23 'gclient') |
24 COVERAGE = False | 24 COVERAGE = False |
25 | 25 |
26 | 26 |
27 class GClientSmokeBase(FakeReposTestBase): | 27 class GClientSmokeBase(FakeReposTestBase): |
28 def setUp(self): | 28 def setUp(self): |
29 FakeReposTestBase.setUp(self) | 29 FakeReposTestBase.setUp(self) |
30 # Make sure it doesn't try to auto update when testing! | 30 # Make sure it doesn't try to auto update when testing! |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 results = self.splitBlock(stdout) | 96 results = self.splitBlock(stdout) |
97 for i in xrange(min(len(results), len(items))): | 97 for i in xrange(min(len(results), len(items))): |
98 if isinstance(items[i], (list, tuple)): | 98 if isinstance(items[i], (list, tuple)): |
99 verb = items[i][0] | 99 verb = items[i][0] |
100 path = items[i][1] | 100 path = items[i][1] |
101 else: | 101 else: |
102 verb = items[i] | 102 verb = items[i] |
103 path = self.root_dir | 103 path = self.root_dir |
104 self.checkString(results[i][0][0], verb, (i, results[i][0][0], verb)) | 104 self.checkString(results[i][0][0], verb, (i, results[i][0][0], verb)) |
105 self.checkString(results[i][0][2], path, (i, results[i][0][2], path)) | 105 self.checkString(results[i][0][2], path, (i, results[i][0][2], path)) |
106 self.assertEquals(len(results), len(items)) | 106 self.assertEquals(len(results), len(items), (stdout, items)) |
107 return results | 107 return results |
108 | 108 |
109 def svnBlockCleanup(self, out): | 109 def svnBlockCleanup(self, out): |
110 """Work around svn status difference between svn 1.5 and svn 1.6 | 110 """Work around svn status difference between svn 1.5 and svn 1.6 |
111 I don't know why but on Windows they are reversed. So sorts the items.""" | 111 I don't know why but on Windows they are reversed. So sorts the items.""" |
112 for i in xrange(len(out)): | 112 for i in xrange(len(out)): |
113 if len(out[i]) < 2: | 113 if len(out[i]) < 2: |
114 continue | 114 continue |
115 out[i] = [out[i][0]] + sorted([x[1:].strip() for x in out[i][1:]]) | 115 out[i] = [out[i][0]] + sorted([x[1:].strip() for x in out[i][1:]]) |
116 return out | 116 return out |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 ('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'), | 739 ('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'), |
740 ('git', 'repo_3', 'src/repo2/repo_renamed'), | 740 ('git', 'repo_3', 'src/repo2/repo_renamed'), |
741 ('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'), | 741 ('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'), |
742 ] | 742 ] |
743 expected = [(scm, bases[scm] + url, os.path.join(self.root_dir, path)) | 743 expected = [(scm, bases[scm] + url, os.path.join(self.root_dir, path)) |
744 for (scm, url, path) in expected_source] | 744 for (scm, url, path) in expected_source] |
745 | 745 |
746 self.assertEquals(sorted(entries), sorted(expected)) | 746 self.assertEquals(sorted(entries), sorted(expected)) |
747 | 747 |
748 | 748 |
| 749 class GClientSmokeFromCheckout(GClientSmokeBase): |
| 750 # WebKit abuses this. It has a .gclient and a DEPS from a checkout. |
| 751 def setUp(self): |
| 752 GClientSmokeBase.setUp(self) |
| 753 self.FAKE_REPOS.setUpSVN() |
| 754 os.rmdir(self.root_dir) |
| 755 check_call(['svn', 'checkout', 'svn://127.0.0.1/svn/trunk/webkit', |
| 756 self.root_dir, '-q', |
| 757 '--non-interactive', '--no-auth-cache', |
| 758 '--username', 'user1', '--password', 'foo']) |
| 759 |
| 760 def testSync(self): |
| 761 self.parseGclient(['sync', '--deps', 'mac'], ['running', 'running']) |
| 762 tree = self.mangle_svn_tree( |
| 763 ('trunk/webkit@2', ''), |
| 764 ('trunk/third_party/foo@1', 'foo/bar')) |
| 765 self.assertTree(tree) |
| 766 |
| 767 def testRevertAndStatus(self): |
| 768 self.gclient(['sync']) |
| 769 |
| 770 # TODO(maruel): This is incorrect. |
| 771 out = self.parseGclient(['status', '--deps', 'mac'], []) |
| 772 |
| 773 # Revert implies --force implies running hooks without looking at pattern |
| 774 # matching. |
| 775 results = self.gclient(['revert', '--deps', 'mac']) |
| 776 out = self.splitBlock(results[0]) |
| 777 self.assertEquals(2, len(out)) |
| 778 self.checkString(2, len(out[0])) |
| 779 self.checkString(2, len(out[1])) |
| 780 self.checkString('foo', out[1][1]) |
| 781 self.checkString('', results[1]) |
| 782 self.assertEquals(0, results[2]) |
| 783 tree = self.mangle_svn_tree( |
| 784 ('trunk/webkit@2', ''), |
| 785 ('trunk/third_party/foo@1', 'foo/bar')) |
| 786 self.assertTree(tree) |
| 787 |
| 788 # TODO(maruel): This is incorrect. |
| 789 out = self.parseGclient(['status', '--deps', 'mac'], []) |
| 790 |
| 791 def testRunHooks(self): |
| 792 # Hooks aren't really tested for now since there is no hook defined. |
| 793 self.gclient(['sync', '--deps', 'mac']) |
| 794 out = self.parseGclient(['runhooks', '--deps', 'mac'], ['running']) |
| 795 self.assertEquals(1, len(out)) |
| 796 self.assertEquals(2, len(out[0])) |
| 797 self.assertEquals(3, len(out[0][0])) |
| 798 self.checkString('foo', out[0][1]) |
| 799 tree = self.mangle_svn_tree( |
| 800 ('trunk/webkit@2', ''), |
| 801 ('trunk/third_party/foo@1', 'foo/bar')) |
| 802 self.assertTree(tree) |
| 803 |
| 804 def testRevInfo(self): |
| 805 self.gclient(['sync', '--deps', 'mac']) |
| 806 results = self.gclient(['revinfo', '--deps', 'mac']) |
| 807 expected = ( |
| 808 './: None;\nfoo/bar: svn://127.0.0.1/svn/trunk/third_party/foo@1\n', |
| 809 '', 0) |
| 810 self.check(expected, results) |
| 811 # TODO(maruel): To be added after the refactor. |
| 812 #results = self.gclient(['revinfo', '--snapshot']) |
| 813 #expected = ( |
| 814 # './: None;\nfoo/bar: svn://127.0.0.1/svn/trunk/third_party/foo@1\n', |
| 815 # '', 0) |
| 816 #self.check(expected, results) |
| 817 |
| 818 def testRest(self): |
| 819 self.gclient(['sync']) |
| 820 # TODO(maruel): This is incorrect, it should run on ./ too. |
| 821 out = self.parseGclient(['cleanup', '--deps', 'mac'], |
| 822 [('running', join(self.root_dir, 'foo', 'bar'))]) |
| 823 out = self.parseGclient(['diff', '--deps', 'mac'], |
| 824 [('running', join(self.root_dir, 'foo', 'bar'))]) |
| 825 |
| 826 |
749 if __name__ == '__main__': | 827 if __name__ == '__main__': |
750 if '-c' in sys.argv: | 828 if '-c' in sys.argv: |
751 COVERAGE = True | 829 COVERAGE = True |
752 sys.argv.remove('-c') | 830 sys.argv.remove('-c') |
753 if os.path.exists('.coverage'): | 831 if os.path.exists('.coverage'): |
754 os.remove('.coverage') | 832 os.remove('.coverage') |
755 os.environ['COVERAGE_FILE'] = os.path.join( | 833 os.environ['COVERAGE_FILE'] = os.path.join( |
756 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | 834 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), |
757 '.coverage') | 835 '.coverage') |
758 unittest.main() | 836 unittest.main() |
OLD | NEW |