Skip to content

Commit 95c9afe

Browse files
committed
Add regression test CanLaunchScriptWithCommentedLastLineAsync
1 parent 07d8577 commit 95c9afe

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;
@@ -297,5 +297,32 @@ public async Task CanStepPastSystemWindowsForms()
297297
Assert.NotNull(form);
298298
Assert.Equal("System.Windows.Forms.Form, Text: ", form.Value);
299299
}
300+
301+
// This tests the edge-case where a raw script (or an untitled script) has the last line
302+
// commented. Since in some cases (such as Windows PowerShell, or the script not having a
303+
// backing ScriptFile) we just wrap the script with braces, we had a bug where the last
304+
// brace would be after the comment. We had to ensure we wrapped with newlines instead.
305+
[Trait("Category", "DAP")]
306+
[Fact]
307+
public async Task CanLaunchScriptWithCommentedLastLineAsync()
308+
{
309+
string script = GenerateScriptFromLoggingStatements("a log statement") + "# a comment at the end";
310+
Assert.Contains(Environment.NewLine + "# a comment", script);
311+
Assert.EndsWith("at the end", script);
312+
313+
// NOTE: This is horribly complicated, but the "script" parameter here is assigned to
314+
// PsesLaunchRequestArguments.Script, which is then assigned to
315+
// DebugStateService.ScriptToLaunch in that handler, and finally used by the
316+
// ConfigurationDoneHandler in LaunchScriptAsync.
317+
await PsesDebugAdapterClient.LaunchScript(script, Started).ConfigureAwait(false);
318+
319+
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(false);
320+
Assert.NotNull(configDoneResponse);
321+
322+
// At this point the script should be running so lets give it time
323+
await Task.Delay(2000).ConfigureAwait(false);
324+
325+
Assert.Collection(GetLog(), (i) => Assert.Equal("a log statement", i));
326+
}
300327
}
301328
}

0 commit comments

Comments
 (0)