gclient_smoketest.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #!/usr/bin/env vpython3
  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
  4. # found in the LICENSE file.
  5. """Smoke tests for gclient.py.
  6. Shell out 'gclient' and run basic conformance tests.
  7. """
  8. import logging
  9. import os
  10. import sys
  11. import unittest
  12. import gclient_smoketest_base
  13. ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  14. sys.path.insert(0, ROOT_DIR)
  15. import subprocess2
  16. from testing_support.fake_repos import join, write
  17. # TODO: Should fix these warnings.
  18. # pylint: disable=line-too-long
  19. class GClientSmoke(gclient_smoketest_base.GClientSmokeBase):
  20. """Doesn't require git-daemon."""
  21. @property
  22. def git_base(self):
  23. return 'git://random.server/git/'
  24. def testNotConfigured(self):
  25. res = ('', 'Error: client not configured; see \'gclient config\'\n', 1)
  26. self.check(res, self.gclient(['diff'], error_ok=True))
  27. self.check(res, self.gclient(['pack'], error_ok=True))
  28. self.check(res, self.gclient(['revert'], error_ok=True))
  29. self.check(res, self.gclient(['revinfo'], error_ok=True))
  30. self.check(res, self.gclient(['runhooks'], error_ok=True))
  31. self.check(res, self.gclient(['status'], error_ok=True))
  32. self.check(res, self.gclient(['sync'], error_ok=True))
  33. self.check(res, self.gclient(['update'], error_ok=True))
  34. def testConfig(self):
  35. # Get any bootstrapping out of the way.
  36. results = self.gclient(['version'])
  37. p = join(self.root_dir, '.gclient')
  38. def test(cmd, expected):
  39. if os.path.exists(p):
  40. os.remove(p)
  41. results = self.gclient(cmd)
  42. self.check(('', '', 0), results)
  43. with open(p, 'r') as f:
  44. actual = {}
  45. exec(f.read(), {}, actual)
  46. self.assertEqual(expected, actual)
  47. test(
  48. ['config', self.git_base + 'src/'], {
  49. 'solutions': [{
  50. 'name': 'src',
  51. 'url': self.git_base + 'src',
  52. 'deps_file': 'DEPS',
  53. 'managed': True,
  54. 'custom_deps': {},
  55. 'custom_vars': {},
  56. }],
  57. })
  58. test(
  59. [
  60. 'config', self.git_base + 'repo_1', '--name', 'src',
  61. '--cache-dir', 'none'
  62. ], {
  63. 'solutions': [{
  64. 'name': 'src',
  65. 'url': self.git_base + 'repo_1',
  66. 'deps_file': 'DEPS',
  67. 'managed': True,
  68. 'custom_deps': {},
  69. 'custom_vars': {},
  70. }],
  71. 'cache_dir':
  72. None
  73. })
  74. test(
  75. [
  76. 'config', 'https://example.com/foo', 'faa', '--cache-dir',
  77. 'something'
  78. ], {
  79. 'solutions': [{
  80. 'name': 'foo',
  81. 'url': 'https://example.com/foo',
  82. 'deps_file': 'DEPS',
  83. 'managed': True,
  84. 'custom_deps': {},
  85. 'custom_vars': {},
  86. }],
  87. 'cache_dir':
  88. 'something'
  89. })
  90. test(
  91. ['config', 'https://example.com/foo', '--deps', 'blah'], {
  92. 'solutions': [{
  93. 'name': 'foo',
  94. 'url': 'https://example.com/foo',
  95. 'deps_file': 'blah',
  96. 'managed': True,
  97. 'custom_deps': {},
  98. 'custom_vars': {},
  99. }]
  100. })
  101. test(
  102. [
  103. 'config', self.git_base + 'src/', '--custom-var',
  104. 'bool_var=True', '--custom-var', 'str_var="abc"'
  105. ], {
  106. 'solutions': [{
  107. 'name': 'src',
  108. 'url': self.git_base + 'src',
  109. 'deps_file': 'DEPS',
  110. 'managed': True,
  111. 'custom_deps': {},
  112. 'custom_vars': {
  113. 'bool_var': True,
  114. 'str_var': 'abc',
  115. },
  116. }]
  117. })
  118. test(['config', '--spec', 'bah = ["blah blah"]'],
  119. {'bah': ["blah blah"]})
  120. os.remove(p)
  121. results = self.gclient(['config', 'foo', 'faa', 'fuu'], error_ok=True)
  122. err = (
  123. 'Usage: gclient.py config [options] [url]\n\n'
  124. 'gclient.py: error: Inconsistent arguments. Use either --spec or one'
  125. ' or 2 args\n')
  126. self.check(('', err, 2), results)
  127. self.assertFalse(os.path.exists(join(self.root_dir, '.gclient')))
  128. def testSolutionNone(self):
  129. results = self.gclient(
  130. ['config', '--spec', 'solutions=[{"name": "./", "url": None}]'])
  131. self.check(('', '', 0), results)
  132. results = self.gclient(['sync'])
  133. self.check(('', '', 0), results)
  134. self.assertTree({})
  135. results = self.gclient(['revinfo'])
  136. self.check(('./: None\n', '', 0), results)
  137. self.check(('', '', 0), self.gclient(['diff']))
  138. self.assertTree({})
  139. self.check(('', '', 0), self.gclient(['pack']))
  140. self.check(('', '', 0), self.gclient(['revert']))
  141. self.assertTree({})
  142. self.check(('', '', 0), self.gclient(['runhooks']))
  143. self.assertTree({})
  144. self.check(('', '', 0), self.gclient(['status']))
  145. def testDifferentTopLevelDirectory(self):
  146. # Check that even if the .gclient file does not mention the directory
  147. # src itself, but it is included via dependencies, the .gclient file is
  148. # used.
  149. self.gclient(['config', self.git_base + 'src.DEPS'])
  150. deps = join(self.root_dir, 'src.DEPS')
  151. os.mkdir(deps)
  152. subprocess2.check_output(['git', 'init'], cwd=deps)
  153. write(join(deps, 'DEPS'), 'deps = { "src": "%ssrc" }' % (self.git_base))
  154. subprocess2.check_output(['git', 'add', 'DEPS'], cwd=deps)
  155. subprocess2.check_output(['git', 'commit', '-a', '-m', 'DEPS file'],
  156. cwd=deps)
  157. src = join(self.root_dir, 'src')
  158. os.mkdir(src)
  159. subprocess2.check_output(['git', 'init'], cwd=src)
  160. res = self.gclient(['status', '--jobs', '1', '-v'], src)
  161. self.checkBlock(res[0], [('running', deps), ('running', src)])
  162. if __name__ == '__main__':
  163. if '-v' in sys.argv:
  164. logging.basicConfig(level=logging.DEBUG)
  165. unittest.main()