From 5fc2a33a78f60d1bfdd6f904a8aba28eb4fe0f69 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Wed, 26 May 2010 19:37:15 +0000 Subject: [PATCH] Add more smoke test for gclient config and gclient revinfo. BUG=23328 Review URL: http://codereview.chromium.org/2285003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@48311 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 7 +-- tests/fake_repos.py | 5 +- tests/gclient_smoketest.py | 95 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 99 insertions(+), 8 deletions(-) diff --git a/gclient.py b/gclient.py index 80b524bc0..926b1785c 100644 --- a/gclient.py +++ b/gclient.py @@ -834,9 +834,10 @@ URL. parser.add_option("--name", help="overrides the default name for the solution") (options, args) = parser.parse_args(args) - if len(args) < 1 and not options.spec: - raise gclient_utils.Error("required argument missing; see 'gclient help " - "config'") + if ((options.spec and args) or len(args) > 2 or + (not options.spec and not args)): + parser.error('Inconsistent arguments. Use either --spec or one or 2 args') + if os.path.exists(options.config_filename): raise gclient_utils.Error("%s file already exists in the current directory" % options.config_filename) diff --git a/tests/fake_repos.py b/tests/fake_repos.py index e55b776b2..85746cf3a 100755 --- a/tests/fake_repos.py +++ b/tests/fake_repos.py @@ -89,8 +89,9 @@ def commit_svn(repo): def commit_git(repo): """Commits the changes and returns the new hash.""" check_call(['git', 'add', '-A', '-f'], cwd=repo) - out = Popen(['git', 'commit', '-m', 'foo'], cwd=repo).communicate()[0] - rev = re.search(r'^\[.*? ([a-f\d]+)\] ', out).group(1) + check_call(['git', 'commit', '-q', '--message', 'foo'], cwd=repo) + rev = Popen(['git', 'show-ref', '--head', 'HEAD'], + cwd=repo).communicate()[0].split(' ', 1)[0] logging.debug('At revision %s' % rev) return rev diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 4433a5e6f..b0b74a5ea 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -134,13 +134,19 @@ class GClientSmokeBase(unittest.TestCase): class GClientSmoke(GClientSmokeBase): - def testCommands(self): - """This test is to make sure no new command was added.""" + def testHelp(self): + """testHelp: make sure no new command was added.""" result = self.gclient(['help']) self.assertEquals(1197, len(result[0])) self.assertEquals(0, len(result[1])) self.assertEquals(0, result[2]) + def testUnknown(self): + result = self.gclient(['foo']) + self.assertEquals(1197, len(result[0])) + self.assertEquals(0, len(result[1])) + self.assertEquals(0, result[2]) + def testNotConfigured(self): res = ('', 'Error: client not configured; see \'gclient config\'\n', 1) self.check(res, self.gclient(['cleanup'])) @@ -154,10 +160,57 @@ class GClientSmoke(GClientSmokeBase): self.check(res, self.gclient(['sync'])) self.check(res, self.gclient(['update'])) + def testConfig(self): + p = join(self.root_dir, '.gclient') + def test(cmd, expected): + if os.path.exists(p): + os.remove(p) + results = self.gclient(cmd) + self.check(('', '', 0), results) + self.checkString(expected, open(p, 'rb').read()) + + test(['config', self.svn_base + 'trunk/src/'], + 'solutions = [\n' + ' { "name" : "src",\n' + ' "url" : "svn://127.0.0.1/svn/trunk/src",\n' + ' "custom_deps" : {\n' + ' },\n' + ' "safesync_url": ""\n' + ' },\n]\n') + + test(['config', self.git_base + 'repo_1', '--name', 'src'], + 'solutions = [\n' + ' { "name" : "src",\n' + ' "url" : "git://127.0.0.1/git/repo_1",\n' + ' "custom_deps" : {\n' + ' },\n' + ' "safesync_url": ""\n' + ' },\n]\n') + + test(['config', 'foo', 'faa'], + 'solutions = [\n' + ' { "name" : "foo",\n' + ' "url" : "foo",\n' + ' "custom_deps" : {\n' + ' },\n' + ' "safesync_url": "faa"\n' + ' },\n]\n') + + test(['config', '--spec', '["blah blah"]'], '["blah blah"]') + + os.remove(p) + results = self.gclient(['config', 'foo', 'faa', 'fuu']) + err = ('Usage: gclient.py config [options] [url] [safesync url]\n\n' + 'gclient.py: error: Inconsistent arguments. Use either --spec or one' + ' or 2 args\n') + self.check(('', err, 2), results) + self.assertFalse(os.path.exists(join(self.root_dir, '.gclient'))) + class GClientSmokeSVN(GClientSmokeBase): - """sync is the most important command. Hence test it more.""" def testSync(self): + # TODO(maruel): safesync, multiple solutions, invalid@revisions, + # multiple revisions. self.gclient(['config', self.svn_base + 'trunk/src/']) # Test unversioned checkout. results = self.gclient(['sync', '--deps', 'mac']) @@ -284,6 +337,24 @@ class GClientSmokeSVN(GClientSmokeBase): self.checkString('', results[1]) self.assertEquals(0, results[2]) + def testRunHooks(self): + self.gclient(['config', self.svn_base + 'trunk/src/']) + self.gclient(['sync', '--deps', 'mac']) + results = self.gclient(['runhooks']) + out = results[0].splitlines(False) + self.assertEquals(4, len(out)) + self.assertEquals(out[0], '') + self.assertTrue(re.match(r'^________ running \'.*?python -c ' + r'open\(\'src/hooked1\', \'w\'\)\.write\(\'hooked1\'\)\' in \'.*', + out[1])) + self.assertEquals(out[2], '') + # runhooks runs all hooks even if not matching by design. + self.assertTrue(re.match(r'^________ running \'.*?python -c ' + r'open\(\'src/hooked2\', \'w\'\)\.write\(\'hooked2\'\)\' in \'.*', + out[3])) + self.checkString('', results[1]) + self.assertEquals(0, results[2]) + def testRunHooksDepsOs(self): self.gclient(['config', self.svn_base + 'trunk/src/']) self.gclient(['sync', '--deps', 'mac', '--revision', 'src@1']) @@ -304,6 +375,8 @@ class GClientSmokeSVN(GClientSmokeBase): class GClientSmokeGIT(GClientSmokeBase): def testSync(self): + # TODO(maruel): safesync, multiple solutions, invalid@revisions, + # multiple revisions. self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) # Test unversioned checkout. results = self.gclient(['sync', '--deps', 'mac']) @@ -417,6 +490,22 @@ class GClientSmokeGIT(GClientSmokeBase): self.checkString('', results[1]) self.assertEquals(0, results[2]) + def testRevInfo(self): + # TODO(maruel): Test multiple solutions. + self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) + self.gclient(['sync', '--deps', 'mac']) + results = self.gclient(['revinfo']) + out = ('src: %(base)srepo_1@%(hash1)s;\n' + 'src/repo2: %(base)srepo_2@%(hash2)s;\n' + 'src/repo2/repo_renamed: %(base)srepo_3@%(hash3)s\n' % + { + 'base': self.git_base, + 'hash1': FAKE.git_hashes['repo_1'][1][0], + 'hash2': FAKE.git_hashes['repo_2'][0][0], + 'hash3': FAKE.git_hashes['repo_3'][1][0], + }) + self.check((out, '', 0), results) + if __name__ == '__main__': if '-v' in sys.argv: