Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with ExecuteScriptWithArgsAsync when script is a command #1569

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,9 @@ public async Task ExecuteScriptWithArgsAsync(string script, string arguments = n

if (arguments != null)
{
// Add CWD from PowerShell if not an absolute path
if (!Path.IsPathRooted(script))
// Add CWD from PowerShell if the script is a file (not a command/inline script) and
// it's not an absolute path.
if (File.Exists(script) && !Path.IsPathRooted(script))
{
try
{
Expand Down
30 changes: 30 additions & 0 deletions test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,36 @@ public void Dispose()
this.powerShellContext.Close();
}

[Trait("Category", "DebugService")]
[Fact]
// This regression test asserts that `ExecuteScriptWithArgsAsync` works for both script
// files and, in this case, in-line scripts (commands). The bug was that the cwd was
// erroneously prepended when the script argument was a command.
public async Task DebuggerAcceptsInlineScript()
{
await this.debugService.SetCommandBreakpointsAsync(
new[] { CommandBreakpointDetails.Create("Get-Random") }).ConfigureAwait(false);

Task executeTask =
this.powerShellContext.ExecuteScriptWithArgsAsync(
"Get-Random", string.Join(" ", "-Maximum", "100"));

await this.AssertDebuggerStopped("", 1).ConfigureAwait(false);
this.debugService.Continue();
await executeTask.ConfigureAwait(false);

StackFrameDetails[] stackFrames = debugService.GetStackFrames();
Assert.Equal(StackFrameDetails.NoFileScriptPath, stackFrames [0].ScriptPath);

VariableDetailsBase[] variables =
debugService.GetVariables(stackFrames[0].LocalVariables.Id);

var var = variables.FirstOrDefault(v => v.Name == "$Error");
Assert.NotNull(var);
Assert.True(var.IsExpandable);
Assert.Equal("[ArrayList: 0]", var.ValueString);
}

public static IEnumerable<object[]> DebuggerAcceptsScriptArgsTestData
{
get
Expand Down