Skip to content

Commit 9ec5d11

Browse files
committed
Added unit tests for #141.
1 parent 44431bb commit 9ec5d11

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
param($Param1, $Param2, [switch]$Force)
2+
3+
"args are $args"

test/PowerShellEditorServices.Test.Shared/PowerShellEditorServices.Test.Shared.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<None Include="Completion\CompletionExamples.psm1">
6565
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6666
</None>
67+
<None Include="Debugging\DebugWithParamsTest.ps1" />
6768
<None Include="Debugging\VariableTest.ps1" />
6869
<None Include="SymbolDetails\SymbolDetails.ps1" />
6970
<None Include="Symbols\MultipleSymbols.ps1" />

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
using Microsoft.PowerShell.EditorServices.Utility;
77
using System;
8+
using System.Collections.Generic;
89
using System.Linq;
910
using System.Management.Automation;
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213
using Xunit;
13-
using Xunit.Sdk;
1414

1515
namespace Microsoft.PowerShell.EditorServices.Test.Debugging
1616
{
@@ -69,6 +69,76 @@ public void Dispose()
6969
this.powerShellContext.Dispose();
7070
}
7171

72+
public static IEnumerable<object[]> DebuggerAcceptsScriptArgsTestData
73+
{
74+
get
75+
{
76+
var data = new[]
77+
{
78+
new[] { new []{ "Foo -Param2 @('Bar','Baz') -Force Extra1" }},
79+
new[] { new []{ "Foo", "-Param2", "@('Bar','Baz')", "-Force", "Extra1" }},
80+
};
81+
82+
return data;
83+
}
84+
}
85+
86+
[Theory]
87+
[MemberData("DebuggerAcceptsScriptArgsTestData")]
88+
public async Task DebuggerAcceptsScriptArgs(string[] args)
89+
{
90+
ScriptFile debugWithParamsFile =
91+
this.workspace.GetFile(
92+
@"..\..\..\PowerShellEditorServices.Test.Shared\Debugging\DebugWithParamsTest.ps1");
93+
94+
await this.debugService.SetBreakpoints(
95+
debugWithParamsFile,
96+
new int[] { 3 });
97+
98+
string arguments = string.Join(" ", args);
99+
100+
// Execute the script and wait for the breakpoint to be hit
101+
this.powerShellContext.ExecuteScriptAtPath(
102+
debugWithParamsFile.FilePath, arguments);
103+
104+
await this.AssertDebuggerStopped(debugWithParamsFile.FilePath);
105+
106+
StackFrameDetails[] stackFrames = debugService.GetStackFrames();
107+
108+
VariableDetailsBase[] variables =
109+
debugService.GetVariables(stackFrames[0].LocalVariables.Id);
110+
111+
var var = variables.FirstOrDefault(v => v.Name == "$Param1");
112+
Assert.NotNull(var);
113+
Assert.Equal("\"Foo\"", var.ValueString);
114+
Assert.False(var.IsExpandable);
115+
116+
var = variables.FirstOrDefault(v => v.Name == "$Param2");
117+
Assert.NotNull(var);
118+
Assert.True(var.IsExpandable);
119+
120+
var childVars = debugService.GetVariables(var.Id);
121+
Assert.Equal(9, childVars.Length);
122+
Assert.Equal("\"Bar\"", childVars[0].ValueString);
123+
Assert.Equal("\"Baz\"", childVars[1].ValueString);
124+
125+
var = variables.FirstOrDefault(v => v.Name == "$Force");
126+
Assert.NotNull(var);
127+
Assert.Equal("True", var.ValueString);
128+
Assert.True(var.IsExpandable);
129+
130+
var = variables.FirstOrDefault(v => v.Name == "$args");
131+
Assert.NotNull(var);
132+
Assert.True(var.IsExpandable);
133+
134+
childVars = debugService.GetVariables(var.Id);
135+
Assert.Equal(8, childVars.Length);
136+
Assert.Equal("\"Extra1\"", childVars[0].ValueString);
137+
138+
// Abort execution of the script
139+
this.powerShellContext.AbortExecution();
140+
}
141+
72142
[Fact]
73143
public async Task DebuggerSetsAndClearsBreakpoints()
74144
{

0 commit comments

Comments
 (0)