OLD | NEW |
---|---|
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 Loading... | |
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 def GetLastLangFlag(flags): | |
57 lastLang = None | |
58 for i, flag in enumerate(flags): | |
59 if flag =='-x': | |
60 lastLang = flags[i+1] | |
61 return lastLang | |
62 | |
56 class Chromium_ycmExtraConfTest(unittest.TestCase): | 63 class Chromium_ycmExtraConfTest(unittest.TestCase): |
57 | 64 |
58 def SetUpFakeChromeTreeBelowPath(self): | 65 def SetUpFakeChromeTreeBelowPath(self): |
59 """Create fake Chromium source tree under self.test_root. | 66 """Create fake Chromium source tree under self.test_root. |
60 | 67 |
61 The fake source tree has the following contents: | 68 The fake source tree has the following contents: |
62 | 69 |
63 <self.test_root> | 70 <self.test_root> |
64 | .gclient | 71 | .gclient |
65 | | 72 | |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 '-std=c++11', | 224 '-std=c++11', |
218 '-x', 'c++', | 225 '-x', 'c++', |
219 '-I[SRC]', | 226 '-I[SRC]', |
220 '-Wno-unknown-warning-option', | 227 '-Wno-unknown-warning-option', |
221 '-I[OUT]/a', | 228 '-I[OUT]/a', |
222 '-isysroot', | 229 '-isysroot', |
223 '/mac.sdk', | 230 '/mac.sdk', |
224 '-I[OUT]/tag-default' | 231 '-I[OUT]/tag-default' |
225 ]) | 232 ]) |
226 | 233 |
234 def testGetFlagsForFileForUnknownObjcFile(self): | |
235 result = self.ycm_extra_conf.FlagsForFile( | |
236 os.path.join(self.chrome_root, 'nonexistent.m')) | |
237 self.assertTrue(result) | |
238 self.assertEqual(GetLastLangFlag(result['flags']), 'objective-c') | |
asanka
2016/09/02 15:00:50
"-x objective-c" might not be the last flag since
Sidney San Martín
2016/09/02 15:07:07
It may not be the last flag, but it does need to b
| |
239 | |
240 def testGetFlagsForFileForUnknownObjcppFile(self): | |
241 result = self.ycm_extra_conf.FlagsForFile( | |
242 os.path.join(self.chrome_root, 'nonexistent.mm')) | |
243 self.assertTrue(result) | |
244 self.assertEqual(GetLastLangFlag(result['flags']), 'objective-c++') | |
245 | |
227 def testGetFlagsForFileForUnknownHeaderFile(self): | 246 def testGetFlagsForFileForUnknownHeaderFile(self): |
228 result = self.ycm_extra_conf.FlagsForFile( | 247 result = self.ycm_extra_conf.FlagsForFile( |
229 os.path.join(self.chrome_root, 'nonexistent.h')) | 248 os.path.join(self.chrome_root, 'nonexistent.h')) |
230 self.assertTrue(result) | 249 self.assertTrue(result) |
231 self.assertTrue('do_cache' in result) | 250 self.assertTrue('do_cache' in result) |
232 self.assertTrue(result['do_cache']) | 251 self.assertTrue(result['do_cache']) |
233 self.assertTrue('flags' in result) | 252 self.assertTrue('flags' in result) |
234 self.assertEquals(self.NormalizeStringsInList(result['flags']), [ | 253 self.assertEquals(self.NormalizeStringsInList(result['flags']), [ |
235 '-DUSE_CLANG_COMPLETER', | 254 '-DUSE_CLANG_COMPLETER', |
236 '-std=c++11', | 255 '-std=c++11', |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 '-Wno-unknown-warning-option', | 403 '-Wno-unknown-warning-option', |
385 '-I[OUT]/a', | 404 '-I[OUT]/a', |
386 '--sysroot=[SRC]/build/sysroot-image', | 405 '--sysroot=[SRC]/build/sysroot-image', |
387 ]) | 406 ]) |
388 | 407 |
389 if __name__ == '__main__': | 408 if __name__ == '__main__': |
390 if not os.path.isfile('chromium.ycm_extra_conf.py'): | 409 if not os.path.isfile('chromium.ycm_extra_conf.py'): |
391 print('The test must be run from src/tools/vim/ directory') | 410 print('The test must be run from src/tools/vim/ directory') |
392 sys.exit(1) | 411 sys.exit(1) |
393 unittest.main() | 412 unittest.main() |
OLD | NEW |