|
5 | 5 |
|
6 | 6 | using Microsoft.PowerShell.EditorServices.Utility;
|
7 | 7 | using System;
|
| 8 | +using System.Collections.Generic; |
8 | 9 | using System.Linq;
|
9 | 10 | using System.Management.Automation;
|
10 | 11 | using System.Threading;
|
11 | 12 | using System.Threading.Tasks;
|
12 | 13 | using Xunit;
|
13 |
| -using Xunit.Sdk; |
14 | 14 |
|
15 | 15 | namespace Microsoft.PowerShell.EditorServices.Test.Debugging
|
16 | 16 | {
|
@@ -69,6 +69,76 @@ public void Dispose()
|
69 | 69 | this.powerShellContext.Dispose();
|
70 | 70 | }
|
71 | 71 |
|
| 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 | + |
72 | 142 | [Fact]
|
73 | 143 | public async Task DebuggerSetsAndClearsBreakpoints()
|
74 | 144 | {
|
|
0 commit comments