Skip to content

Commit c47306f

Browse files
committed
Fix scenario tests broken by recent async changes
This change fixes scenario tests that were broken by the recent message serialization changes. First of all, the correct stdio streams were not being used in the test runner so no messages could be read or written. Secondly, the existing unit tests were not using 'await' on the async WriteMessage calls, so this was causing some trouble with their operation. Also, some existing tests around REPL support were disabled for now until future design changes are completed. We're waiting on new message support from VS Code's debug protocol.
1 parent 02966c1 commit c47306f

File tree

3 files changed

+61
-59
lines changed

3 files changed

+61
-59
lines changed

test/PowerShellEditorServices.Test.Host/LanguageServiceManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public void Start()
6767
messageTypeResolver.ScanForMessageTypes(typeof(StartedEvent).Assembly);
6868

6969
// Open the standard input/output streams
70-
this.inputStream = System.Console.OpenStandardInput();
71-
this.outputStream = System.Console.OpenStandardOutput();
70+
this.inputStream = this.languageServiceProcess.StandardOutput.BaseStream;
71+
this.outputStream = this.languageServiceProcess.StandardInput.BaseStream;
7272

7373
// Set up the message reader and writer
7474
this.MessageReader =

test/PowerShellEditorServices.Test.Host/ScenarioTests.cs

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Response;
1212
using System;
1313
using System.Collections.Generic;
14+
using System.Threading.Tasks;
1415
using Xunit;
1516

1617
namespace Microsoft.PowerShell.EditorServices.Test.Host
@@ -41,11 +42,11 @@ public void Dispose()
4142
}
4243

4344
[Fact]
44-
public void ServiceReturnsSyntaxErrors()
45+
public async Task ServiceReturnsSyntaxErrors()
4546
{
4647
// Send the 'open' and 'geterr' events
47-
this.SendOpenFileRequest("TestFiles\\SimpleSyntaxError.ps1");
48-
this.SendErrorRequest("TestFiles\\SimpleSyntaxError.ps1");
48+
await this.SendOpenFileRequest("TestFiles\\SimpleSyntaxError.ps1");
49+
await this.SendErrorRequest("TestFiles\\SimpleSyntaxError.ps1");
4950

5051
// Wait for the events
5152
SyntaxDiagnosticEvent syntaxEvent = this.WaitForMessage<SyntaxDiagnosticEvent>();
@@ -62,10 +63,10 @@ public void ServiceReturnsSyntaxErrors()
6263
}
6364

6465
[Fact]
65-
public void ServiceCompletesFunctionName()
66+
public async Task ServiceCompletesFunctionName()
6667
{
67-
this.SendOpenFileRequest("TestFiles\\CompleteFunctionName.ps1");
68-
this.MessageWriter.WriteMessage(
68+
await this.SendOpenFileRequest("TestFiles\\CompleteFunctionName.ps1");
69+
await this.MessageWriter.WriteMessage(
6970
new CompletionsRequest
7071
{
7172
Arguments = new CompletionsRequestArgs
@@ -85,10 +86,10 @@ public void ServiceCompletesFunctionName()
8586
}
8687

8788
[Fact]
88-
public void CompletesDetailOnVariableSuggestion()
89+
public async Task CompletesDetailOnVariableSuggestion()
8990
{
90-
this.SendOpenFileRequest("TestFiles\\CompleteFunctionName.ps1");
91-
this.MessageWriter.WriteMessage(
91+
await this.SendOpenFileRequest("TestFiles\\CompleteFunctionName.ps1");
92+
await this.MessageWriter.WriteMessage(
9293
new CompletionsRequest
9394
{
9495
Arguments = new CompletionsRequestArgs
@@ -102,7 +103,7 @@ public void CompletesDetailOnVariableSuggestion()
102103
CompletionsResponse completion = this.WaitForMessage<CompletionsResponse>();
103104
List<string> entryName = new List<string>();
104105
entryName.Add("$ConsoleFileName");
105-
this.MessageWriter.WriteMessage(
106+
await this.MessageWriter.WriteMessage(
106107
new CompletionDetailsRequest
107108
{
108109
Arguments = new CompletionDetailsRequestArgs
@@ -119,10 +120,10 @@ public void CompletesDetailOnVariableSuggestion()
119120
}
120121

121122
[Fact]
122-
public void CompletesDetailOnVariableDocSuggestion()
123+
public async Task CompletesDetailOnVariableDocSuggestion()
123124
{
124-
this.SendOpenFileRequest("TestFiles\\CompleteFunctionName.ps1");
125-
this.MessageWriter.WriteMessage(
125+
await this.SendOpenFileRequest("TestFiles\\CompleteFunctionName.ps1");
126+
await this.MessageWriter.WriteMessage(
126127
new CompletionsRequest
127128
{
128129
Arguments = new CompletionsRequestArgs
@@ -136,7 +137,7 @@ public void CompletesDetailOnVariableDocSuggestion()
136137
CompletionsResponse completion = this.WaitForMessage<CompletionsResponse>();
137138
List<string> entryName = new List<string>();
138139
entryName.Add("$HKCU:");
139-
this.MessageWriter.WriteMessage(
140+
await this.MessageWriter.WriteMessage(
140141
new CompletionDetailsRequest
141142
{
142143
Arguments = new CompletionDetailsRequestArgs
@@ -153,10 +154,10 @@ public void CompletesDetailOnVariableDocSuggestion()
153154
}
154155

155156
[Fact]
156-
public void CompletesDetailOnCommandSuggestion()
157+
public async Task CompletesDetailOnCommandSuggestion()
157158
{
158-
this.SendOpenFileRequest("TestFiles\\CompleteFunctionName.ps1");
159-
this.MessageWriter.WriteMessage(
159+
await this.SendOpenFileRequest("TestFiles\\CompleteFunctionName.ps1");
160+
await this.MessageWriter.WriteMessage(
160161
new CompletionsRequest
161162
{
162163
Arguments = new CompletionsRequestArgs
@@ -171,7 +172,7 @@ public void CompletesDetailOnCommandSuggestion()
171172
CompletionsResponse completion = this.WaitForMessage<CompletionsResponse>();
172173
List<string> entryName = new List<string>();
173174
entryName.Add("Get-Process");
174-
this.MessageWriter.WriteMessage(
175+
await this.MessageWriter.WriteMessage(
175176
new CompletionDetailsRequest
176177
{
177178
Arguments = new CompletionDetailsRequestArgs
@@ -187,10 +188,10 @@ public void CompletesDetailOnCommandSuggestion()
187188
}
188189

189190
[Fact]
190-
public void FindsReferencesOfVariable()
191+
public async Task FindsReferencesOfVariable()
191192
{
192-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
193-
this.MessageWriter.WriteMessage(
193+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
194+
await this.MessageWriter.WriteMessage(
194195
new ReferencesRequest
195196
{
196197
Arguments = new FileLocationRequestArgs
@@ -208,10 +209,10 @@ public void FindsReferencesOfVariable()
208209
}
209210

210211
[Fact]
211-
public void FindsNoReferencesOfEmptyLine()
212+
public async Task FindsNoReferencesOfEmptyLine()
212213
{
213-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
214-
this.MessageWriter.WriteMessage(
214+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
215+
await this.MessageWriter.WriteMessage(
215216
new ReferencesRequest
216217
{
217218
Arguments = new FileLocationRequestArgs
@@ -227,10 +228,10 @@ public void FindsNoReferencesOfEmptyLine()
227228
}
228229

229230
[Fact]
230-
public void FindsReferencesOnFunctionDefinition()
231+
public async Task FindsReferencesOnFunctionDefinition()
231232
{
232-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
233-
this.MessageWriter.WriteMessage(
233+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
234+
await this.MessageWriter.WriteMessage(
234235
new ReferencesRequest
235236
{
236237
Arguments = new FileLocationRequestArgs
@@ -248,10 +249,10 @@ public void FindsReferencesOnFunctionDefinition()
248249
}
249250

250251
[Fact]
251-
public void FindsReferencesOnCommand()
252+
public async Task FindsReferencesOnCommand()
252253
{
253-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
254-
this.MessageWriter.WriteMessage(
254+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
255+
await this.MessageWriter.WriteMessage(
255256
new ReferencesRequest
256257
{
257258
Arguments = new FileLocationRequestArgs
@@ -269,10 +270,10 @@ public void FindsReferencesOnCommand()
269270
}
270271

271272
[Fact]
272-
public void FindsDefinitionOfCommand()
273+
public async Task FindsDefinitionOfCommand()
273274
{
274-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
275-
this.MessageWriter.WriteMessage(
275+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
276+
await this.MessageWriter.WriteMessage(
276277
new DeclarationRequest
277278
{
278279
Arguments = new FileLocationRequestArgs
@@ -289,10 +290,10 @@ public void FindsDefinitionOfCommand()
289290
}
290291

291292
[Fact]
292-
public void FindsNoDefinitionOfBuiltinCommand()
293+
public async Task FindsNoDefinitionOfBuiltinCommand()
293294
{
294-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
295-
this.MessageWriter.WriteMessage(
295+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
296+
await this.MessageWriter.WriteMessage(
296297
new DeclarationRequest
297298
{
298299
Arguments = new FileLocationRequestArgs
@@ -307,10 +308,10 @@ public void FindsNoDefinitionOfBuiltinCommand()
307308
}
308309

309310
[Fact]
310-
public void FindsDefintionOfVariable()
311+
public async Task FindsDefintionOfVariable()
311312
{
312-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
313-
this.MessageWriter.WriteMessage(
313+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
314+
await this.MessageWriter.WriteMessage(
314315
new DeclarationRequest
315316
{
316317
Arguments = new FileLocationRequestArgs
@@ -320,6 +321,7 @@ public void FindsDefintionOfVariable()
320321
Offset = 14,
321322
}
322323
});
324+
323325
DefinitionResponse definition = this.WaitForMessage<DefinitionResponse>();
324326
Assert.NotNull(definition);
325327
Assert.Equal(6, definition.Body[0].Start.Line);
@@ -329,10 +331,10 @@ public void FindsDefintionOfVariable()
329331
}
330332

331333
[Fact]
332-
public void FindsOccurencesOnFunctionDefinition()
334+
public async Task FindsOccurencesOnFunctionDefinition()
333335
{
334-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
335-
this.MessageWriter.WriteMessage(
336+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
337+
await this.MessageWriter.WriteMessage(
336338
new OccurrencesRequest
337339
{
338340
Arguments = new FileLocationRequestArgs
@@ -350,10 +352,10 @@ public void FindsOccurencesOnFunctionDefinition()
350352
}
351353

352354
[Fact]
353-
public void GetsParameterHintsOnCommand()
355+
public async Task GetsParameterHintsOnCommand()
354356
{
355-
this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
356-
this.MessageWriter.WriteMessage(
357+
await this.SendOpenFileRequest("TestFiles\\FindReferences.ps1");
358+
await this.MessageWriter.WriteMessage(
357359
new SignatureHelpRequest
358360
{
359361
Arguments = new SignatureHelpRequestArgs
@@ -370,10 +372,10 @@ public void GetsParameterHintsOnCommand()
370372
Assert.Equal(sigHelp.Body.ArgumentCount, 1);
371373
}
372374

373-
[Fact]
374-
public void ServiceExecutesReplCommandAndReceivesOutput()
375+
[Fact(Skip = "Console output events are disabled until we migrate to the updated debug protocol.")]
376+
public async Task ServiceExecutesReplCommandAndReceivesOutput()
375377
{
376-
this.MessageWriter.WriteMessage(
378+
await this.MessageWriter.WriteMessage(
377379
new ReplExecuteRequest
378380
{
379381
Arguments = new ReplExecuteArgs
@@ -386,8 +388,8 @@ public void ServiceExecutesReplCommandAndReceivesOutput()
386388
Assert.Equal("3", replWriteLineEvent.Body.LineContents);
387389
}
388390

389-
[Fact]
390-
public void ServiceExecutesReplCommandAndReceivesChoicePrompt()
391+
[Fact(Skip = "Choice prompt functionality is currently in transition to a new model.")]
392+
public async Task ServiceExecutesReplCommandAndReceivesChoicePrompt()
391393
{
392394
string choiceScript =
393395
@"
@@ -399,7 +401,7 @@ public void ServiceExecutesReplCommandAndReceivesChoicePrompt()
399401
$response = $host.ui.PromptForChoice($caption, $message, $choices, 1)
400402
$response";
401403

402-
this.MessageWriter.WriteMessage(
404+
await this.MessageWriter.WriteMessage(
403405
new ReplExecuteRequest
404406
{
405407
Arguments = new ReplExecuteArgs
@@ -413,7 +415,7 @@ public void ServiceExecutesReplCommandAndReceivesChoicePrompt()
413415
Assert.Equal(1, replPromptChoiceEvent.Body.DefaultChoice);
414416

415417
// Respond to the prompt event
416-
this.MessageWriter.WriteMessage(
418+
await this.MessageWriter.WriteMessage(
417419
new ReplPromptChoiceResponse
418420
{
419421
Body = new ReplPromptChoiceResponseBody
@@ -427,15 +429,15 @@ public void ServiceExecutesReplCommandAndReceivesChoicePrompt()
427429
Assert.Equal("0", replWriteLineEvent.Body.LineContents);
428430
}
429431

430-
private void SendOpenFileRequest(string fileName)
432+
private async Task SendOpenFileRequest(string fileName)
431433
{
432-
this.MessageWriter.WriteMessage(
434+
await this.MessageWriter.WriteMessage(
433435
OpenFileRequest.Create(fileName));
434436
}
435437

436-
private void SendErrorRequest(params string[] fileNames)
438+
private async Task SendErrorRequest(params string[] fileNames)
437439
{
438-
this.MessageWriter.WriteMessage(
440+
await this.MessageWriter.WriteMessage(
439441
ErrorRequest.Create(fileNames));
440442
}
441443

test/PowerShellEditorServices.Test/Console/ConsoleServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void Dispose()
2929
{
3030
}
3131

32-
[Fact]
32+
[Fact(Skip = "Choice prompt functionality is currently in transition to a new model.")]
3333
public async Task ReceivesChoicePrompt()
3434
{
3535
string choiceScript =

0 commit comments

Comments
 (0)