Commit 5fc2a33a authored by maruel@chromium.org's avatar maruel@chromium.org

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
parent 5ca2769d
...@@ -834,9 +834,10 @@ URL. ...@@ -834,9 +834,10 @@ URL.
parser.add_option("--name", parser.add_option("--name",
help="overrides the default name for the solution") help="overrides the default name for the solution")
(options, args) = parser.parse_args(args) (options, args) = parser.parse_args(args)
if len(args) < 1 and not options.spec: if ((options.spec and args) or len(args) > 2 or
raise gclient_utils.Error("required argument missing; see 'gclient help " (not options.spec and not args)):
"config'") parser.error('Inconsistent arguments. Use either --spec or one or 2 args')
if os.path.exists(options.config_filename): if os.path.exists(options.config_filename):
raise gclient_utils.Error("%s file already exists in the current directory" raise gclient_utils.Error("%s file already exists in the current directory"
% options.config_filename) % options.config_filename)
......
...@@ -89,8 +89,9 @@ def commit_svn(repo): ...@@ -89,8 +89,9 @@ def commit_svn(repo):
def commit_git(repo): def commit_git(repo):
"""Commits the changes and returns the new hash.""" """Commits the changes and returns the new hash."""
check_call(['git', 'add', '-A', '-f'], cwd=repo) check_call(['git', 'add', '-A', '-f'], cwd=repo)
out = Popen(['git', 'commit', '-m', 'foo'], cwd=repo).communicate()[0] check_call(['git', 'commit', '-q', '--message', 'foo'], cwd=repo)
rev = re.search(r'^\[.*? ([a-f\d]+)\] ', out).group(1) rev = Popen(['git', 'show-ref', '--head', 'HEAD'],
cwd=repo).communicate()[0].split(' ', 1)[0]
logging.debug('At revision %s' % rev) logging.debug('At revision %s' % rev)
return rev return rev
......
...@@ -134,13 +134,19 @@ class GClientSmokeBase(unittest.TestCase): ...@@ -134,13 +134,19 @@ class GClientSmokeBase(unittest.TestCase):
class GClientSmoke(GClientSmokeBase): class GClientSmoke(GClientSmokeBase):
def testCommands(self): def testHelp(self):
"""This test is to make sure no new command was added.""" """testHelp: make sure no new command was added."""
result = self.gclient(['help']) result = self.gclient(['help'])
self.assertEquals(1197, len(result[0])) self.assertEquals(1197, len(result[0]))
self.assertEquals(0, len(result[1])) self.assertEquals(0, len(result[1]))
self.assertEquals(0, result[2]) 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): def testNotConfigured(self):
res = ('', 'Error: client not configured; see \'gclient config\'\n', 1) res = ('', 'Error: client not configured; see \'gclient config\'\n', 1)
self.check(res, self.gclient(['cleanup'])) self.check(res, self.gclient(['cleanup']))
...@@ -154,10 +160,57 @@ class GClientSmoke(GClientSmokeBase): ...@@ -154,10 +160,57 @@ class GClientSmoke(GClientSmokeBase):
self.check(res, self.gclient(['sync'])) self.check(res, self.gclient(['sync']))
self.check(res, self.gclient(['update'])) 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): class GClientSmokeSVN(GClientSmokeBase):
"""sync is the most important command. Hence test it more."""
def testSync(self): def testSync(self):
# TODO(maruel): safesync, multiple solutions, invalid@revisions,
# multiple revisions.
self.gclient(['config', self.svn_base + 'trunk/src/']) self.gclient(['config', self.svn_base + 'trunk/src/'])
# Test unversioned checkout. # Test unversioned checkout.
results = self.gclient(['sync', '--deps', 'mac']) results = self.gclient(['sync', '--deps', 'mac'])
...@@ -284,6 +337,24 @@ class GClientSmokeSVN(GClientSmokeBase): ...@@ -284,6 +337,24 @@ class GClientSmokeSVN(GClientSmokeBase):
self.checkString('', results[1]) self.checkString('', results[1])
self.assertEquals(0, results[2]) 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): def testRunHooksDepsOs(self):
self.gclient(['config', self.svn_base + 'trunk/src/']) self.gclient(['config', self.svn_base + 'trunk/src/'])
self.gclient(['sync', '--deps', 'mac', '--revision', 'src@1']) self.gclient(['sync', '--deps', 'mac', '--revision', 'src@1'])
...@@ -304,6 +375,8 @@ class GClientSmokeSVN(GClientSmokeBase): ...@@ -304,6 +375,8 @@ class GClientSmokeSVN(GClientSmokeBase):
class GClientSmokeGIT(GClientSmokeBase): class GClientSmokeGIT(GClientSmokeBase):
def testSync(self): def testSync(self):
# TODO(maruel): safesync, multiple solutions, invalid@revisions,
# multiple revisions.
self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
# Test unversioned checkout. # Test unversioned checkout.
results = self.gclient(['sync', '--deps', 'mac']) results = self.gclient(['sync', '--deps', 'mac'])
...@@ -417,6 +490,22 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -417,6 +490,22 @@ class GClientSmokeGIT(GClientSmokeBase):
self.checkString('', results[1]) self.checkString('', results[1])
self.assertEquals(0, results[2]) 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 __name__ == '__main__':
if '-v' in sys.argv: if '-v' in sys.argv:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment