diff --git a/python/ycm/server/tests/get_completions_test.py b/python/ycm/server/tests/get_completions_test.py index 7751b3f7..14fd5e54 100644 --- a/python/ycm/server/tests/get_completions_test.py +++ b/python/ycm/server/tests/get_completions_test.py @@ -23,7 +23,7 @@ import time import httplib from .test_utils import ( Setup, BuildRequest, PathToTestFile, ChangeSpecificOptions ) -from webtest import TestApp +from webtest import TestApp, AppError from nose.tools import eq_, with_setup from hamcrest import ( assert_that, has_item, has_items, has_entry, contains_inanyorder ) @@ -95,6 +95,80 @@ def GetCompletions_CsCompleter_Works_test(): command_arguments = ['StopServer'], filetype = 'cs' ) ) +@with_setup( Setup ) +def GetCompletions_CsCompleter_StartsWithUnambiguousMultipleSolutions_test(): + app = TestApp( handlers.app ) + filepath = PathToTestFile( ('testy-multiple-solutions/' + 'solution-named-like-folder/' + 'testy/Program.cs') ) + contents = open( filepath ).read() + event_data = BuildRequest( filepath = filepath, + filetype = 'cs', + contents = contents, + event_name = 'FileReadyToParse' ) + + # Here the server will raise an exception if it can't start + app.post_json( '/event_notification', event_data ) + + # Now for some cleanup: wait for the server to start then shut it down + while True: + result = app.post_json( '/run_completer_command', + BuildRequest( completer_target = 'filetype_default', + command_arguments = ['ServerRunning'], + filetype = 'cs' ) ).json + if result: + break + time.sleep( 0.2 ) + + # We need to turn off the CS server so that it doesn't stick around + app.post_json( '/run_completer_command', + BuildRequest( completer_target = 'filetype_default', + command_arguments = ['StopServer'], + filetype = 'cs' ) ) + +@with_setup( Setup ) +def GetCompletions_CsCompleter_DoesntStartWithAmbiguousMultipleSolutions_test(): + app = TestApp( handlers.app ) + filepath = PathToTestFile( ('testy-multiple-solutions/' + 'solution-not-named-like-folder/' + 'testy/Program.cs') ) + contents = open( filepath ).read() + event_data = BuildRequest( filepath = filepath, + filetype = 'cs', + contents = contents, + event_name = 'FileReadyToParse' ) + + exceptioncaught = False + try: + app.post_json( '/event_notification', event_data ) + except AppError as e: + if 'Found multiple solution files' in str(e): + exceptioncaught = True + + # the test passes if we caught an exception when trying to start it, + # so raise one if it managed to start + if exceptioncaught == False: + # Now for some cleanup: wait for the server to start then shut it down + while True: + result = app.post_json( '/run_completer_command', + BuildRequest( completer_target = 'filetype_default', + command_arguments = ['ServerRunning'], + filetype = 'cs' ) ).json + if result: + break + time.sleep( 0.2 ) + + # We need to turn off the CS server so that it doesn't stick around + app.post_json( '/run_completer_command', + BuildRequest( completer_target = 'filetype_default', + command_arguments = ['StopServer'], + filetype = 'cs' ) ) + + raise Exception( ('The Omnisharp server started, despite us not being able ' + 'to find a suitable solution file to feed it. Did you ' + 'fiddle with the solution finding code in ' + 'cs_completer.py? Hopefully you\'ve enhanced it: you need' + 'to update this test then :)') ) @with_setup( Setup ) def GetCompletions_ClangCompleter_WorksWithExplicitFlags_test(): diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy.sln b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy.sln new file mode 100644 index 00000000..82e3d155 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testy", "testy/testy.csproj", "{0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Debug|x86.ActiveCfg = Debug|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Debug|x86.Build.0 = Debug|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Release|x86.ActiveCfg = Release|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = testy/testy.csproj + EndGlobalSection +EndGlobal diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/Program.cs b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/Program.cs new file mode 100644 index 00000000..cac606c8 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace testy +{ + class MainClass + { + public static void Main (string[] args) + { + Console. + } + } +} diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/Properties/AssemblyInfo.cs b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..bed715b8 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/Properties/AssemblyInfo.cs @@ -0,0 +1,22 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. +[assembly: AssemblyTitle ("testy")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("valloric")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. +[assembly: AssemblyVersion ("1.0.*")] +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/testy.csproj b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/testy.csproj new file mode 100644 index 00000000..1f1c0dd1 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy/testy.csproj @@ -0,0 +1,41 @@ + + + + Debug + x86 + 10.0.0 + 2.0 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F} + Exe + testy + testy + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + full + true + bin\Release + prompt + 4 + true + x86 + + + + + + + + + + \ No newline at end of file diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy2.sln b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy2.sln new file mode 100644 index 00000000..82e3d155 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-named-like-folder/testy2.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testy", "testy/testy.csproj", "{0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Debug|x86.ActiveCfg = Debug|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Debug|x86.Build.0 = Debug|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Release|x86.ActiveCfg = Release|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = testy/testy.csproj + EndGlobalSection +EndGlobal diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/Program.cs b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/Program.cs new file mode 100644 index 00000000..cac606c8 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace testy +{ + class MainClass + { + public static void Main (string[] args) + { + Console. + } + } +} diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/Properties/AssemblyInfo.cs b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..bed715b8 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/Properties/AssemblyInfo.cs @@ -0,0 +1,22 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. +[assembly: AssemblyTitle ("testy")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("valloric")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. +[assembly: AssemblyVersion ("1.0.*")] +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/testy.csproj b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/testy.csproj new file mode 100644 index 00000000..1f1c0dd1 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy/testy.csproj @@ -0,0 +1,41 @@ + + + + Debug + x86 + 10.0.0 + 2.0 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F} + Exe + testy + testy + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + full + true + bin\Release + prompt + 4 + true + x86 + + + + + + + + + + \ No newline at end of file diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy1.sln b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy1.sln new file mode 100644 index 00000000..82e3d155 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy1.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testy", "testy/testy.csproj", "{0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Debug|x86.ActiveCfg = Debug|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Debug|x86.Build.0 = Debug|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Release|x86.ActiveCfg = Release|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = testy/testy.csproj + EndGlobalSection +EndGlobal diff --git a/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy2.sln b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy2.sln new file mode 100644 index 00000000..82e3d155 --- /dev/null +++ b/python/ycm/server/tests/testdata/testy-multiple-solutions/solution-not-named-like-folder/testy2.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testy", "testy/testy.csproj", "{0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Debug|x86.ActiveCfg = Debug|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Debug|x86.Build.0 = Debug|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Release|x86.ActiveCfg = Release|x86 + {0C99F719-E00E-4CCD-AB9F-FEFBCD97C51F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = testy/testy.csproj + EndGlobalSection +EndGlobal