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 """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 socket | |
17 import subprocess | 16 import subprocess |
18 import sys | 17 import sys |
19 import unittest | 18 import unittest |
20 | 19 |
21 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 20 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
22 sys.path.insert(0, ROOT_DIR) | 21 sys.path.insert(0, ROOT_DIR) |
23 | 22 |
24 from testing_support.fake_repos import join, write | 23 from testing_support.fake_repos import join, write |
25 from testing_support.fake_repos import FakeReposTestBase, FakeRepoTransitive | 24 from testing_support.fake_repos import FakeReposTestBase, FakeRepoTransitive |
26 | 25 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if not match: | 102 if not match: |
104 match = re.match(r'^_____ (.*) is missing, synching instead$', line) | 103 match = re.match(r'^_____ (.*) is missing, synching instead$', line) |
105 if match: | 104 if match: |
106 # Blah, it's when a dependency is deleted, we should probably not | 105 # Blah, it's when a dependency is deleted, we should probably not |
107 # output this message. | 106 # output this message. |
108 results.append([line]) | 107 results.append([line]) |
109 elif ( | 108 elif ( |
110 not re.match( | 109 not re.match( |
111 r'_____ [^ ]+ : Attempting rebase onto [0-9a-f]+...', | 110 r'_____ [^ ]+ : Attempting rebase onto [0-9a-f]+...', |
112 line) and | 111 line) and |
113 not re.match(r'_____ [^ ]+ at [^ ]+', line) and not | 112 not re.match(r'_____ [^ ]+ at [^ ]+', line)): |
114 re.match(r'________ (.*) looks like git-svn; skipping.', line)): | 113 # The two regexp above are a bit too broad, they are necessary only |
115 # The regexp above are a bit too broad. | 114 # for git checkouts. |
116 self.fail(line) | 115 self.fail(line) |
117 else: | 116 else: |
118 results.append([[match.group(1), match.group(2), match.group(3)]]) | 117 results.append([[match.group(1), match.group(2), match.group(3)]]) |
119 else: | 118 else: |
120 if not results: | 119 if not results: |
121 # TODO(maruel): gclient's git stdout is inconsistent. | 120 # TODO(maruel): gclient's git stdout is inconsistent. |
122 # This should fail the test instead!! | 121 # This should fail the test instead!! |
123 pass | 122 pass |
124 else: | 123 else: |
125 results[-1].append(line) | 124 results[-1].append(line) |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 return | 769 return |
771 self.gclient(['config', self.svn_base + 'trunk/src/']) | 770 self.gclient(['config', self.svn_base + 'trunk/src/']) |
772 cmd = ['sync', '--jobs', '1', '--delete_unversioned_trees', '--reset'] | 771 cmd = ['sync', '--jobs', '1', '--delete_unversioned_trees', '--reset'] |
773 self.assertEquals(0, self.gclient(cmd)[-1]) | 772 self.assertEquals(0, self.gclient(cmd)[-1]) |
774 third_party = join(self.root_dir, 'src', 'third_party') | 773 third_party = join(self.root_dir, 'src', 'third_party') |
775 subprocess2.check_call(['svn', 'propset', '-q', 'svn:ignore', 'foo', '.'], | 774 subprocess2.check_call(['svn', 'propset', '-q', 'svn:ignore', 'foo', '.'], |
776 cwd=third_party) | 775 cwd=third_party) |
777 | 776 |
778 # Cripple src/third_party/foo and make sure gclient still succeeds. | 777 # Cripple src/third_party/foo and make sure gclient still succeeds. |
779 gclient_utils.rmtree(join(third_party, 'foo', '.svn')) | 778 gclient_utils.rmtree(join(third_party, 'foo', '.svn')) |
780 self.assertEquals(0, self.gclient(cmd + ['--force'])[-1]) | 779 self.assertEquals(0, self.gclient(cmd)[-1]) |
781 | |
782 def testSkipGitSvn(self): | |
783 # Check that gclient skips git-svn checkouts. | |
784 if not self.enabled: | |
785 return | |
786 | |
787 # Create the .gclient file. | |
788 svn_url = self.svn_base + 'trunk/src' | |
789 self.gclient(['config', svn_url], cwd=self.root_dir) | |
790 | |
791 # Create a git-svn checkout. | |
792 subprocess2.check_call(['git', 'svn', 'clone', svn_url], cwd=self.root_dir) | |
793 | |
794 # Ensure that gclient skips the git-svn checkout. | |
795 stdout, stderr, rc = self.gclient(['sync', '--jobs', '1']) | |
796 self.assertEquals(rc, 0) | |
797 self.assertFalse(stderr) | |
798 self.assertTrue('________ src looks like git-svn; skipping.' in stdout) | |
799 self.checkBlock(stdout, [ | |
800 ['running', self.root_dir], | |
801 ['running', os.path.join(self.root_dir, 'src', 'file', 'other')], | |
802 ['running', self.root_dir], | |
803 ['running', self.root_dir], | |
804 ['running', self.root_dir], | |
805 ['running', self.root_dir], | |
806 ]) | |
807 | |
808 # But, we still need the DEPS to be checked out... | |
809 foo_dir = os.path.join(self.root_dir, 'src', 'third_party', 'foo') | |
810 foo_rev = subprocess2.check_output(['svnversion', foo_dir]).strip() | |
811 self.assertEquals(foo_rev, '1') | |
812 | |
813 other_dir = os.path.join(self.root_dir, 'src', 'other') | |
814 other_rev = subprocess2.check_output(['svnversion', other_dir]).strip() | |
815 self.assertEquals(other_rev, '2') | |
816 | 780 |
817 | 781 |
818 class GClientSmokeSVNTransitive(GClientSmokeBase): | 782 class GClientSmokeSVNTransitive(GClientSmokeBase): |
819 FAKE_REPOS_CLASS = FakeRepoTransitive | 783 FAKE_REPOS_CLASS = FakeRepoTransitive |
820 | 784 |
821 def setUp(self): | 785 def setUp(self): |
822 super(GClientSmokeSVNTransitive, self).setUp() | 786 super(GClientSmokeSVNTransitive, self).setUp() |
823 self.enabled = self.FAKE_REPOS.set_up_svn() | 787 self.enabled = self.FAKE_REPOS.set_up_svn() |
824 | 788 |
825 def testSyncTransitive(self): | 789 def testSyncTransitive(self): |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 | 1096 |
1133 # Pre-DEPS hooks don't run with runhooks. | 1097 # Pre-DEPS hooks don't run with runhooks. |
1134 self.gclient(['runhooks', '--deps', 'mac']) | 1098 self.gclient(['runhooks', '--deps', 'mac']) |
1135 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1099 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
1136 ('repo_1@2', 'src/repo1'), | 1100 ('repo_1@2', 'src/repo1'), |
1137 ('repo_2@1', 'src/repo2') | 1101 ('repo_2@1', 'src/repo2') |
1138 ) | 1102 ) |
1139 self.assertTree(tree) | 1103 self.assertTree(tree) |
1140 | 1104 |
1141 # Pre-DEPS hooks run when syncing with --nohooks. | 1105 # Pre-DEPS hooks run when syncing with --nohooks. |
1142 self.gclient(['sync', '--deps', 'mac', '--nohooks', '--force', | 1106 self.gclient(['sync', '--deps', 'mac', '--nohooks', |
1143 '--revision', 'src@' + self.githash('repo_5', 2)]) | 1107 '--revision', 'src@' + self.githash('repo_5', 2)]) |
1144 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1108 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
1145 ('repo_1@2', 'src/repo1'), | 1109 ('repo_1@2', 'src/repo1'), |
1146 ('repo_2@1', 'src/repo2') | 1110 ('repo_2@1', 'src/repo2') |
1147 ) | 1111 ) |
1148 tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked' | 1112 tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked' |
1149 self.assertTree(tree) | 1113 self.assertTree(tree) |
1150 | 1114 |
1151 os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked')) | 1115 os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked')) |
1152 | 1116 |
1153 # Pre-DEPS hooks don't run with --noprehooks | 1117 # Pre-DEPS hooks don't run with --noprehooks |
1154 self.gclient(['sync', '--deps', 'mac', '--noprehooks', '--force', | 1118 self.gclient(['sync', '--deps', 'mac', '--noprehooks', |
1155 '--revision', 'src@' + self.githash('repo_5', 2)]) | 1119 '--revision', 'src@' + self.githash('repo_5', 2)]) |
1156 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1120 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
1157 ('repo_1@2', 'src/repo1'), | 1121 ('repo_1@2', 'src/repo1'), |
1158 ('repo_2@1', 'src/repo2') | 1122 ('repo_2@1', 'src/repo2') |
1159 ) | 1123 ) |
1160 self.assertTree(tree) | 1124 self.assertTree(tree) |
1161 | 1125 |
1162 def testPreDepsHooksError(self): | 1126 def testPreDepsHooksError(self): |
1163 if not self.enabled: | 1127 if not self.enabled: |
1164 return | 1128 return |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 ('svn', 'trunk/other', 'src/other'), | 1336 ('svn', 'trunk/other', 'src/other'), |
1373 ('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'), | 1337 ('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'), |
1374 ('git', 'repo_3', 'src/repo2/repo_renamed'), | 1338 ('git', 'repo_3', 'src/repo2/repo_renamed'), |
1375 ('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'), | 1339 ('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'), |
1376 ] | 1340 ] |
1377 expected = [(scm, bases[scm] + url, os.path.join(self.root_dir, path)) | 1341 expected = [(scm, bases[scm] + url, os.path.join(self.root_dir, path)) |
1378 for (scm, url, path) in expected_source] | 1342 for (scm, url, path) in expected_source] |
1379 | 1343 |
1380 self.assertEquals(sorted(entries), sorted(expected)) | 1344 self.assertEquals(sorted(entries), sorted(expected)) |
1381 | 1345 |
1382 # TODO(borenet): Enable this at the same time that the guard is removed in | |
1383 # gclient. | |
1384 if (os.environ.get('CHROME_HEADLESS') and | |
1385 socket.gethostname() in ('vm859-m1', 'build1-m1', 'vm630-m1')): | |
1386 def testDeleteConflictingCheckout(self): | |
1387 if not self.enabled: | |
1388 return | |
1389 | |
1390 # Create an initial svn checkout. | |
1391 self.gclient(['config', '--spec', | |
1392 'solutions=[' | |
1393 '{"name": "src",' | |
1394 ' "url": "' + self.svn_base + 'trunk/src"},' | |
1395 ']' | |
1396 ]) | |
1397 results = self.gclient(['sync', '--deps', 'mac']) | |
1398 self.assertEqual(results[2], 0, 'Sync failed!') | |
1399 | |
1400 # Verify that we have the expected svn checkout. | |
1401 results = self.gclient(['revinfo', '--deps', 'mac']) | |
1402 actual = results[0].splitlines() | |
1403 expected = [ | |
1404 'src: %strunk/src' % self.svn_base, | |
1405 'src/file/other: File("%strunk/other/DEPS")' % self.svn_base, | |
1406 'src/other: %strunk/other' % self.svn_base, | |
1407 'src/third_party/foo: %strunk/third_party/foo@1' % self.svn_base, | |
1408 ] | |
1409 self.assertEquals(actual, expected) | |
1410 | |
1411 # Change the desired checkout to git. | |
1412 self.gclient(['config', '--spec', | |
1413 'solutions=[' | |
1414 '{"name": "src",' | |
1415 ' "url": "' + self.git_base + 'repo_1"},' | |
1416 ']' | |
1417 ]) | |
1418 | |
1419 # Verify that the sync succeeds with --force. | |
1420 results = self.gclient(['sync', '--deps', 'mac', '--force']) | |
1421 self.assertEqual(results[2], 0, 'Sync failed!') | |
1422 | |
1423 # Verify that we got the desired git checkout. | |
1424 results = self.gclient(['revinfo', '--deps', 'mac']) | |
1425 actual = results[0].splitlines() | |
1426 expected = [ | |
1427 'src: %srepo_1' % self.git_base, | |
1428 'src/repo2: %srepo_2@%s' % (self.git_base, | |
1429 self.githash('repo_2', 1)[:7]), | |
1430 'src/repo2/repo_renamed: %srepo_3' % self.git_base, | |
1431 ] | |
1432 self.assertEquals(actual, expected) | |
1433 | |
1434 # Change the desired checkout back to svn. | |
1435 self.gclient(['config', '--spec', | |
1436 'solutions=[' | |
1437 '{"name": "src",' | |
1438 ' "url": "' + self.svn_base + 'trunk/src"},' | |
1439 ']' | |
1440 ]) | |
1441 | |
1442 # Verify that the sync succeeds. | |
1443 results = self.gclient(['sync', '--deps', 'mac', '--force']) | |
1444 self.assertEqual(results[2], 0, 'Sync failed!') | |
1445 | |
1446 # Verify that we have the expected svn checkout. | |
1447 results = self.gclient(['revinfo', '--deps', 'mac']) | |
1448 actual = results[0].splitlines() | |
1449 expected = [ | |
1450 'src: %strunk/src' % self.svn_base, | |
1451 'src/file/other: File("%strunk/other/DEPS")' % self.svn_base, | |
1452 'src/other: %strunk/other' % self.svn_base, | |
1453 'src/third_party/foo: %strunk/third_party/foo@1' % self.svn_base, | |
1454 ] | |
1455 self.assertEquals(actual, expected) | |
1456 | |
1457 | 1346 |
1458 class GClientSmokeFromCheckout(GClientSmokeBase): | 1347 class GClientSmokeFromCheckout(GClientSmokeBase): |
1459 # WebKit abuses this. It has a .gclient and a DEPS from a checkout. | 1348 # WebKit abuses this. It has a .gclient and a DEPS from a checkout. |
1460 def setUp(self): | 1349 def setUp(self): |
1461 super(GClientSmokeFromCheckout, self).setUp() | 1350 super(GClientSmokeFromCheckout, self).setUp() |
1462 self.enabled = self.FAKE_REPOS.set_up_svn() | 1351 self.enabled = self.FAKE_REPOS.set_up_svn() |
1463 os.rmdir(self.root_dir) | 1352 os.rmdir(self.root_dir) |
1464 if self.enabled: | 1353 if self.enabled: |
1465 usr, pwd = self.FAKE_REPOS.USERS[0] | 1354 usr, pwd = self.FAKE_REPOS.USERS[0] |
1466 subprocess2.check_call( | 1355 subprocess2.check_call( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 | 1444 |
1556 if '-c' in sys.argv: | 1445 if '-c' in sys.argv: |
1557 COVERAGE = True | 1446 COVERAGE = True |
1558 sys.argv.remove('-c') | 1447 sys.argv.remove('-c') |
1559 if os.path.exists('.coverage'): | 1448 if os.path.exists('.coverage'): |
1560 os.remove('.coverage') | 1449 os.remove('.coverage') |
1561 os.environ['COVERAGE_FILE'] = os.path.join( | 1450 os.environ['COVERAGE_FILE'] = os.path.join( |
1562 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | 1451 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), |
1563 '.coverage') | 1452 '.coverage') |
1564 unittest.main() | 1453 unittest.main() |
OLD | NEW |