@@ -90,6 +90,14 @@ private ScriptFile GetDebugScript(string fileName)
90
90
) ) ) ;
91
91
}
92
92
93
+ private VariableDetailsBase [ ] GetVariables ( string scopeName )
94
+ {
95
+ VariableScope scope = Array . Find (
96
+ debugService . GetVariableScopes ( 0 ) ,
97
+ s => s . Name == scopeName ) ;
98
+ return debugService . GetVariables ( scope . Id ) ;
99
+ }
100
+
93
101
private Task ExecutePowerShellCommand ( string command , params string [ ] args )
94
102
{
95
103
return psesHost . ExecutePSCommandAsync (
@@ -158,10 +166,10 @@ await debugService.SetCommandBreakpointsAsync(
158
166
159
167
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
160
168
Assert . Equal ( StackFrameDetails . NoFileScriptPath , stackFrames [ 0 ] . ScriptPath ) ;
161
- VariableDetailsBase [ ] variables = debugService . GetVariables ( debugService . globalScopeVariables . Id ) ;
162
169
163
170
// NOTE: This assertion will fail if any error occurs. Notably this happens in testing
164
171
// when the assembly path changes and the commands definition file can't be found.
172
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . GlobalScopeName ) ;
165
173
var var = Array . Find ( variables , v => v . Name == "$Error" ) ;
166
174
Assert . NotNull ( var ) ;
167
175
Assert . True ( var . IsExpandable ) ;
@@ -197,8 +205,7 @@ public async Task DebuggerAcceptsScriptArgs()
197
205
198
206
AssertDebuggerStopped ( debugWithParamsFile . FilePath , 3 ) ;
199
207
200
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
201
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
208
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
202
209
203
210
var var = Array . Find ( variables , v => v . Name == "$Param1" ) ;
204
211
Assert . NotNull ( var ) ;
@@ -220,6 +227,7 @@ public async Task DebuggerAcceptsScriptArgs()
220
227
Assert . True ( var . IsExpandable ) ;
221
228
222
229
// NOTE: $args are no longer found in AutoVariables but CommandVariables instead.
230
+ StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
223
231
variables = debugService . GetVariables ( stackFrames [ 0 ] . CommandVariables . Id ) ;
224
232
var = Array . Find ( variables , v => v . Name == "$args" ) ;
225
233
Assert . NotNull ( var ) ;
@@ -266,8 +274,7 @@ public async Task DebuggerStopsOnFunctionBreakpoints()
266
274
Task _ = ExecuteDebugFile ( ) ;
267
275
AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
268
276
269
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
270
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
277
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
271
278
272
279
// Verify the function breakpoint broke at Write-Host and $i is 1
273
280
var i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -279,8 +286,7 @@ public async Task DebuggerStopsOnFunctionBreakpoints()
279
286
debugService . Continue ( ) ;
280
287
AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
281
288
282
- stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
283
- variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
289
+ variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
284
290
285
291
// Verify the function breakpoint broke at Write-Host and $i is 1
286
292
i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -356,8 +362,7 @@ await debugService.SetLineBreakpointsAsync(
356
362
Task _ = ExecuteDebugFile ( ) ;
357
363
AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
358
364
359
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
360
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
365
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
361
366
362
367
// Verify the breakpoint only broke at the condition ie. $i -eq breakpointValue1
363
368
var i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -370,8 +375,7 @@ await debugService.SetLineBreakpointsAsync(
370
375
debugService . Continue ( ) ;
371
376
AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
372
377
373
- stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
374
- variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
378
+ variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
375
379
376
380
// Verify the breakpoint only broke at the condition ie. $i -eq breakpointValue1
377
381
i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -395,8 +399,7 @@ await debugService.SetLineBreakpointsAsync(
395
399
Task _ = ExecuteDebugFile ( ) ;
396
400
AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
397
401
398
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
399
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
402
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
400
403
401
404
// Verify the breakpoint only broke at the condition ie. $i -eq breakpointValue1
402
405
var i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -418,8 +421,7 @@ await debugService.SetLineBreakpointsAsync(
418
421
Task _ = ExecuteDebugFile ( ) ;
419
422
AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
420
423
421
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
422
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
424
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
423
425
424
426
// Verify the breakpoint only broke at the condition ie. $i -eq breakpointValue1
425
427
var i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -519,8 +521,7 @@ await debugService.SetLineBreakpointsAsync(
519
521
Task _ = ExecuteVariableScriptFile ( ) ;
520
522
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
521
523
522
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
523
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
524
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
524
525
525
526
var var = Array . Find ( variables , v => v . Name == "$strVar" ) ;
526
527
Assert . NotNull ( var ) ;
@@ -539,8 +540,7 @@ await debugService.SetLineBreakpointsAsync(
539
540
Task _ = ExecuteVariableScriptFile ( ) ;
540
541
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
541
542
542
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
543
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
543
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
544
544
545
545
// TODO: Add checks for correct value strings as well
546
546
var strVar = Array . Find ( variables , v => v . Name == "$strVar" ) ;
@@ -580,7 +580,7 @@ await debugService.SetLineBreakpointsAsync(
580
580
}
581
581
582
582
[ Trait ( "Category" , "DebugService" ) ]
583
- [ Fact ( Skip = "Variable setting is broken" ) ]
583
+ [ Fact ]
584
584
public async Task DebuggerSetsVariablesNoConversion ( )
585
585
{
586
586
await debugService . SetLineBreakpointsAsync (
@@ -590,16 +590,16 @@ await debugService.SetLineBreakpointsAsync(
590
590
Task _ = ExecuteVariableScriptFile ( ) ;
591
591
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
592
592
593
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
594
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
593
+ VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
594
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
595
595
596
596
// Test set of a local string variable (not strongly typed)
597
- const string newStrValue = "\" Goodbye\" " ;
598
- string setStrValue = await debugService . SetVariableAsync ( stackFrames [ 0 ] . AutoVariables . Id , "$strVar" , newStrValue ) . ConfigureAwait ( true ) ;
597
+ const string newStrValue = "Goodbye" ;
598
+ VariableScope localScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . LocalScopeName ) ;
599
+ // TODO: Fix this so it has the second quotes again?
600
+ string setStrValue = await debugService . SetVariableAsync ( localScope . Id , "$strVar" , '"' + newStrValue + '"' ) . ConfigureAwait ( true ) ;
599
601
Assert . Equal ( newStrValue , setStrValue ) ;
600
602
601
- VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
602
-
603
603
// Test set of script scope int variable (not strongly typed)
604
604
VariableScope scriptScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . ScriptScopeName ) ;
605
605
const string newIntValue = "49" ;
@@ -615,33 +615,27 @@ await debugService.SetLineBreakpointsAsync(
615
615
616
616
// The above just tests that the debug service returns the correct new value string.
617
617
// Let's step the debugger and make sure the values got set to the new values.
618
- debugService . StepOver ( ) ;
618
+ await Task . Run ( ( ) => debugService . StepOver ( ) ) . ConfigureAwait ( true ) ;
619
619
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
620
620
621
- stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
622
-
623
621
// Test set of a local string variable (not strongly typed)
624
- variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
622
+ variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
625
623
var strVar = Array . Find ( variables , v => v . Name == "$strVar" ) ;
626
624
Assert . Equal ( newStrValue , strVar . ValueString ) ;
627
625
628
- scopes = debugService . GetVariableScopes ( 0 ) ;
629
-
630
626
// Test set of script scope int variable (not strongly typed)
631
- scriptScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . ScriptScopeName ) ;
632
- variables = debugService . GetVariables ( scriptScope . Id ) ;
627
+ variables = GetVariables ( VariableContainerDetails . ScriptScopeName ) ;
633
628
var intVar = Array . Find ( variables , v => v . Name == "$scriptInt" ) ;
634
629
Assert . Equal ( newIntValue , intVar . ValueString ) ;
635
630
636
631
// Test set of global scope int variable (not strongly typed)
637
- globalScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . GlobalScopeName ) ;
638
- variables = debugService . GetVariables ( globalScope . Id ) ;
632
+ variables = GetVariables ( VariableContainerDetails . GlobalScopeName ) ;
639
633
var intGlobalVar = Array . Find ( variables , v => v . Name == "$MaximumHistoryCount" ) ;
640
634
Assert . Equal ( newGlobalIntValue , intGlobalVar . ValueString ) ;
641
635
}
642
636
643
637
[ Trait ( "Category" , "DebugService" ) ]
644
- [ Fact ( Skip = "Variable setting is broken" ) ]
638
+ [ Fact ( Skip = "Variable conversion is broken" ) ]
645
639
public async Task DebuggerSetsVariablesWithConversion ( )
646
640
{
647
641
await debugService . SetLineBreakpointsAsync (
@@ -652,17 +646,16 @@ await debugService.SetLineBreakpointsAsync(
652
646
Task _ = ExecuteVariableScriptFile ( ) ;
653
647
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
654
648
655
- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
656
- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
649
+ VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
650
+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
657
651
658
652
// Test set of a local string variable (not strongly typed but force conversion)
659
- const string newStrValue = "\" False\" " ;
653
+ const string newStrValue = "False" ;
660
654
const string newStrExpr = "$false" ;
661
- string setStrValue = await debugService . SetVariableAsync ( stackFrames [ 0 ] . AutoVariables . Id , "$strVar2" , newStrExpr ) . ConfigureAwait ( true ) ;
655
+ VariableScope localScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . LocalScopeName ) ;
656
+ string setStrValue = await debugService . SetVariableAsync ( localScope . Id , "$strVar2" , newStrExpr ) . ConfigureAwait ( true ) ;
662
657
Assert . Equal ( newStrValue , setStrValue ) ;
663
658
664
- VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
665
-
666
659
// Test set of script scope bool variable (strongly typed)
667
660
VariableScope scriptScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . ScriptScopeName ) ;
668
661
const string newBoolValue = "$true" ;
@@ -679,27 +672,23 @@ await debugService.SetLineBreakpointsAsync(
679
672
680
673
// The above just tests that the debug service returns the correct new value string.
681
674
// Let's step the debugger and make sure the values got set to the new values.
682
- debugService . StepOver ( ) ;
675
+ await Task . Run ( ( ) => debugService . StepOver ( ) ) . ConfigureAwait ( true ) ;
683
676
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
684
677
685
- stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
686
-
687
678
// Test set of a local string variable (not strongly typed but force conversion)
688
- variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
679
+ variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
689
680
var strVar = Array . Find ( variables , v => v . Name == "$strVar2" ) ;
690
681
Assert . Equal ( newStrValue , strVar . ValueString ) ;
691
682
692
683
scopes = debugService . GetVariableScopes ( 0 ) ;
693
684
694
685
// Test set of script scope bool variable (strongly typed)
695
- scriptScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . ScriptScopeName ) ;
696
- variables = debugService . GetVariables ( scriptScope . Id ) ;
686
+ variables = GetVariables ( VariableContainerDetails . ScriptScopeName ) ;
697
687
var boolVar = Array . Find ( variables , v => v . Name == "$scriptBool" ) ;
698
688
Assert . Equal ( newBoolValue , boolVar . ValueString ) ;
699
689
700
690
// Test set of global scope ActionPreference variable (strongly typed)
701
- globalScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . GlobalScopeName ) ;
702
- variables = debugService . GetVariables ( globalScope . Id ) ;
691
+ variables = GetVariables ( VariableContainerDetails . GlobalScopeName ) ;
703
692
var globalVar = Array . Find ( variables , v => v . Name == "$VerbosePreference" ) ;
704
693
Assert . Equal ( newGlobalValue , globalVar . ValueString ) ;
705
694
}
0 commit comments