Skip to content

Commit 195a439

Browse files
committed
Add multi-module test for go
1 parent 57f3b75 commit 195a439

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

ycmd/tests/go/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def Wrapper( test_case_instance, *args, **kwargs ):
7373
return Decorator
7474

7575

76-
def PathToTestFile( *args ):
76+
def PathToTestFile( *args, module_dir = 'go_module' ):
7777
dir_of_current_script = os.path.dirname( os.path.abspath( __file__ ) )
7878
# GOPLS doesn't work if any parent directory is named "testdata"
79-
return os.path.join( dir_of_current_script, 'go_module', *args )
79+
return os.path.join( dir_of_current_script, module_dir, *args )

ycmd/tests/go/go_module/thing.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package main
22

3+
import "example.com/owner/module/td"
4+
35
type thinger interface {
4-
DoThing()
6+
DoThing()
57
}
68

79
type thing string
810

9-
func (thing) DoThing() {}
11+
func (thing) DoThing() {
12+
td.Hello()
13+
}

ycmd/tests/go/go_module_2/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module example.com/owner/other_module
2+
3+
go 1.22.0

ycmd/tests/go/go_module_2/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
func f() {}
4+
5+
func main() {
6+
f()
7+
}

ycmd/tests/go/subcommands_test.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232

3333
from ycmd import handlers
3434
from ycmd.tests.go import setUpModule, tearDownModule # noqa
35-
from ycmd.tests.go import PathToTestFile, SharedYcmd
35+
from ycmd.tests.go import ( PathToTestFile,
36+
SharedYcmd,
37+
IsolatedYcmd,
38+
StartGoCompleterServerInDirectory )
3639
from ycmd.tests.test_utils import ( BuildRequest,
3740
ChunkMatcher,
3841
ErrorMatcher,
@@ -391,10 +394,10 @@ def test_Subcommands_GoToType( self, app ):
391394
def test_Subcommands_GoToImplementation( self, app ):
392395
for test in [
393396
# Works
394-
{ 'req': ( 'thing.go', 3, 8 ),
395-
'res': ( 'thing.go', 7, 6 ) },
397+
{ 'req': ( 'thing.go', 5, 8 ),
398+
'res': ( 'thing.go', 9, 6 ) },
396399
# Fails
397-
{ 'req': ( 'thing.go', 12, 7 ),
400+
{ 'req': ( 'thing.go', 10, 1 ),
398401
'res': 'Cannot jump to location' } ]:
399402
with self.subTest( test = test ):
400403
RunGoToTest( app, 'GoToImplementation', test )
@@ -508,3 +511,20 @@ def test_Subcommands_GoToCallers( self, app ):
508511
]:
509512
with self.subTest( test = test ):
510513
RunGoToTest( app, 'GoToCallers', test )
514+
515+
516+
@IsolatedYcmd()
517+
def test_Subcommands_GoTo_WorksAfterSwitchingProjects( self, app ):
518+
project_dir = PathToTestFile( module_dir = 'go_module_2' )
519+
StartGoCompleterServerInDirectory( app, project_dir )
520+
go_module_2_main = PathToTestFile( 'main.go', module_dir = 'go_module_2' )
521+
thing_go = PathToTestFile( 'thing.go' )
522+
td_test_go = PathToTestFile( 'td', 'test.go' )
523+
for test in [
524+
{ 'req': ( go_module_2_main, 6, 3 ),
525+
'res': ( go_module_2_main, 3, 6 ) },
526+
{ 'req': ( thing_go, 12, 8 ),
527+
'res': ( td_test_go, 9, 6 ) }
528+
]:
529+
with self.subTest( test = test ):
530+
RunGoToTest( app, 'GoTo', test )

0 commit comments

Comments
 (0)