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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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): | 56 def GetLastLangFlag(flags): |
57 lastLang = None | 57 lastLang = None |
58 for i, flag in enumerate(flags): | 58 for i, flag in enumerate(flags): |
59 if flag =='-x': | 59 if flag =='-x': |
60 lastLang = flags[i+1] | 60 lastLang = flags[i+1] |
61 return lastLang | 61 return lastLang |
62 | 62 |
| 63 def TestLanguage(test_file, language): |
| 64 def test(self): |
| 65 result = self.ycm_extra_conf.FlagsForFile( |
| 66 os.path.join(self.chrome_root, test_file)) |
| 67 self.assertTrue(result) |
| 68 self.assertEqual(GetLastLangFlag(result['flags']), language) |
| 69 return test |
| 70 |
63 class Chromium_ycmExtraConfTest(unittest.TestCase): | 71 class Chromium_ycmExtraConfTest(unittest.TestCase): |
64 | 72 |
65 def SetUpFakeChromeTreeBelowPath(self): | 73 def SetUpFakeChromeTreeBelowPath(self): |
66 """Create fake Chromium source tree under self.test_root. | 74 """Create fake Chromium source tree under self.test_root. |
67 | 75 |
68 The fake source tree has the following contents: | 76 The fake source tree has the following contents: |
69 | 77 |
70 <self.test_root> | 78 <self.test_root> |
71 | .gclient | 79 | .gclient |
72 | | 80 | |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 '-std=c++11', | 233 '-std=c++11', |
226 '-x', 'c++', | 234 '-x', 'c++', |
227 '-I[SRC]', | 235 '-I[SRC]', |
228 '-Wno-unknown-warning-option', | 236 '-Wno-unknown-warning-option', |
229 '-I[OUT]/a', | 237 '-I[OUT]/a', |
230 '-isysroot', | 238 '-isysroot', |
231 '/mac.sdk', | 239 '/mac.sdk', |
232 '-I[OUT]/tag-default' | 240 '-I[OUT]/tag-default' |
233 ]) | 241 ]) |
234 | 242 |
235 def testGetFlagsForFileForUnknownObjcFile(self): | 243 testGetFlagsForFileForKnownObjcFile = TestLanguage( |
236 result = self.ycm_extra_conf.FlagsForFile( | 244 'eight.m', 'objective-c') |
237 os.path.join(self.chrome_root, 'nonexistent.m')) | 245 testGetFlagsForFileForKnownObjcHeaderFile = TestLanguage( |
238 self.assertTrue(result) | 246 'eight.h', 'objective-c') |
239 self.assertEqual(GetLastLangFlag(result['flags']), 'objective-c') | 247 testGetFlagsForFileForUnknownObjcFile = TestLanguage( |
240 | 248 'nonexistent.m', 'objective-c') |
241 def testGetFlagsForFileForUnknownObjcppFile(self): | 249 testGetFlagsForFileForKnownObjcppFile = TestLanguage( |
242 result = self.ycm_extra_conf.FlagsForFile( | 250 'nine.mm', 'objective-c++') |
243 os.path.join(self.chrome_root, 'nonexistent.mm')) | 251 testGetFlagsForFileForKnownObjcppHeaderFile = TestLanguage( |
244 self.assertTrue(result) | 252 'nine.h', 'objective-c++') |
245 self.assertEqual(GetLastLangFlag(result['flags']), 'objective-c++') | 253 testGetFlagsForFileForUnknownObjcppFile = TestLanguage( |
| 254 'nonexistent.mm', 'objective-c++') |
246 | 255 |
247 def testGetFlagsForFileForUnknownHeaderFile(self): | 256 def testGetFlagsForFileForUnknownHeaderFile(self): |
248 result = self.ycm_extra_conf.FlagsForFile( | 257 result = self.ycm_extra_conf.FlagsForFile( |
249 os.path.join(self.chrome_root, 'nonexistent.h')) | 258 os.path.join(self.chrome_root, 'nonexistent.h')) |
250 self.assertTrue(result) | 259 self.assertTrue(result) |
251 self.assertTrue('do_cache' in result) | 260 self.assertTrue('do_cache' in result) |
252 self.assertTrue(result['do_cache']) | 261 self.assertTrue(result['do_cache']) |
253 self.assertTrue('flags' in result) | 262 self.assertTrue('flags' in result) |
254 self.assertEquals(self.NormalizeStringsInList(result['flags']), [ | 263 self.assertEquals(self.NormalizeStringsInList(result['flags']), [ |
255 '-DUSE_CLANG_COMPLETER', | 264 '-DUSE_CLANG_COMPLETER', |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 '-Wno-unknown-warning-option', | 413 '-Wno-unknown-warning-option', |
405 '-I[OUT]/a', | 414 '-I[OUT]/a', |
406 '--sysroot=[SRC]/build/sysroot-image', | 415 '--sysroot=[SRC]/build/sysroot-image', |
407 ]) | 416 ]) |
408 | 417 |
409 if __name__ == '__main__': | 418 if __name__ == '__main__': |
410 if not os.path.isfile('chromium.ycm_extra_conf.py'): | 419 if not os.path.isfile('chromium.ycm_extra_conf.py'): |
411 print('The test must be run from src/tools/vim/ directory') | 420 print('The test must be run from src/tools/vim/ directory') |
412 sys.exit(1) | 421 sys.exit(1) |
413 unittest.main() | 422 unittest.main() |
OLD | NEW |