Skip to content

Commit

Permalink
Fix bug with ExecuteScriptWithArgsAsync when script is a command
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Sep 1, 2021
1 parent 356efa6 commit 2bc0c03
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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

0 comments on commit 2bc0c03

Please sign in to comment.