13
13
using Microsoft . PowerShell . EditorServices . Handlers ;
14
14
using Microsoft . PowerShell . EditorServices . Services ;
15
15
using Microsoft . PowerShell . EditorServices . Services . DebugAdapter ;
16
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Console ;
16
17
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
17
18
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
18
19
using Microsoft . PowerShell . EditorServices . Test ;
22
23
23
24
namespace PowerShellEditorServices . Test . Debugging
24
25
{
26
+ internal class TestReadLine : IReadLine
27
+ {
28
+ public List < string > history = new ( ) ;
29
+
30
+ public string ReadLine ( CancellationToken cancellationToken ) => "" ;
31
+
32
+ public void AddToHistory ( string historyEntry ) => history . Add ( historyEntry ) ;
33
+ }
34
+
25
35
[ Trait ( "Category" , "DebugService" ) ]
26
36
public class DebugServiceTests : IDisposable
27
37
{
@@ -32,13 +42,15 @@ public class DebugServiceTests : IDisposable
32
42
private readonly WorkspaceService workspace ;
33
43
private readonly ScriptFile debugScriptFile ;
34
44
private readonly ScriptFile variableScriptFile ;
45
+ private readonly TestReadLine testReadLine = new ( ) ;
35
46
36
47
public DebugServiceTests ( )
37
48
{
38
49
psesHost = PsesHostFactory . Create ( NullLoggerFactory . Instance ) ;
39
50
// This is required for remote debugging, but we call it here to end up in the same
40
51
// state as the usual startup path.
41
52
psesHost . DebugContext . EnableDebugMode ( ) ;
53
+ psesHost . _readLineProvider . ReadLine = testReadLine ;
42
54
43
55
breakpointService = new BreakpointService (
44
56
NullLoggerFactory . Instance ,
@@ -558,6 +570,50 @@ await debugService.SetCommandBreakpointsAsync(
558
570
Assert . Equal ( "\" . $args[0]\" " , myInvocationLine . ValueString ) ;
559
571
}
560
572
573
+ [ Fact ]
574
+ public async Task RecordsF5CommandInPowerShellHistory ( )
575
+ {
576
+ ConfigurationDoneHandler configurationDoneHandler = new (
577
+ NullLoggerFactory . Instance , null , debugService , null , null , psesHost , workspace , null , psesHost ) ;
578
+ await configurationDoneHandler . LaunchScriptAsync ( debugScriptFile . FilePath ) . ConfigureAwait ( true ) ;
579
+
580
+ IReadOnlyList < string > historyResult = await psesHost . ExecutePSCommandAsync < string > (
581
+ new PSCommand ( ) . AddScript ( "(Get-History).CommandLine" ) ,
582
+ CancellationToken . None ) . ConfigureAwait ( true ) ;
583
+
584
+ // Check the PowerShell history
585
+ Assert . Single ( historyResult ) ;
586
+ Assert . Equal ( ". \" " + debugScriptFile . FilePath + "\" " , historyResult [ 0 ] ) ;
587
+
588
+ // Check the stubbed PSReadLine history
589
+ Assert . Single ( testReadLine . history ) ;
590
+ Assert . Equal ( ". \" " + debugScriptFile . FilePath + "\" " , testReadLine . history [ 0 ] ) ;
591
+ }
592
+
593
+ [ Fact ]
594
+ public async Task RecordsF8CommandInHistory ( )
595
+ {
596
+ const string script = "Write-Output Hello" ;
597
+ EvaluateHandler evaluateHandler = new ( psesHost ) ;
598
+ EvaluateResponseBody evaluateResponseBody = await evaluateHandler . Handle (
599
+ new EvaluateRequestArguments { Expression = script , Context = "repl" } ,
600
+ CancellationToken . None ) . ConfigureAwait ( true ) ;
601
+ // TODO: Right now this response is hard-coded, maybe it should change?
602
+ Assert . Equal ( "" , evaluateResponseBody . Result ) ;
603
+
604
+ IReadOnlyList < string > historyResult = await psesHost . ExecutePSCommandAsync < string > (
605
+ new PSCommand ( ) . AddScript ( "(Get-History).CommandLine" ) ,
606
+ CancellationToken . None ) . ConfigureAwait ( true ) ;
607
+
608
+ // Check the PowerShell history
609
+ Assert . Single ( historyResult ) ;
610
+ Assert . Equal ( script , historyResult [ 0 ] ) ;
611
+
612
+ // Check the stubbed PSReadLine history
613
+ Assert . Single ( testReadLine . history ) ;
614
+ Assert . Equal ( script , testReadLine . history [ 0 ] ) ;
615
+ }
616
+
561
617
[ Fact ]
562
618
public async Task DebuggerVariableStringDisplaysCorrectly ( )
563
619
{
0 commit comments