Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: tests/gclient_smoketest.py

Issue 2285003: Add more smoke test for gclient config and gclient revinfo. (Closed)
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/fake_repos.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 actual = read_tree(self.root_dir) 127 actual = read_tree(self.root_dir)
128 diff = dict_diff(tree, actual) 128 diff = dict_diff(tree, actual)
129 if diff: 129 if diff:
130 logging.debug('Actual %s\n%s' % (self.root_dir, pprint.pformat(actual))) 130 logging.debug('Actual %s\n%s' % (self.root_dir, pprint.pformat(actual)))
131 logging.debug('Expected\n%s' % pprint.pformat(tree)) 131 logging.debug('Expected\n%s' % pprint.pformat(tree))
132 logging.debug('Diff\n%s' % pprint.pformat(diff)) 132 logging.debug('Diff\n%s' % pprint.pformat(diff))
133 self.assertEquals(tree, actual) 133 self.assertEquals(tree, actual)
134 134
135 135
136 class GClientSmoke(GClientSmokeBase): 136 class GClientSmoke(GClientSmokeBase):
137 def testCommands(self): 137 def testHelp(self):
138 """This test is to make sure no new command was added.""" 138 """testHelp: make sure no new command was added."""
139 result = self.gclient(['help']) 139 result = self.gclient(['help'])
140 self.assertEquals(1197, len(result[0])) 140 self.assertEquals(1197, len(result[0]))
141 self.assertEquals(0, len(result[1])) 141 self.assertEquals(0, len(result[1]))
142 self.assertEquals(0, result[2]) 142 self.assertEquals(0, result[2])
143 143
144 def testUnknown(self):
145 result = self.gclient(['foo'])
146 self.assertEquals(1197, len(result[0]))
147 self.assertEquals(0, len(result[1]))
148 self.assertEquals(0, result[2])
149
144 def testNotConfigured(self): 150 def testNotConfigured(self):
145 res = ('', 'Error: client not configured; see \'gclient config\'\n', 1) 151 res = ('', 'Error: client not configured; see \'gclient config\'\n', 1)
146 self.check(res, self.gclient(['cleanup'])) 152 self.check(res, self.gclient(['cleanup']))
147 self.check(res, self.gclient(['diff'])) 153 self.check(res, self.gclient(['diff']))
148 self.check(res, self.gclient(['export', 'foo'])) 154 self.check(res, self.gclient(['export', 'foo']))
149 self.check(res, self.gclient(['pack'])) 155 self.check(res, self.gclient(['pack']))
150 self.check(res, self.gclient(['revert'])) 156 self.check(res, self.gclient(['revert']))
151 self.check(res, self.gclient(['revinfo'])) 157 self.check(res, self.gclient(['revinfo']))
152 self.check(res, self.gclient(['runhooks'])) 158 self.check(res, self.gclient(['runhooks']))
153 self.check(res, self.gclient(['status'])) 159 self.check(res, self.gclient(['status']))
154 self.check(res, self.gclient(['sync'])) 160 self.check(res, self.gclient(['sync']))
155 self.check(res, self.gclient(['update'])) 161 self.check(res, self.gclient(['update']))
156 162
163 def testConfig(self):
164 p = join(self.root_dir, '.gclient')
165 def test(cmd, expected):
166 if os.path.exists(p):
167 os.remove(p)
168 results = self.gclient(cmd)
169 self.check(('', '', 0), results)
170 self.checkString(expected, open(p, 'rb').read())
171
172 test(['config', self.svn_base + 'trunk/src/'],
173 'solutions = [\n'
174 ' { "name" : "src",\n'
175 ' "url" : "svn://127.0.0.1/svn/trunk/src",\n'
176 ' "custom_deps" : {\n'
177 ' },\n'
178 ' "safesync_url": ""\n'
179 ' },\n]\n')
180
181 test(['config', self.git_base + 'repo_1', '--name', 'src'],
182 'solutions = [\n'
183 ' { "name" : "src",\n'
184 ' "url" : "git://127.0.0.1/git/repo_1",\n'
185 ' "custom_deps" : {\n'
186 ' },\n'
187 ' "safesync_url": ""\n'
188 ' },\n]\n')
189
190 test(['config', 'foo', 'faa'],
191 'solutions = [\n'
192 ' { "name" : "foo",\n'
193 ' "url" : "foo",\n'
194 ' "custom_deps" : {\n'
195 ' },\n'
196 ' "safesync_url": "faa"\n'
197 ' },\n]\n')
198
199 test(['config', '--spec', '["blah blah"]'], '["blah blah"]')
200
201 os.remove(p)
202 results = self.gclient(['config', 'foo', 'faa', 'fuu'])
203 err = ('Usage: gclient.py config [options] [url] [safesync url]\n\n'
204 'gclient.py: error: Inconsistent arguments. Use either --spec or one'
205 ' or 2 args\n')
206 self.check(('', err, 2), results)
207 self.assertFalse(os.path.exists(join(self.root_dir, '.gclient')))
208
157 209
158 class GClientSmokeSVN(GClientSmokeBase): 210 class GClientSmokeSVN(GClientSmokeBase):
159 """sync is the most important command. Hence test it more."""
160 def testSync(self): 211 def testSync(self):
212 # TODO(maruel): safesync, multiple solutions, invalid@revisions,
213 # multiple revisions.
161 self.gclient(['config', self.svn_base + 'trunk/src/']) 214 self.gclient(['config', self.svn_base + 'trunk/src/'])
162 # Test unversioned checkout. 215 # Test unversioned checkout.
163 results = self.gclient(['sync', '--deps', 'mac']) 216 results = self.gclient(['sync', '--deps', 'mac'])
164 logging.debug(results[0]) 217 logging.debug(results[0])
165 out = results[0].splitlines(False) 218 out = results[0].splitlines(False)
166 self.assertEquals(17, len(out)) 219 self.assertEquals(17, len(out))
167 self.checkString('', results[1]) 220 self.checkString('', results[1])
168 self.assertEquals(0, results[2]) 221 self.assertEquals(0, results[2])
169 tree = mangle_svn_tree( 222 tree = mangle_svn_tree(
170 (join('trunk', 'src'), 'src', FAKE.svn_revs[-1]), 223 (join('trunk', 'src'), 'src', FAKE.svn_revs[-1]),
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 results = self.gclient(['revinfo']) 350 results = self.gclient(['revinfo'])
298 out = ('src: %(base)s/src@2;\n' 351 out = ('src: %(base)s/src@2;\n'
299 'src/other: %(base)s/other@2;\n' 352 'src/other: %(base)s/other@2;\n'
300 'src/third_party/foo: %(base)s/third_party/foo@1\n' % 353 'src/third_party/foo: %(base)s/third_party/foo@1\n' %
301 { 'base': self.svn_base + 'trunk' }) 354 { 'base': self.svn_base + 'trunk' })
302 self.check((out, '', 0), results) 355 self.check((out, '', 0), results)
303 356
304 357
305 class GClientSmokeGIT(GClientSmokeBase): 358 class GClientSmokeGIT(GClientSmokeBase):
306 def testSync(self): 359 def testSync(self):
360 # TODO(maruel): safesync, multiple solutions, invalid@revisions,
361 # multiple revisions.
307 self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) 362 self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
308 # Test unversioned checkout. 363 # Test unversioned checkout.
309 results = self.gclient(['sync', '--deps', 'mac']) 364 results = self.gclient(['sync', '--deps', 'mac'])
310 out = results[0].splitlines(False) 365 out = results[0].splitlines(False)
311 # TODO(maruel): http://crosbug.com/3582 hooks run even if not matching, must 366 # TODO(maruel): http://crosbug.com/3582 hooks run even if not matching, must
312 # add sync parsing to get the list of updated files. 367 # add sync parsing to get the list of updated files.
313 self.assertEquals(13, len(out)) 368 self.assertEquals(13, len(out))
314 self.assertTrue(results[1].startswith('Switched to a new branch \'')) 369 self.assertTrue(results[1].startswith('Switched to a new branch \''))
315 self.assertEquals(0, results[2]) 370 self.assertEquals(0, results[2])
316 tree = mangle_git_tree( 371 tree = mangle_git_tree(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 r'open\(\'src/hooked1\', \'w\'\)\.write\(\'hooked1\'\)\' in \'.*', 465 r'open\(\'src/hooked1\', \'w\'\)\.write\(\'hooked1\'\)\' in \'.*',
411 out[1])) 466 out[1]))
412 self.assertEquals(out[2], '') 467 self.assertEquals(out[2], '')
413 # runhooks runs all hooks even if not matching by design. 468 # runhooks runs all hooks even if not matching by design.
414 self.assertTrue(re.match(r'^________ running \'.*?python -c ' 469 self.assertTrue(re.match(r'^________ running \'.*?python -c '
415 r'open\(\'src/hooked2\', \'w\'\)\.write\(\'hooked2\'\)\' in \'.*', 470 r'open\(\'src/hooked2\', \'w\'\)\.write\(\'hooked2\'\)\' in \'.*',
416 out[3])) 471 out[3]))
417 self.checkString('', results[1]) 472 self.checkString('', results[1])
418 self.assertEquals(0, results[2]) 473 self.assertEquals(0, results[2])
419 474
475 def testRevInfo(self):
476 # TODO(maruel): Test multiple solutions.
477 self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
478 self.gclient(['sync', '--deps', 'mac'])
479 results = self.gclient(['revinfo'])
480 out = ('src: %(base)srepo_1@%(hash1)s;\n'
481 'src/repo2: %(base)srepo_2@%(hash2)s;\n'
482 'src/repo2/repo_renamed: %(base)srepo_3@%(hash3)s\n' %
483 {
484 'base': self.git_base,
485 'hash1': FAKE.git_hashes['repo_1'][1][0],
486 'hash2': FAKE.git_hashes['repo_2'][0][0],
487 'hash3': FAKE.git_hashes['repo_3'][1][0],
488 })
489 self.check((out, '', 0), results)
490
420 491
421 if __name__ == '__main__': 492 if __name__ == '__main__':
422 if '-v' in sys.argv: 493 if '-v' in sys.argv:
423 logging.basicConfig(level=logging.DEBUG) 494 logging.basicConfig(level=logging.DEBUG)
424 if '-l' in sys.argv: 495 if '-l' in sys.argv:
425 SHOULD_LEAK = True 496 SHOULD_LEAK = True
426 sys.argv.remove('-l') 497 sys.argv.remove('-l')
427 FAKE = FakeRepos(TRIAL_DIR, SHOULD_LEAK, True) 498 FAKE = FakeRepos(TRIAL_DIR, SHOULD_LEAK, True)
428 try: 499 try:
429 FAKE.setUp() 500 FAKE.setUp()
430 unittest.main() 501 unittest.main()
431 finally: 502 finally:
432 FAKE.tearDown() 503 FAKE.tearDown()
OLDNEW
« no previous file with comments | « tests/fake_repos.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698