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

Side by Side Diff: tools/vim/tests/chromium.ycm_extra_conf_unittest.py

Issue 2039923002: Fix the .ycm_extra_conf.py and SublimeText documentation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « tools/vim/chromium.ycm_extra_conf.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/env python 1 #!/usr/bin/env python
2 2
3 # Copyright 2015 The Chromium Authors. All rights reserved. 3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Tests for chromium.ycm_extra_conf. 7 """Tests for chromium.ycm_extra_conf.
8 8
9 These tests should be getting picked up by the PRESUBMIT.py in /tools/vim. 9 These tests should be getting picked up by the PRESUBMIT.py in /tools/vim.
10 Currently the tests only run on Linux and require 'ninja' to be available on 10 Currently the tests only run on Linux and require 'ninja' to be available on
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 with open(copy_from, 'r') as source: 46 with open(copy_from, 'r') as source:
47 contents = source.read() 47 contents = source.read()
48 if format_with: 48 if format_with:
49 formatter = string.Formatter() 49 formatter = string.Formatter()
50 contents = formatter.vformat(contents, None, format_with) 50 contents = formatter.vformat(contents, None, format_with)
51 f.write(contents) 51 f.write(contents)
52 if make_executable: 52 if make_executable:
53 statinfo = os.stat(path) 53 statinfo = os.stat(path)
54 os.chmod(path, statinfo.st_mode | stat.S_IXUSR) 54 os.chmod(path, statinfo.st_mode | stat.S_IXUSR)
55 55
56 @unittest.skipIf(sys.platform.startswith('linux'),
57 'Tests are only valid on Linux.')
58 class Chromium_ycmExtraConfTest_NotOnLinux(unittest.TestCase):
59 def testAlwaysFailsIfNotRunningOnLinux(self):
60 self.fail('Changes to chromium.ycm_extra_conf.py currently need to be ' \
61 'uploaded from Linux since the tests only run on Linux.')
62
63 @unittest.skipUnless(sys.platform.startswith('linux'),
64 'Tests are only valid on Linux.')
65 class Chromium_ycmExtraConfTest(unittest.TestCase): 56 class Chromium_ycmExtraConfTest(unittest.TestCase):
66 57
67 def SetUpFakeChromeTreeBelowPath(self): 58 def SetUpFakeChromeTreeBelowPath(self):
68 """Create fake Chromium source tree under self.test_root. 59 """Create fake Chromium source tree under self.test_root.
69 60
70 The fake source tree has the following contents: 61 The fake source tree has the following contents:
71 62
72 <self.test_root> 63 <self.test_root>
73 | .gclient 64 | .gclient
74 | 65 |
(...skipping 22 matching lines...) Expand all
97 88
98 # Fake ninja build file. Applications of 'cxx' rule are tagged by which 89 # Fake ninja build file. Applications of 'cxx' rule are tagged by which
99 # source file was used as input so that the test can verify that the correct 90 # source file was used as input so that the test can verify that the correct
100 # build dependency was used. 91 # build dependency was used.
101 CreateFile(os.path.join(self.out_dir, 'build.ninja'), 92 CreateFile(os.path.join(self.out_dir, 'build.ninja'),
102 copy_from=os.path.join(self.test_data_path, 93 copy_from=os.path.join(self.test_data_path,
103 'fake_build_ninja.txt')) 94 'fake_build_ninja.txt'))
104 95
105 def NormalizeString(self, string): 96 def NormalizeString(self, string):
106 return string.replace(self.out_dir, '[OUT]').\ 97 return string.replace(self.out_dir, '[OUT]').\
107 replace(self.chrome_root, '[SRC]') 98 replace(self.chrome_root, '[SRC]').replace('\\', '/')
108 99
109 def NormalizeStringsInList(self, list_of_strings): 100 def NormalizeStringsInList(self, list_of_strings):
110 return [self.NormalizeString(s) for s in list_of_strings] 101 return [self.NormalizeString(s) for s in list_of_strings]
111 102
112 def setUp(self): 103 def setUp(self):
113 self.actual_chrome_root = os.path.normpath( 104 self.actual_chrome_root = os.path.normpath(
114 os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../..')) 105 os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../..'))
115 sys.path.append(os.path.join(self.actual_chrome_root, 'tools', 'vim')) 106 sys.path.append(os.path.join(self.actual_chrome_root, 'tools', 'vim'))
116 self.test_data_path = os.path.join(self.actual_chrome_root, 'tools', 'vim', 107 self.test_data_path = os.path.join(self.actual_chrome_root, 'tools', 'vim',
117 'tests', 'data') 108 'tests', 'data')
118 self.ycm_extra_conf = imp.load_source('ycm_extra_conf', 109 self.ycm_extra_conf = imp.load_source('ycm_extra_conf',
119 'chromium.ycm_extra_conf.py') 110 'chromium.ycm_extra_conf.py')
120 self.test_root = tempfile.mkdtemp() 111 self.test_root = tempfile.mkdtemp()
121 self.SetUpFakeChromeTreeBelowPath() 112 self.SetUpFakeChromeTreeBelowPath()
122 113
123 def tearDown(self): 114 def tearDown(self):
124 if self.test_root: 115 if False and self.test_root:
scottmg 2016/06/06 16:32:11 ?
pastarmovj 2016/06/07 08:52:29 Sorry I needed to preserve the test files while fi
125 shutil.rmtree(self.test_root) 116 shutil.rmtree(self.test_root)
126 117
127 def testNinjaIsAvailable(self): 118 def testNinjaIsAvailable(self):
128 p = subprocess.Popen(['ninja', '--version'], stdout=subprocess.PIPE) 119 p = subprocess.Popen(['ninja', '--version'], stdout=subprocess.PIPE)
129 _, _ = p.communicate() 120 _, _ = p.communicate()
130 self.assertFalse(p.returncode) 121 self.assertFalse(p.returncode)
131 122
132 def testFindChromeSrc(self): 123 def testFindChromeSrc(self):
133 chrome_source = self.ycm_extra_conf.FindChromeSrcFromFilename( 124 chrome_source = self.ycm_extra_conf.FindChromeSrcFromFilename(
134 os.path.join(self.chrome_root, 'chrome', 'one.cpp')) 125 os.path.join(self.chrome_root, 'chrome', 'one.cpp'))
(...skipping 30 matching lines...) Expand all
165 156
166 def testOutDirNames(self): 157 def testOutDirNames(self):
167 out_root = os.path.join(self.chrome_root, 'out_with_underscore') 158 out_root = os.path.join(self.chrome_root, 'out_with_underscore')
168 out_dir = os.path.join(out_root, 'gn') 159 out_dir = os.path.join(out_root, 'gn')
169 shutil.move(os.path.join(self.chrome_root, 'out'), 160 shutil.move(os.path.join(self.chrome_root, 'out'),
170 out_root) 161 out_root)
171 162
172 clang_options = \ 163 clang_options = \
173 self.ycm_extra_conf.GetClangOptionsFromNinjaForFilename( 164 self.ycm_extra_conf.GetClangOptionsFromNinjaForFilename(
174 self.chrome_root, os.path.join(self.chrome_root, 'one.cpp')) 165 self.chrome_root, os.path.join(self.chrome_root, 'one.cpp'))
175 self.assertIn('-I%s/a' % out_dir, clang_options) 166 self.assertIn('-I%s/a' % self.NormalizeString(out_dir),
176 self.assertIn('-I%s/tag-one' % out_dir, clang_options) 167 self.NormalizeStringsInList(clang_options))
168 self.assertIn('-I%s/tag-one' % self.NormalizeString(out_dir),
169 self.NormalizeStringsInList(clang_options))
177 170
178 def testGetFlagsForFileForKnownCppFile(self): 171 def testGetFlagsForFileForKnownCppFile(self):
179 result = self.ycm_extra_conf.FlagsForFile( 172 result = self.ycm_extra_conf.FlagsForFile(
180 os.path.join(self.chrome_root, 'one.cpp')) 173 os.path.join(self.chrome_root, 'one.cpp'))
181 self.assertTrue(result) 174 self.assertTrue(result)
182 self.assertTrue('do_cache' in result) 175 self.assertTrue('do_cache' in result)
183 self.assertTrue(result['do_cache']) 176 self.assertTrue(result['do_cache'])
184 self.assertTrue('flags' in result) 177 self.assertTrue('flags' in result)
185 self.assertEquals(self.NormalizeStringsInList(result['flags']), [ 178 self.assertEquals(self.NormalizeStringsInList(result['flags']), [
186 '-DUSE_CLANG_COMPLETER', 179 '-DUSE_CLANG_COMPLETER',
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 '-isysroot', 299 '-isysroot',
307 '/mac.sdk', 300 '/mac.sdk',
308 '-I[OUT]/tag-three' 301 '-I[OUT]/tag-three'
309 ]) 302 ])
310 303
311 def testSourceFileWithNonClangOutputs(self): 304 def testSourceFileWithNonClangOutputs(self):
312 # Verify assumption that four.cc has non-compiler-output listed as the first 305 # Verify assumption that four.cc has non-compiler-output listed as the first
313 # output. 306 # output.
314 p = subprocess.Popen(['ninja', '-C', self.out_dir, '-t', 307 p = subprocess.Popen(['ninja', '-C', self.out_dir, '-t',
315 'query', '../../four.cc'], 308 'query', '../../four.cc'],
316 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 309 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
310 universal_newlines=True)
317 stdout, _ = p.communicate() 311 stdout, _ = p.communicate()
318 self.assertFalse(p.returncode) 312 self.assertFalse(p.returncode)
319 self.assertEquals(stdout, 313 self.assertEquals(stdout,
320 '../../four.cc:\n' 314 '../../four.cc:\n'
321 ' outputs:\n' 315 ' outputs:\n'
322 ' obj/linker-output.o\n' 316 ' obj/linker-output.o\n'
323 ' obj/four.o\n') 317 ' obj/four.o\n')
324 318
325 result = self.ycm_extra_conf.FlagsForFile( 319 result = self.ycm_extra_conf.FlagsForFile(
326 os.path.join(self.chrome_root, 'four.cc')) 320 os.path.join(self.chrome_root, 'four.cc'))
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 '-Wno-unknown-warning-option', 385 '-Wno-unknown-warning-option',
392 '-I[OUT]/a', 386 '-I[OUT]/a',
393 '--sysroot=[SRC]/build/sysroot-image', 387 '--sysroot=[SRC]/build/sysroot-image',
394 ]) 388 ])
395 389
396 if __name__ == '__main__': 390 if __name__ == '__main__':
397 if not os.path.isfile('chromium.ycm_extra_conf.py'): 391 if not os.path.isfile('chromium.ycm_extra_conf.py'):
398 print('The test must be run from src/tools/vim/ directory') 392 print('The test must be run from src/tools/vim/ directory')
399 sys.exit(1) 393 sys.exit(1)
400 unittest.main() 394 unittest.main()
OLDNEW
« no previous file with comments | « tools/vim/chromium.ycm_extra_conf.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698