| 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 # Use check_output to hide the output from the subprocess. | |
| 793 subprocess2.check_output(['git', 'svn', 'clone', svn_url], | |
| 794 cwd=self.root_dir) | |
| 795 | |
| 796 # Ensure that gclient skips the git-svn checkout. | |
| 797 stdout, stderr, rc = self.gclient(['sync', '--jobs', '1']) | |
| 798 self.assertEquals(rc, 0) | |
| 799 self.assertFalse(stderr) | |
| 800 self.assertTrue('________ src looks like git-svn; skipping.' in stdout) | |
| 801 self.checkBlock(stdout, [ | |
| 802 ['running', self.root_dir], | |
| 803 ['running', os.path.join(self.root_dir, 'src', 'file', 'other')], | |
| 804 ['running', self.root_dir], | |
| 805 ['running', self.root_dir], | |
| 806 ['running', self.root_dir], | |
| 807 ['running', self.root_dir], | |
| 808 ['running', self.root_dir], | |
| 809 ]) | |
| 810 | |
| 811 # But, we still need the DEPS to be checked out... | |
| 812 foo_dir = os.path.join(self.root_dir, 'src', 'third_party', 'foo') | |
| 813 foo_rev = subprocess2.check_output(['svnversion', foo_dir]).strip() | |
| 814 self.assertEquals(foo_rev, '1') | |
| 815 | |
| 816 other_dir = os.path.join(self.root_dir, 'src', 'other') | |
| 817 other_rev = subprocess2.check_output(['svnversion', other_dir]).strip() | |
| 818 self.assertEquals(other_rev, '2') | |
| 819 | |
| 820 # Verify that the DEPS are NOT skipped on a second update. | |
| 821 stdout, stderr, rc = self.gclient(['sync', '--jobs', '1']) | |
| 822 self.assertFalse(stderr) | |
| 823 self.assertTrue('________ src looks like git-svn; skipping.' in stdout) | |
| 824 self.assertFalse( | |
| 825 '________ src/other looks like git-svn; skipping.' in stdout, | |
| 826 'Non git-svn checkout is incorrectly skipped.') | |
| 827 self.assertFalse( | |
| 828 '________ src/third_party/foo looks like git-svn; skipping.' in stdout, | |
| 829 'Non git-svn checkout is incorrectly skipped.') | |
| 830 | 780 |
| 831 | 781 |
| 832 class GClientSmokeSVNTransitive(GClientSmokeBase): | 782 class GClientSmokeSVNTransitive(GClientSmokeBase): |
| 833 FAKE_REPOS_CLASS = FakeRepoTransitive | 783 FAKE_REPOS_CLASS = FakeRepoTransitive |
| 834 | 784 |
| 835 def setUp(self): | 785 def setUp(self): |
| 836 super(GClientSmokeSVNTransitive, self).setUp() | 786 super(GClientSmokeSVNTransitive, self).setUp() |
| 837 self.enabled = self.FAKE_REPOS.set_up_svn() | 787 self.enabled = self.FAKE_REPOS.set_up_svn() |
| 838 | 788 |
| 839 def testSyncTransitive(self): | 789 def testSyncTransitive(self): |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 | 1096 |
| 1147 # Pre-DEPS hooks don't run with runhooks. | 1097 # Pre-DEPS hooks don't run with runhooks. |
| 1148 self.gclient(['runhooks', '--deps', 'mac']) | 1098 self.gclient(['runhooks', '--deps', 'mac']) |
| 1149 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1099 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
| 1150 ('repo_1@2', 'src/repo1'), | 1100 ('repo_1@2', 'src/repo1'), |
| 1151 ('repo_2@1', 'src/repo2') | 1101 ('repo_2@1', 'src/repo2') |
| 1152 ) | 1102 ) |
| 1153 self.assertTree(tree) | 1103 self.assertTree(tree) |
| 1154 | 1104 |
| 1155 # Pre-DEPS hooks run when syncing with --nohooks. | 1105 # Pre-DEPS hooks run when syncing with --nohooks. |
| 1156 self.gclient(['sync', '--deps', 'mac', '--nohooks', '--force', | 1106 self.gclient(['sync', '--deps', 'mac', '--nohooks', |
| 1157 '--revision', 'src@' + self.githash('repo_5', 2)]) | 1107 '--revision', 'src@' + self.githash('repo_5', 2)]) |
| 1158 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1108 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
| 1159 ('repo_1@2', 'src/repo1'), | 1109 ('repo_1@2', 'src/repo1'), |
| 1160 ('repo_2@1', 'src/repo2') | 1110 ('repo_2@1', 'src/repo2') |
| 1161 ) | 1111 ) |
| 1162 tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked' | 1112 tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked' |
| 1163 self.assertTree(tree) | 1113 self.assertTree(tree) |
| 1164 | 1114 |
| 1165 os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked')) | 1115 os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked')) |
| 1166 | 1116 |
| 1167 # Pre-DEPS hooks don't run with --noprehooks | 1117 # Pre-DEPS hooks don't run with --noprehooks |
| 1168 self.gclient(['sync', '--deps', 'mac', '--noprehooks', '--force', | 1118 self.gclient(['sync', '--deps', 'mac', '--noprehooks', |
| 1169 '--revision', 'src@' + self.githash('repo_5', 2)]) | 1119 '--revision', 'src@' + self.githash('repo_5', 2)]) |
| 1170 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1120 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
| 1171 ('repo_1@2', 'src/repo1'), | 1121 ('repo_1@2', 'src/repo1'), |
| 1172 ('repo_2@1', 'src/repo2') | 1122 ('repo_2@1', 'src/repo2') |
| 1173 ) | 1123 ) |
| 1174 self.assertTree(tree) | 1124 self.assertTree(tree) |
| 1175 | 1125 |
| 1176 def testPreDepsHooksError(self): | 1126 def testPreDepsHooksError(self): |
| 1177 if not self.enabled: | 1127 if not self.enabled: |
| 1178 return | 1128 return |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 ('svn', 'trunk/other', 'src/other'), | 1336 ('svn', 'trunk/other', 'src/other'), |
| 1387 ('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'), | 1337 ('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'), |
| 1388 ('git', 'repo_3', 'src/repo2/repo_renamed'), | 1338 ('git', 'repo_3', 'src/repo2/repo_renamed'), |
| 1389 ('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'), | 1339 ('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'), |
| 1390 ] | 1340 ] |
| 1391 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)) |
| 1392 for (scm, url, path) in expected_source] | 1342 for (scm, url, path) in expected_source] |
| 1393 | 1343 |
| 1394 self.assertEquals(sorted(entries), sorted(expected)) | 1344 self.assertEquals(sorted(entries), sorted(expected)) |
| 1395 | 1345 |
| 1396 # TODO(borenet): Enable this at the same time that the guard is removed in | |
| 1397 # gclient. | |
| 1398 if (os.environ.get('CHROME_HEADLESS') and | |
| 1399 socket.gethostname() in ('vm859-m1', 'build1-m1', 'vm630-m1')): | |
| 1400 def testDeleteConflictingCheckout(self): | |
| 1401 if not self.enabled: | |
| 1402 return | |
| 1403 | |
| 1404 # Create an initial svn checkout. | |
| 1405 self.gclient(['config', '--spec', | |
| 1406 'solutions=[' | |
| 1407 '{"name": "src",' | |
| 1408 ' "url": "' + self.svn_base + 'trunk/src"},' | |
| 1409 ']' | |
| 1410 ]) | |
| 1411 results = self.gclient(['sync', '--deps', 'mac']) | |
| 1412 self.assertEqual(results[2], 0, 'Sync failed!') | |
| 1413 | |
| 1414 # Verify that we have the expected svn checkout. | |
| 1415 results = self.gclient(['revinfo', '--deps', 'mac']) | |
| 1416 actual = results[0].splitlines() | |
| 1417 expected = [ | |
| 1418 'src: %strunk/src' % self.svn_base, | |
| 1419 'src/file/other: File("%strunk/other/DEPS")' % self.svn_base, | |
| 1420 'src/other: %strunk/other' % self.svn_base, | |
| 1421 'src/third_party/foo: %strunk/third_party/foo@1' % self.svn_base, | |
| 1422 ] | |
| 1423 self.assertEquals(actual, expected) | |
| 1424 | |
| 1425 # Change the desired checkout to git. | |
| 1426 self.gclient(['config', '--spec', | |
| 1427 'solutions=[' | |
| 1428 '{"name": "src",' | |
| 1429 ' "url": "' + self.git_base + 'repo_1"},' | |
| 1430 ']' | |
| 1431 ]) | |
| 1432 | |
| 1433 # Verify that the sync succeeds with --force. | |
| 1434 results = self.gclient(['sync', '--deps', 'mac', '--force']) | |
| 1435 self.assertEqual(results[2], 0, 'Sync failed!') | |
| 1436 | |
| 1437 # Verify that we got the desired git checkout. | |
| 1438 results = self.gclient(['revinfo', '--deps', 'mac']) | |
| 1439 actual = results[0].splitlines() | |
| 1440 expected = [ | |
| 1441 'src: %srepo_1' % self.git_base, | |
| 1442 'src/repo2: %srepo_2@%s' % (self.git_base, | |
| 1443 self.githash('repo_2', 1)[:7]), | |
| 1444 'src/repo2/repo_renamed: %srepo_3' % self.git_base, | |
| 1445 ] | |
| 1446 self.assertEquals(actual, expected) | |
| 1447 | |
| 1448 # Change the desired checkout back to svn. | |
| 1449 self.gclient(['config', '--spec', | |
| 1450 'solutions=[' | |
| 1451 '{"name": "src",' | |
| 1452 ' "url": "' + self.svn_base + 'trunk/src"},' | |
| 1453 ']' | |
| 1454 ]) | |
| 1455 | |
| 1456 # Verify that the sync succeeds. | |
| 1457 results = self.gclient(['sync', '--deps', 'mac', '--force']) | |
| 1458 self.assertEqual(results[2], 0, 'Sync failed!') | |
| 1459 | |
| 1460 # Verify that we have the expected svn checkout. | |
| 1461 results = self.gclient(['revinfo', '--deps', 'mac']) | |
| 1462 actual = results[0].splitlines() | |
| 1463 expected = [ | |
| 1464 'src: %strunk/src' % self.svn_base, | |
| 1465 'src/file/other: File("%strunk/other/DEPS")' % self.svn_base, | |
| 1466 'src/other: %strunk/other' % self.svn_base, | |
| 1467 'src/third_party/foo: %strunk/third_party/foo@1' % self.svn_base, | |
| 1468 ] | |
| 1469 self.assertEquals(actual, expected) | |
| 1470 | |
| 1471 | 1346 |
| 1472 class GClientSmokeFromCheckout(GClientSmokeBase): | 1347 class GClientSmokeFromCheckout(GClientSmokeBase): |
| 1473 # 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. |
| 1474 def setUp(self): | 1349 def setUp(self): |
| 1475 super(GClientSmokeFromCheckout, self).setUp() | 1350 super(GClientSmokeFromCheckout, self).setUp() |
| 1476 self.enabled = self.FAKE_REPOS.set_up_svn() | 1351 self.enabled = self.FAKE_REPOS.set_up_svn() |
| 1477 os.rmdir(self.root_dir) | 1352 os.rmdir(self.root_dir) |
| 1478 if self.enabled: | 1353 if self.enabled: |
| 1479 usr, pwd = self.FAKE_REPOS.USERS[0] | 1354 usr, pwd = self.FAKE_REPOS.USERS[0] |
| 1480 subprocess2.check_call( | 1355 subprocess2.check_call( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 | 1444 |
| 1570 if '-c' in sys.argv: | 1445 if '-c' in sys.argv: |
| 1571 COVERAGE = True | 1446 COVERAGE = True |
| 1572 sys.argv.remove('-c') | 1447 sys.argv.remove('-c') |
| 1573 if os.path.exists('.coverage'): | 1448 if os.path.exists('.coverage'): |
| 1574 os.remove('.coverage') | 1449 os.remove('.coverage') |
| 1575 os.environ['COVERAGE_FILE'] = os.path.join( | 1450 os.environ['COVERAGE_FILE'] = os.path.join( |
| 1576 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | 1451 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), |
| 1577 '.coverage') | 1452 '.coverage') |
| 1578 unittest.main() | 1453 unittest.main() |
| OLD | NEW |