@@ -90,6 +90,14 @@ private ScriptFile GetDebugScript(string fileName)
9090 ) ) ) ;
9191 }
9292
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+
93101 private Task ExecutePowerShellCommand ( string command , params string [ ] args )
94102 {
95103 return psesHost . ExecutePSCommandAsync (
@@ -158,10 +166,10 @@ await debugService.SetCommandBreakpointsAsync(
158166
159167 StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
160168 Assert . Equal ( StackFrameDetails . NoFileScriptPath , stackFrames [ 0 ] . ScriptPath ) ;
161- VariableDetailsBase [ ] variables = debugService . GetVariables ( debugService . globalScopeVariables . Id ) ;
162169
163170 // NOTE: This assertion will fail if any error occurs. Notably this happens in testing
164171 // when the assembly path changes and the commands definition file can't be found.
172+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . GlobalScopeName ) ;
165173 var var = Array . Find ( variables , v => v . Name == "$Error" ) ;
166174 Assert . NotNull ( var ) ;
167175 Assert . True ( var . IsExpandable ) ;
@@ -197,8 +205,7 @@ public async Task DebuggerAcceptsScriptArgs()
197205
198206 AssertDebuggerStopped ( debugWithParamsFile . FilePath , 3 ) ;
199207
200- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
201- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
208+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
202209
203210 var var = Array . Find ( variables , v => v . Name == "$Param1" ) ;
204211 Assert . NotNull ( var ) ;
@@ -220,6 +227,7 @@ public async Task DebuggerAcceptsScriptArgs()
220227 Assert . True ( var . IsExpandable ) ;
221228
222229 // NOTE: $args are no longer found in AutoVariables but CommandVariables instead.
230+ StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
223231 variables = debugService . GetVariables ( stackFrames [ 0 ] . CommandVariables . Id ) ;
224232 var = Array . Find ( variables , v => v . Name == "$args" ) ;
225233 Assert . NotNull ( var ) ;
@@ -266,8 +274,7 @@ public async Task DebuggerStopsOnFunctionBreakpoints()
266274 Task _ = ExecuteDebugFile ( ) ;
267275 AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
268276
269- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
270- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
277+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
271278
272279 // Verify the function breakpoint broke at Write-Host and $i is 1
273280 var i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -279,8 +286,7 @@ public async Task DebuggerStopsOnFunctionBreakpoints()
279286 debugService . Continue ( ) ;
280287 AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
281288
282- stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
283- variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
289+ variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
284290
285291 // Verify the function breakpoint broke at Write-Host and $i is 1
286292 i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -356,8 +362,7 @@ await debugService.SetLineBreakpointsAsync(
356362 Task _ = ExecuteDebugFile ( ) ;
357363 AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
358364
359- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
360- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
365+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
361366
362367 // Verify the breakpoint only broke at the condition ie. $i -eq breakpointValue1
363368 var i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -370,8 +375,7 @@ await debugService.SetLineBreakpointsAsync(
370375 debugService . Continue ( ) ;
371376 AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
372377
373- stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
374- variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
378+ variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
375379
376380 // Verify the breakpoint only broke at the condition ie. $i -eq breakpointValue1
377381 i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -395,8 +399,7 @@ await debugService.SetLineBreakpointsAsync(
395399 Task _ = ExecuteDebugFile ( ) ;
396400 AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
397401
398- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
399- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
402+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
400403
401404 // Verify the breakpoint only broke at the condition ie. $i -eq breakpointValue1
402405 var i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -418,8 +421,7 @@ await debugService.SetLineBreakpointsAsync(
418421 Task _ = ExecuteDebugFile ( ) ;
419422 AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
420423
421- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
422- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
424+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
423425
424426 // Verify the breakpoint only broke at the condition ie. $i -eq breakpointValue1
425427 var i = Array . Find ( variables , v => v . Name == "$i" ) ;
@@ -519,8 +521,7 @@ await debugService.SetLineBreakpointsAsync(
519521 Task _ = ExecuteVariableScriptFile ( ) ;
520522 AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
521523
522- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
523- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
524+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
524525
525526 var var = Array . Find ( variables , v => v . Name == "$strVar" ) ;
526527 Assert . NotNull ( var ) ;
@@ -539,8 +540,7 @@ await debugService.SetLineBreakpointsAsync(
539540 Task _ = ExecuteVariableScriptFile ( ) ;
540541 AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
541542
542- StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
543- VariableDetailsBase [ ] variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
543+ VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
544544
545545 // TODO: Add checks for correct value strings as well
546546 var strVar = Array . Find ( variables , v => v . Name == "$strVar" ) ;
@@ -580,7 +580,7 @@ await debugService.SetLineBreakpointsAsync(
580580 }
581581
582582 [ Trait ( "Category" , "DebugService" ) ]
583- [ Fact ( Skip = "Variable setting is broken" ) ]
583+ [ Fact ]
584584 public async Task DebuggerSetsVariablesNoConversion ( )
585585 {
586586 await debugService . SetLineBreakpointsAsync (
@@ -590,16 +590,16 @@ await debugService.SetLineBreakpointsAsync(
590590 Task _ = ExecuteVariableScriptFile ( ) ;
591591 AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
592592
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 ) ;
595595
596596 // 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 ) ;
599601 Assert . Equal ( newStrValue , setStrValue ) ;
600602
601- VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
602-
603603 // Test set of script scope int variable (not strongly typed)
604604 VariableScope scriptScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . ScriptScopeName ) ;
605605 const string newIntValue = "49" ;
@@ -615,33 +615,27 @@ await debugService.SetLineBreakpointsAsync(
615615
616616 // The above just tests that the debug service returns the correct new value string.
617617 // 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 ) ;
619619 AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
620620
621- stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
622-
623621 // Test set of a local string variable (not strongly typed)
624- variables = debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id ) ;
622+ variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
625623 var strVar = Array . Find ( variables , v => v . Name == "$strVar" ) ;
626624 Assert . Equal ( newStrValue , strVar . ValueString ) ;
627625
628- scopes = debugService . GetVariableScopes ( 0 ) ;
629-
630626 // 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 ) ;
633628 var intVar = Array . Find ( variables , v => v . Name == "$scriptInt" ) ;
634629 Assert . Equal ( newIntValue , intVar . ValueString ) ;
635630
636631 // 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 ) ;
639633 var intGlobalVar = Array . Find ( variables , v => v . Name == "$MaximumHistoryCount" ) ;
640634 Assert . Equal ( newGlobalIntValue , intGlobalVar . ValueString ) ;
641635 }
642636
643637 [ Trait ( "Category" , "DebugService" ) ]
644- [ Fact ( Skip = "Variable setting is broken" ) ]
638+ [ Fact ( Skip = "Variable conversion is broken" ) ]
645639 public async Task DebuggerSetsVariablesWithConversion ( )
646640 {
647641 await debugService . SetLineBreakpointsAsync (
@@ -652,17 +646,16 @@ await debugService.SetLineBreakpointsAsync(
652646 Task _ = ExecuteVariableScriptFile ( ) ;
653647 AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
654648
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 ) ;
657651
658652 // Test set of a local string variable (not strongly typed but force conversion)
659- const string newStrValue = "\" False\" " ;
653+ const string newStrValue = "False" ;
660654 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 ) ;
662657 Assert . Equal ( newStrValue , setStrValue ) ;
663658
664- VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
665-
666659 // Test set of script scope bool variable (strongly typed)
667660 VariableScope scriptScope = Array . Find ( scopes , s => s . Name == VariableContainerDetails . ScriptScopeName ) ;
668661 const string newBoolValue = "$true" ;
@@ -679,27 +672,23 @@ await debugService.SetLineBreakpointsAsync(
679672
680673 // The above just tests that the debug service returns the correct new value string.
681674 // 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 ) ;
683676 AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
684677
685- stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
686-
687678 // 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 ) ;
689680 var strVar = Array . Find ( variables , v => v . Name == "$strVar2" ) ;
690681 Assert . Equal ( newStrValue , strVar . ValueString ) ;
691682
692683 scopes = debugService . GetVariableScopes ( 0 ) ;
693684
694685 // 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 ) ;
697687 var boolVar = Array . Find ( variables , v => v . Name == "$scriptBool" ) ;
698688 Assert . Equal ( newBoolValue , boolVar . ValueString ) ;
699689
700690 // 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 ) ;
703692 var globalVar = Array . Find ( variables , v => v . Name == "$VerbosePreference" ) ;
704693 Assert . Equal ( newGlobalValue , globalVar . ValueString ) ;
705694 }
0 commit comments