Skip to content

Commit 3de31d7

Browse files
committed
Add multi-project test for rust
1 parent 77734d6 commit 3de31d7

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

ycmd/tests/rust/subcommands_test.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@
3333

3434
from ycmd import handlers
3535
from ycmd.tests.rust import setUpModule, tearDownModule # noqa
36-
from ycmd.tests.rust import PathToTestFile, SharedYcmd
36+
from ycmd.tests.rust import ( PathToTestFile,
37+
SharedYcmd,
38+
IsolatedYcmd,
39+
StartRustCompleterServerInDirectory )
3740
from ycmd.tests.test_utils import ( BuildRequest,
3841
ChunkMatcher,
3942
ErrorMatcher,
4043
ExpectedFailure,
4144
LocationMatcher,
45+
WaitForDiagnosticsToBeReady,
4246
WithRetry )
4347
from ycmd.utils import ReadFile
4448

@@ -47,8 +51,9 @@
4751

4852

4953
def RunTest( app, test, contents = None ):
54+
filepath = test[ 'request' ][ 'filepath' ]
5055
if not contents:
51-
contents = ReadFile( test[ 'request' ][ 'filepath' ] )
56+
contents = ReadFile( filepath )
5257

5358
def CombineRequest( request, data ):
5459
kw = request
@@ -67,6 +72,10 @@ def CombineRequest( request, data ):
6772
} ),
6873
expect_errors = True )
6974

75+
# rust-analyzer sometimes needs a bit of time after opening a new file.
76+
# Probably to relax after some hard work...
77+
WaitForDiagnosticsToBeReady( app, filepath, contents, 'rust' )
78+
7079
# We also ignore errors here, but then we check the response code
7180
# ourself. This is to allow testing of requests returning errors.
7281
response = app.post_json(
@@ -88,8 +97,8 @@ def CombineRequest( request, data ):
8897
assert_that( response.json, test[ 'expect' ][ 'data' ] )
8998

9099

91-
def RunGoToTest( app, command, test ):
92-
folder = PathToTestFile( 'common', 'src' )
100+
def RunGoToTest( app, command, test, *, project_root = 'common' ):
101+
folder = PathToTestFile( project_root, 'src' )
93102
filepath = os.path.join( folder, test[ 'req' ][ 0 ] )
94103
request = {
95104
'command': command,
@@ -531,3 +540,22 @@ def test_Subcommands_FixIt_Basic( self, app ):
531540
} )
532541
},
533542
} )
543+
544+
545+
@IsolatedYcmd()
546+
def test_Subcommands_GoTo_WorksAfterChangingProject( self, app ):
547+
filepath = PathToTestFile( 'macro', 'src', 'main.rs' )
548+
StartRustCompleterServerInDirectory( app, filepath )
549+
550+
for test, root in [
551+
(
552+
{ 'req': ( 'main.rs', 31, 24 ), 'res': ( 'main.rs', 14, 9 ) },
553+
'macro'
554+
),
555+
(
556+
{ 'req': ( 'main.rs', 13, 19 ), 'res': ( 'test.rs', 4, 12 ) },
557+
'common'
558+
),
559+
]:
560+
with self.subTest( test = test, root = root ):
561+
RunGoToTest( app, 'GoTo', test, project_root = root )

0 commit comments

Comments
 (0)