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. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 if not match: | 102 if not match: |
103 match = re.match(r'^_____ (.*) is missing, synching instead$', line) | 103 match = re.match(r'^_____ (.*) is missing, synching instead$', line) |
104 if match: | 104 if match: |
105 # 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 |
106 # output this message. | 106 # output this message. |
107 results.append([line]) | 107 results.append([line]) |
108 elif ( | 108 elif ( |
109 not re.match( | 109 not re.match( |
110 r'_____ [^ ]+ : Attempting rebase onto [0-9a-f]+...', | 110 r'_____ [^ ]+ : Attempting rebase onto [0-9a-f]+...', |
111 line) and | 111 line) and |
112 not re.match(r'_____ [^ ]+ at [^ ]+', line) and not | 112 not re.match(r'_____ [^ ]+ at [^ ]+', line)): |
113 re.match( | 113 # The two regexp above are a bit too broad, they are necessary only |
114 r'_____ (.*) looks like a git-svn checkout. Skipping.', | 114 # for git checkouts. |
115 line)): | |
116 # The regexp above are a bit too broad. | |
117 self.fail(line) | 115 self.fail(line) |
118 else: | 116 else: |
119 results.append([[match.group(1), match.group(2), match.group(3)]]) | 117 results.append([[match.group(1), match.group(2), match.group(3)]]) |
120 else: | 118 else: |
121 if not results: | 119 if not results: |
122 # TODO(maruel): gclient's git stdout is inconsistent. | 120 # TODO(maruel): gclient's git stdout is inconsistent. |
123 # This should fail the test instead!! | 121 # This should fail the test instead!! |
124 pass | 122 pass |
125 else: | 123 else: |
126 results[-1].append(line) | 124 results[-1].append(line) |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 return | 769 return |
772 self.gclient(['config', self.svn_base + 'trunk/src/']) | 770 self.gclient(['config', self.svn_base + 'trunk/src/']) |
773 cmd = ['sync', '--jobs', '1', '--delete_unversioned_trees', '--reset'] | 771 cmd = ['sync', '--jobs', '1', '--delete_unversioned_trees', '--reset'] |
774 self.assertEquals(0, self.gclient(cmd)[-1]) | 772 self.assertEquals(0, self.gclient(cmd)[-1]) |
775 third_party = join(self.root_dir, 'src', 'third_party') | 773 third_party = join(self.root_dir, 'src', 'third_party') |
776 subprocess2.check_call(['svn', 'propset', '-q', 'svn:ignore', 'foo', '.'], | 774 subprocess2.check_call(['svn', 'propset', '-q', 'svn:ignore', 'foo', '.'], |
777 cwd=third_party) | 775 cwd=third_party) |
778 | 776 |
779 # Cripple src/third_party/foo and make sure gclient still succeeds. | 777 # Cripple src/third_party/foo and make sure gclient still succeeds. |
780 gclient_utils.rmtree(join(third_party, 'foo', '.svn')) | 778 gclient_utils.rmtree(join(third_party, 'foo', '.svn')) |
781 self.assertEquals(0, self.gclient(cmd + ['--force'])[-1]) | 779 self.assertEquals(0, self.gclient(cmd)[-1]) |
782 | |
783 def testSkipGitSvn(self): | |
784 # Check that gclient skips git-svn checkouts. | |
785 if not self.enabled: | |
786 return | |
787 | |
788 # Create the .gclient file. | |
789 svn_url = self.svn_base + 'trunk/src' | |
790 self.gclient(['config', svn_url], cwd=self.root_dir) | |
791 | |
792 # Create a git-svn checkout. | |
793 # Use check_output to hide the output from the subprocess. | |
794 subprocess2.check_output(['git', 'svn', 'clone', svn_url], | |
795 cwd=self.root_dir) | |
796 | |
797 # Ensure that gclient skips the git-svn checkout. | |
798 stdout, stderr, rc = self.gclient(['sync', '--jobs', '1']) | |
799 self.assertEquals(rc, 0) | |
800 self.assertFalse(stderr) | |
801 self.assertTrue('_____ src looks like a git-svn checkout. Skipping.' | |
802 in stdout) | |
803 self.checkBlock(stdout, [ | |
804 ['running', self.root_dir], | |
805 ['running', os.path.join(self.root_dir, 'src', 'file', 'other')], | |
806 ['running', self.root_dir], | |
807 ['running', self.root_dir], | |
808 ['running', self.root_dir], | |
809 ['running', self.root_dir], | |
810 ['running', self.root_dir], | |
811 ]) | |
812 | |
813 # But, we still need the DEPS to be checked out... | |
814 foo_dir = os.path.join(self.root_dir, 'src', 'third_party', 'foo') | |
815 foo_rev = subprocess2.check_output(['svnversion', foo_dir]).strip() | |
816 self.assertEquals(foo_rev, '1') | |
817 | |
818 other_dir = os.path.join(self.root_dir, 'src', 'other') | |
819 other_rev = subprocess2.check_output(['svnversion', other_dir]).strip() | |
820 self.assertEquals(other_rev, '2') | |
821 | |
822 # Verify that the DEPS are NOT skipped on a second update. | |
823 stdout, stderr, rc = self.gclient(['sync', '--jobs', '1']) | |
824 self.assertFalse(stderr) | |
825 self.assertTrue('_____ src looks like a git-svn checkout. Skipping.' | |
826 in stdout) | |
827 self.assertFalse( | |
828 '_____ src/other looks like a git-svn checkout. Skipping.' in stdout, | |
829 'Non git-svn checkout is incorrectly skipped.') | |
830 self.assertFalse( | |
831 '_____ src/third_party/foo looks like a git-svn checkout. Skipping.' | |
832 in stdout, | |
833 'Non git-svn checkout is incorrectly skipped.') | |
834 | 780 |
835 | 781 |
836 class GClientSmokeSVNTransitive(GClientSmokeBase): | 782 class GClientSmokeSVNTransitive(GClientSmokeBase): |
837 FAKE_REPOS_CLASS = FakeRepoTransitive | 783 FAKE_REPOS_CLASS = FakeRepoTransitive |
838 | 784 |
839 def setUp(self): | 785 def setUp(self): |
840 super(GClientSmokeSVNTransitive, self).setUp() | 786 super(GClientSmokeSVNTransitive, self).setUp() |
841 self.enabled = self.FAKE_REPOS.set_up_svn() | 787 self.enabled = self.FAKE_REPOS.set_up_svn() |
842 | 788 |
843 def testSyncTransitive(self): | 789 def testSyncTransitive(self): |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 | 1055 |
1110 # Pre-DEPS hooks don't run with runhooks. | 1056 # Pre-DEPS hooks don't run with runhooks. |
1111 self.gclient(['runhooks', '--deps', 'mac']) | 1057 self.gclient(['runhooks', '--deps', 'mac']) |
1112 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1058 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
1113 ('repo_1@2', 'src/repo1'), | 1059 ('repo_1@2', 'src/repo1'), |
1114 ('repo_2@1', 'src/repo2') | 1060 ('repo_2@1', 'src/repo2') |
1115 ) | 1061 ) |
1116 self.assertTree(tree) | 1062 self.assertTree(tree) |
1117 | 1063 |
1118 # Pre-DEPS hooks run when syncing with --nohooks. | 1064 # Pre-DEPS hooks run when syncing with --nohooks. |
1119 self.gclient(['sync', '--deps', 'mac', '--nohooks', '--force', | 1065 self.gclient(['sync', '--deps', 'mac', '--nohooks', |
1120 '--revision', 'src@' + self.githash('repo_5', 2)]) | 1066 '--revision', 'src@' + self.githash('repo_5', 2)]) |
1121 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1067 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
1122 ('repo_1@2', 'src/repo1'), | 1068 ('repo_1@2', 'src/repo1'), |
1123 ('repo_2@1', 'src/repo2') | 1069 ('repo_2@1', 'src/repo2') |
1124 ) | 1070 ) |
1125 tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked' | 1071 tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked' |
1126 self.assertTree(tree) | 1072 self.assertTree(tree) |
1127 | 1073 |
1128 os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked')) | 1074 os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked')) |
1129 | 1075 |
1130 # Pre-DEPS hooks don't run with --noprehooks | 1076 # Pre-DEPS hooks don't run with --noprehooks |
1131 self.gclient(['sync', '--deps', 'mac', '--noprehooks', '--force', | 1077 self.gclient(['sync', '--deps', 'mac', '--noprehooks', |
1132 '--revision', 'src@' + self.githash('repo_5', 2)]) | 1078 '--revision', 'src@' + self.githash('repo_5', 2)]) |
1133 tree = self.mangle_git_tree(('repo_5@2', 'src'), | 1079 tree = self.mangle_git_tree(('repo_5@2', 'src'), |
1134 ('repo_1@2', 'src/repo1'), | 1080 ('repo_1@2', 'src/repo1'), |
1135 ('repo_2@1', 'src/repo2') | 1081 ('repo_2@1', 'src/repo2') |
1136 ) | 1082 ) |
1137 self.assertTree(tree) | 1083 self.assertTree(tree) |
1138 | 1084 |
1139 def testPreDepsHooksError(self): | 1085 def testPreDepsHooksError(self): |
1140 if not self.enabled: | 1086 if not self.enabled: |
1141 return | 1087 return |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 ('svn', 'trunk/other', 'src/other'), | 1389 ('svn', 'trunk/other', 'src/other'), |
1444 ('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'), | 1390 ('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'), |
1445 ('git', 'repo_3', 'src/repo2/repo_renamed'), | 1391 ('git', 'repo_3', 'src/repo2/repo_renamed'), |
1446 ('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'), | 1392 ('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'), |
1447 ] | 1393 ] |
1448 expected = [(scm, bases[scm] + url, os.path.join(self.root_dir, path)) | 1394 expected = [(scm, bases[scm] + url, os.path.join(self.root_dir, path)) |
1449 for (scm, url, path) in expected_source] | 1395 for (scm, url, path) in expected_source] |
1450 | 1396 |
1451 self.assertEquals(sorted(entries), sorted(expected)) | 1397 self.assertEquals(sorted(entries), sorted(expected)) |
1452 | 1398 |
1453 if gclient_utils.enable_deletion_of_conflicting_checkouts(): | |
1454 def testDeleteConflictingCheckout(self): | |
1455 if not self.enabled: | |
1456 return | |
1457 | |
1458 # Create an initial svn checkout. | |
1459 self.gclient(['config', '--spec', | |
1460 'solutions=[' | |
1461 '{"name": "src",' | |
1462 ' "url": "' + self.svn_base + 'trunk/src"},' | |
1463 ']' | |
1464 ]) | |
1465 results = self.gclient(['sync', '--deps', 'mac']) | |
1466 self.assertEqual(results[2], 0, 'Sync failed!') | |
1467 | |
1468 # Verify that we have the expected svn checkout. | |
1469 results = self.gclient(['revinfo', '--deps', 'mac']) | |
1470 actual = results[0].splitlines() | |
1471 expected = [ | |
1472 'src: %strunk/src' % self.svn_base, | |
1473 'src/file/other: File("%strunk/other/DEPS")' % self.svn_base, | |
1474 'src/other: %strunk/other' % self.svn_base, | |
1475 'src/third_party/foo: %strunk/third_party/foo@1' % self.svn_base, | |
1476 ] | |
1477 self.assertEquals(actual, expected) | |
1478 | |
1479 # Change the desired checkout to git. | |
1480 self.gclient(['config', '--spec', | |
1481 'solutions=[' | |
1482 '{"name": "src",' | |
1483 ' "url": "' + self.git_base + 'repo_1"},' | |
1484 ']' | |
1485 ]) | |
1486 | |
1487 # Verify that the sync succeeds with --force. | |
1488 results = self.gclient(['sync', '--deps', 'mac', '--force']) | |
1489 self.assertEqual(results[2], 0, 'Sync failed!') | |
1490 | |
1491 # Verify that we got the desired git checkout. | |
1492 results = self.gclient(['revinfo', '--deps', 'mac']) | |
1493 actual = results[0].splitlines() | |
1494 expected = [ | |
1495 'src: %srepo_1' % self.git_base, | |
1496 'src/repo2: %srepo_2@%s' % (self.git_base, | |
1497 self.githash('repo_2', 1)[:7]), | |
1498 'src/repo2/repo_renamed: %srepo_3' % self.git_base, | |
1499 ] | |
1500 self.assertEquals(actual, expected) | |
1501 | |
1502 # Change the desired checkout back to svn. | |
1503 self.gclient(['config', '--spec', | |
1504 'solutions=[' | |
1505 '{"name": "src",' | |
1506 ' "url": "' + self.svn_base + 'trunk/src"},' | |
1507 ']' | |
1508 ]) | |
1509 | |
1510 # Verify that the sync succeeds. | |
1511 results = self.gclient(['sync', '--deps', 'mac', '--force']) | |
1512 self.assertEqual(results[2], 0, 'Sync failed!') | |
1513 | |
1514 # Verify that we have the expected svn checkout. | |
1515 results = self.gclient(['revinfo', '--deps', 'mac']) | |
1516 actual = results[0].splitlines() | |
1517 expected = [ | |
1518 'src: %strunk/src' % self.svn_base, | |
1519 'src/file/other: File("%strunk/other/DEPS")' % self.svn_base, | |
1520 'src/other: %strunk/other' % self.svn_base, | |
1521 'src/third_party/foo: %strunk/third_party/foo@1' % self.svn_base, | |
1522 ] | |
1523 self.assertEquals(actual, expected) | |
1524 | |
1525 | 1399 |
1526 class GClientSmokeFromCheckout(GClientSmokeBase): | 1400 class GClientSmokeFromCheckout(GClientSmokeBase): |
1527 # WebKit abuses this. It has a .gclient and a DEPS from a checkout. | 1401 # WebKit abuses this. It has a .gclient and a DEPS from a checkout. |
1528 def setUp(self): | 1402 def setUp(self): |
1529 super(GClientSmokeFromCheckout, self).setUp() | 1403 super(GClientSmokeFromCheckout, self).setUp() |
1530 self.enabled = self.FAKE_REPOS.set_up_svn() | 1404 self.enabled = self.FAKE_REPOS.set_up_svn() |
1531 os.rmdir(self.root_dir) | 1405 os.rmdir(self.root_dir) |
1532 if self.enabled: | 1406 if self.enabled: |
1533 usr, pwd = self.FAKE_REPOS.USERS[0] | 1407 usr, pwd = self.FAKE_REPOS.USERS[0] |
1534 subprocess2.check_call( | 1408 subprocess2.check_call( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 | 1497 |
1624 if '-c' in sys.argv: | 1498 if '-c' in sys.argv: |
1625 COVERAGE = True | 1499 COVERAGE = True |
1626 sys.argv.remove('-c') | 1500 sys.argv.remove('-c') |
1627 if os.path.exists('.coverage'): | 1501 if os.path.exists('.coverage'): |
1628 os.remove('.coverage') | 1502 os.remove('.coverage') |
1629 os.environ['COVERAGE_FILE'] = os.path.join( | 1503 os.environ['COVERAGE_FILE'] = os.path.join( |
1630 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | 1504 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), |
1631 '.coverage') | 1505 '.coverage') |
1632 unittest.main() | 1506 unittest.main() |
OLD | NEW |