12
12
using Microsoft . Extensions . Logging . Abstractions ;
13
13
using Microsoft . PowerShell . EditorServices . Services ;
14
14
using Microsoft . PowerShell . EditorServices . Services . DebugAdapter ;
15
- using Microsoft . PowerShell . EditorServices . Services . PowerShell . Execution ;
16
15
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
17
16
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
18
17
using Microsoft . PowerShell . EditorServices . Test . Shared ;
18
+ using Microsoft . PowerShell . EditorServices . Utility ;
19
19
using Xunit ;
20
20
21
21
namespace Microsoft . PowerShell . EditorServices . Test . Debugging
@@ -92,12 +92,18 @@ public async Task DebuggerAcceptsInlineScript()
92
92
await debugService . SetCommandBreakpointsAsync (
93
93
new [ ] { CommandBreakpointDetails . Create ( "Get-Random" ) } ) . ConfigureAwait ( false ) ;
94
94
95
- Task executeTask = _psesHost . ExecutePSCommandAsync (
96
- new PSCommand ( ) . AddScript ( "Get-Random -Maximum 100" ) , CancellationToken . None ) ;
95
+ Task < IReadOnlyList < int > > executeTask = _psesHost . ExecutePSCommandAsync < int > (
96
+ new PSCommand ( ) . AddScript ( "Get-Random -SetSeed 42 - Maximum 100" ) , CancellationToken . None ) ;
97
97
98
98
AssertDebuggerStopped ( "" , 1 ) ;
99
+
100
+ // NOTE: Continuing the debugger cancels the current task, as it expects the integrated
101
+ // console to be running. So we run the prompt so our actual debug task is not canceled.
102
+ await ExecutePowerShellCommand ( "prompt" ) . ConfigureAwait ( false ) ;
99
103
debugService . Continue ( ) ;
100
104
105
+ Assert . Equal ( 17 , ( await executeTask . ConfigureAwait ( false ) ) [ 0 ] ) ;
106
+
101
107
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( false ) ;
102
108
Assert . Equal ( StackFrameDetails . NoFileScriptPath , stackFrames [ 0 ] . ScriptPath ) ;
103
109
@@ -110,49 +116,40 @@ await debugService.SetCommandBreakpointsAsync(
110
116
Assert . Equal ( "[ArrayList: 0]" , var . ValueString ) ;
111
117
}
112
118
113
- public static IEnumerable < object [ ] > DebuggerAcceptsScriptArgsTestData
114
- {
115
- get
116
- {
117
- return new [ ]
118
- {
119
- new [ ] { new [ ] { "Foo -Param2 @('Bar','Baz') -Force Extra1" } } ,
120
- new [ ] { new [ ] { "Foo" , "-Param2" , "@('Bar','Baz')" , "-Force" , "Extra1" } } ,
121
- } ;
122
- }
123
- }
124
-
125
119
[ Trait ( "Category" , "DebugService" ) ]
126
- [ Theory ]
127
- [ MemberData ( nameof ( DebuggerAcceptsScriptArgsTestData ) ) ]
128
- public async Task DebuggerAcceptsScriptArgs ( string [ ] args )
120
+ [ Fact ]
121
+ public async Task DebuggerAcceptsScriptArgs ( )
129
122
{
130
123
// The path is intentionally odd (some escaped chars but not all) because we are testing
131
124
// the internal path escaping mechanism - it should escape certains chars ([, ] and space) but
132
125
// it should not escape already escaped chars.
133
126
ScriptFile debugWithParamsFile = GetDebugScript ( "Debug W&ith Params [Test].ps1" ) ;
134
127
135
- await debugService . SetLineBreakpointsAsync (
128
+ BreakpointDetails [ ] breakpoints = await debugService . SetLineBreakpointsAsync (
136
129
debugWithParamsFile ,
137
130
new [ ] { BreakpointDetails . Create ( debugWithParamsFile . FilePath , 3 ) } ) . ConfigureAwait ( false ) ;
138
131
139
- // Execute the script and wait for the breakpoint to be hit
140
- Task executeTask = _psesHost . ExecutePSCommandAsync (
141
- new PSCommand ( ) . AddCommand ( debugWithParamsFile . FilePath ) . AddArgument ( string . Join ( " " , args ) ) ,
142
- CancellationToken . None ) ;
132
+ Assert . Single ( breakpoints ) ;
133
+ Assert . Collection ( breakpoints , ( breakpoint ) =>
134
+ {
135
+ Assert . Equal ( debugWithParamsFile . FilePath , breakpoint . Source ) ;
136
+ Assert . Equal ( 3 , breakpoint . LineNumber ) ;
137
+ Assert . True ( breakpoint . Verified ) ;
138
+ } ) ;
143
139
144
- AssertDebuggerStopped ( debugWithParamsFile . FilePath ) ;
140
+ // TODO: This test used to also pass the args as a single string, but that doesn't seem
141
+ // to work any more. Perhaps that's a bug?
142
+ var args = new [ ] { "Foo" , "-Param2" , "@('Bar','Baz')" , "-Force" , "Extra1" } ;
143
+ Task executeTask = ExecutePowerShellCommand ( debugWithParamsFile . FilePath , args ) ;
145
144
146
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( false ) ;
145
+ AssertDebuggerStopped ( debugWithParamsFile . FilePath , 3 ) ;
147
146
148
- VariableDetailsBase [ ] variables =
149
- debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
147
+ StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( false ) ;
148
+ VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
150
149
151
150
var var = Array . Find ( variables , v => v . Name == "$Param1" ) ;
152
151
Assert . NotNull ( var ) ;
153
- // TODO: Double-check this is intended.
154
- Assert . StartsWith ( "\" Foo" , var . ValueString ) ;
155
- // Assert.Equal("\"Foo\"", var.ValueString);
152
+ Assert . Equal ( "\" Foo\" " , var . ValueString ) ;
156
153
Assert . False ( var . IsExpandable ) ;
157
154
158
155
var = Array . Find ( variables , v => v . Name == "$Param2" ) ;
@@ -169,6 +166,9 @@ await debugService.SetLineBreakpointsAsync(
169
166
Assert . Equal ( "True" , var . ValueString ) ;
170
167
Assert . True ( var . IsExpandable ) ;
171
168
169
+ // NOTE: $args are not longer found in AutoVariables.
170
+ variables = debugService . GetVariables ( stackFrames [ 0 ] . CommandVariables . Id ) ;
171
+
172
172
var = Array . Find ( variables , v => v . Name == "$args" ) ;
173
173
Assert . NotNull ( var ) ;
174
174
Assert . True ( var . IsExpandable ) ;
@@ -179,7 +179,6 @@ await debugService.SetLineBreakpointsAsync(
179
179
180
180
// Abort script execution early and wait for completion
181
181
debugService . Abort ( ) ;
182
- await executeTask . ConfigureAwait ( false ) ;
183
182
}
184
183
185
184
[ Trait ( "Category" , "DebugService" ) ]
@@ -1008,6 +1007,10 @@ await debugService.SetLineBreakpointsAsync(
1008
1007
debugService . Abort ( ) ;
1009
1008
await executeTask . ConfigureAwait ( false ) ;
1010
1009
}
1010
+ private Task ExecutePowerShellCommand ( string command , params string [ ] args )
1011
+ {
1012
+ return _psesHost . ExecutePSCommandAsync ( PSCommandHelpers . BuildCommandFromArguments ( command , args ) , CancellationToken . None ) ;
1013
+ }
1011
1014
1012
1015
private void AssertDebuggerPaused ( )
1013
1016
{
@@ -1024,6 +1027,8 @@ private void AssertDebuggerStopped(
1024
1027
DebuggerStoppedEventArgs eventArgs =
1025
1028
debuggerStoppedQueue . Take ( new CancellationTokenSource ( 10000 ) . Token ) ;
1026
1029
1030
+ // Assert.True(_psesHost.DebugContext.IsStopped);
1031
+
1027
1032
// TODO: Why does the casing of the path change? Specifically the Drive letter on Windows.
1028
1033
if ( eventArgs . ScriptPath is not null )
1029
1034
{
0 commit comments