| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 '-std=c++11', | 225 '-std=c++11', |
| 219 '-x', 'c++', | 226 '-x', 'c++', |
| 220 '-I[SRC]', | 227 '-I[SRC]', |
| 221 '-Wno-unknown-warning-option', | 228 '-Wno-unknown-warning-option', |
| 222 '-I[OUT]/a', | 229 '-I[OUT]/a', |
| 223 '-isysroot', | 230 '-isysroot', |
| 224 '/mac.sdk', | 231 '/mac.sdk', |
| 225 '-I[OUT]/tag-default' | 232 '-I[OUT]/tag-default' |
| 226 ]) | 233 ]) |
| 227 | 234 |
| 235 def testGetFlagsForFileForUnknownObjcFile(self): |
| 236 result = self.ycm_extra_conf.FlagsForFile( |
| 237 os.path.join(self.chrome_root, 'nonexistent.m')) |
| 238 self.assertTrue(result) |
| 239 self.assertEqual(GetLastLangFlag(result['flags']), 'objective-c') |
| 240 |
| 241 def testGetFlagsForFileForUnknownObjcppFile(self): |
| 242 result = self.ycm_extra_conf.FlagsForFile( |
| 243 os.path.join(self.chrome_root, 'nonexistent.mm')) |
| 244 self.assertTrue(result) |
| 245 self.assertEqual(GetLastLangFlag(result['flags']), 'objective-c++') |
| 246 |
| 228 def testGetFlagsForFileForUnknownHeaderFile(self): | 247 def testGetFlagsForFileForUnknownHeaderFile(self): |
| 229 result = self.ycm_extra_conf.FlagsForFile( | 248 result = self.ycm_extra_conf.FlagsForFile( |
| 230 os.path.join(self.chrome_root, 'nonexistent.h')) | 249 os.path.join(self.chrome_root, 'nonexistent.h')) |
| 231 self.assertTrue(result) | 250 self.assertTrue(result) |
| 232 self.assertTrue('do_cache' in result) | 251 self.assertTrue('do_cache' in result) |
| 233 self.assertTrue(result['do_cache']) | 252 self.assertTrue(result['do_cache']) |
| 234 self.assertTrue('flags' in result) | 253 self.assertTrue('flags' in result) |
| 235 self.assertEquals(self.NormalizeStringsInList(result['flags']), [ | 254 self.assertEquals(self.NormalizeStringsInList(result['flags']), [ |
| 236 '-DUSE_CLANG_COMPLETER', | 255 '-DUSE_CLANG_COMPLETER', |
| 237 '-std=c++11', | 256 '-std=c++11', |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 '-Wno-unknown-warning-option', | 404 '-Wno-unknown-warning-option', |
| 386 '-I[OUT]/a', | 405 '-I[OUT]/a', |
| 387 '--sysroot=[SRC]/build/sysroot-image', | 406 '--sysroot=[SRC]/build/sysroot-image', |
| 388 ]) | 407 ]) |
| 389 | 408 |
| 390 if __name__ == '__main__': | 409 if __name__ == '__main__': |
| 391 if not os.path.isfile('chromium.ycm_extra_conf.py'): | 410 if not os.path.isfile('chromium.ycm_extra_conf.py'): |
| 392 print('The test must be run from src/tools/vim/ directory') | 411 print('The test must be run from src/tools/vim/ directory') |
| 393 sys.exit(1) | 412 sys.exit(1) |
| 394 unittest.main() | 413 unittest.main() |
| OLD | NEW |