|
| 1 | +# Copyright (C) 2021 ycmd contributors |
| 2 | +# |
| 3 | +# This file is part of ycmd. |
| 4 | +# |
| 5 | +# ycmd is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# ycmd is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with ycmd. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +from unittest.mock import patch |
| 19 | +from unittest import TestCase |
| 20 | +from hamcrest import assert_that, equal_to |
| 21 | + |
| 22 | +from ycmd import user_options_store |
| 23 | +from ycmd.completers.cs.hook import GetCompleter |
| 24 | +from ycmd.completers.cs.cs_completer import PATH_TO_OMNISHARP_ROSLYN_BINARY |
| 25 | +from ycmd.tests.cs import setUpModule, tearDownModule # noqa |
| 26 | + |
| 27 | + |
| 28 | +class GoCompleterTest( TestCase ): |
| 29 | + def test_GetCompleter_OmniSharpFound( self ): |
| 30 | + assert_that( GetCompleter( user_options_store.GetAll() ) ) |
| 31 | + |
| 32 | + |
| 33 | + @patch( 'ycmd.completers.cs.cs_completer.PATH_TO_OMNISHARP_ROSLYN_BINARY', None ) |
| 34 | + def test_GetCompleter_OmniSharpNotFound( self, *args ): |
| 35 | + assert_that( not GetCompleter( user_options_store.GetAll() ) ) |
| 36 | + |
| 37 | + |
| 38 | + @patch( 'ycmd.completers.cs.cs_completer.FindExecutableWithFallback', |
| 39 | + wraps = lambda x, fb: x if x == 'omnisharp' else None ) |
| 40 | + @patch( 'os.path.isfile', return_value = False ) |
| 41 | + def test_GetCompleter_CustomOmniSharpNotFound( self, *args ): |
| 42 | + user_options = user_options_store.GetAll().copy( |
| 43 | + roslyn_binary_path = 'omnisharp' ) |
| 44 | + assert_that( not GetCompleter( user_options ) ) |
| 45 | + |
| 46 | + |
| 47 | + @patch( 'ycmd.completers.cs.cs_completer.FindExecutableWithFallback', |
| 48 | + wraps = lambda x, fb: x if x == 'omnisharp' else None ) |
| 49 | + @patch( 'os.path.isfile', return_value = True ) |
| 50 | + def test_GetCompleter_CustomOmniSharpFound_MonoNotRequired( self, *args ): |
| 51 | + user_options = user_options_store.GetAll().copy( |
| 52 | + roslyn_binary_path = 'omnisharp' ) |
| 53 | + assert_that( GetCompleter( user_options ) ) |
| 54 | + |
| 55 | + |
| 56 | + @patch( 'ycmd.completers.cs.cs_completer.FindExecutableWithFallback', |
| 57 | + wraps = lambda x, fb: x if x in ( 'mono', 'omnisharp.exe' ) else None ) |
| 58 | + @patch( 'os.path.isfile', return_value = True ) |
| 59 | + def test_GetCompleter_CustomOmniSharpFound_MonoRequiredAndFound( self, *args ): |
| 60 | + user_options = user_options_store.GetAll().copy( |
| 61 | + roslyn_binary_path = 'omnisharp.exe', |
| 62 | + mono_binary_path = 'mono' ) |
| 63 | + assert_that( GetCompleter( user_options ) ) |
| 64 | + |
| 65 | + |
| 66 | + @patch( 'ycmd.completers.cs.cs_completer.FindExecutableWithFallback', |
| 67 | + wraps = lambda x, fb: x if x == 'omnisharp.exe' else None ) |
| 68 | + @patch( 'os.path.isfile', return_value = True ) |
| 69 | + def test_GetCompleter_CustomOmniSharpFound_MonoRequiredAndMissing( self, *args ): |
| 70 | + user_options = user_options_store.GetAll().copy( |
| 71 | + roslyn_binary_path = 'omnisharp.exe' ) |
| 72 | + assert_that( not GetCompleter( user_options ) ) |
| 73 | + |
| 74 | + |
| 75 | + def test_GetCompleter_OmniSharpDefaultOptions( self, *args ): |
| 76 | + completer = GetCompleter( user_options_store.GetAll() ) |
| 77 | + assert_that( completer._roslyn_path, equal_to( PATH_TO_OMNISHARP_ROSLYN_BINARY ) ) |
| 78 | + |
| 79 | + |
| 80 | + @patch( 'ycmd.completers.cs.cs_completer.FindExecutableWithFallback', |
| 81 | + wraps = lambda x, fb: x if x == 'omnisharp' else None ) |
| 82 | + @patch( 'os.path.isfile', return_value = True ) |
| 83 | + def test_GetCompleter_OmniSharpFromUserOption_NoMonoNeeded( self, *args ): |
| 84 | + user_options = user_options_store.GetAll().copy( |
| 85 | + roslyn_binary_path = 'omnisharp' ) |
| 86 | + completer = GetCompleter( user_options ) |
| 87 | + assert_that( completer._roslyn_path, equal_to( 'omnisharp' ) ) |
| 88 | + assert_that( completer.GetCommandLine()[ 0 ], equal_to( 'omnisharp' ) ) |
| 89 | + |
| 90 | + |
| 91 | + @patch( 'ycmd.completers.cs.cs_completer.FindExecutableWithFallback', |
| 92 | + wraps = lambda x, fb: x if x in ( 'omnisharp.exe', 'mono' ) else None ) |
| 93 | + @patch( 'os.path.isfile', return_value = True ) |
| 94 | + def test_GetCompleter_OmniSharpFromUserOption_MonoNeeded( self, *args ): |
| 95 | + user_options = user_options_store.GetAll().copy( |
| 96 | + roslyn_binary_path = 'omnisharp.exe', |
| 97 | + mono_binary_path = 'mono' ) |
| 98 | + completer = GetCompleter( user_options ) |
| 99 | + assert_that( completer._roslyn_path, equal_to( 'omnisharp.exe' ) ) |
| 100 | + assert_that( completer._mono, equal_to( 'mono' ) ) |
| 101 | + assert_that( completer.GetCommandLine()[ 0 ], equal_to( 'mono' ) ) |
0 commit comments