1919namespace PowerShellEditorServices . Test . E2E
2020{
2121 [ Trait ( "Category" , "DAP" ) ]
22- public class DebugAdapterProtocolMessageTests : IAsyncLifetime
22+ public class DebugAdapterProtocolMessageTests : IAsyncLifetime , IDisposable
2323 {
2424 private const string TestOutputFileName = "__dapTestOutputFile.txt" ;
2525 private static readonly bool s_isWindows = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
@@ -104,7 +104,13 @@ await PsesDebugAdapterClient.RequestDisconnect(new DisconnectArguments
104104 TerminateDebuggee = true
105105 } ) . ConfigureAwait ( true ) ;
106106 await _psesProcess . Stop ( ) . ConfigureAwait ( true ) ;
107+ }
108+
109+ public void Dispose ( )
110+ {
111+ GC . SuppressFinalize ( this ) ;
107112 PsesDebugAdapterClient ? . Dispose ( ) ;
113+ _psesProcess ? . Dispose ( ) ;
108114 }
109115
110116 private static string NewTestFile ( string script , bool isPester = false )
@@ -130,11 +136,23 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements
130136 }
131137
132138 // Have script create file first with `>` (but don't rely on overwriting).
133- StringBuilder builder = new StringBuilder ( ) . Append ( '\' ' ) . Append ( logStatements [ 0 ] ) . Append ( "' > '" ) . Append ( s_testOutputPath ) . AppendLine ( "'" ) ;
139+ // NOTE: We uses double quotes so that we can use PowerShell variables.
140+ StringBuilder builder = new StringBuilder ( )
141+ . Append ( "Write-Output \" " )
142+ . Append ( logStatements [ 0 ] )
143+ . Append ( "\" > '" )
144+ . Append ( s_testOutputPath )
145+ . AppendLine ( "'" ) ;
146+
134147 for ( int i = 1 ; i < logStatements . Length ; i ++ )
135148 {
136149 // Then append to that script with `>>`.
137- builder . Append ( '\' ' ) . Append ( logStatements [ i ] ) . Append ( "' >> '" ) . Append ( s_testOutputPath ) . AppendLine ( "'" ) ;
150+ builder
151+ . Append ( "Write-Output \" " )
152+ . Append ( logStatements [ i ] )
153+ . Append ( "\" >> '" )
154+ . Append ( s_testOutputPath )
155+ . AppendLine ( "'" ) ;
138156 }
139157
140158 _output . WriteLine ( "Script is:" ) ;
@@ -144,7 +162,7 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements
144162
145163 private static async Task < string [ ] > GetLog ( )
146164 {
147- while ( ! File . Exists ( s_testOutputPath ) )
165+ for ( int i = 0 ; ! File . Exists ( s_testOutputPath ) && i < 10 ; i ++ )
148166 {
149167 await Task . Delay ( 1000 ) . ConfigureAwait ( true ) ;
150168 }
@@ -164,6 +182,17 @@ public void CanInitializeWithCorrectServerSettings()
164182 Assert . True ( PsesDebugAdapterClient . ServerSettings . SupportsSetVariable ) ;
165183 }
166184
185+ [ Fact ]
186+ public async Task UsesDotSourceOperatorAndQuotesAsync ( )
187+ {
188+ string filePath = NewTestFile ( GenerateScriptFromLoggingStatements ( "$($MyInvocation.Line)" ) ) ;
189+ await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( true ) ;
190+ ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( true ) ;
191+ Assert . NotNull ( configDoneResponse ) ;
192+ Assert . Collection ( await GetLog ( ) . ConfigureAwait ( true ) ,
193+ ( i ) => Assert . StartsWith ( ". \" " , i ) ) ;
194+ }
195+
167196 [ Fact ]
168197 public async Task CanLaunchScriptWithNoBreakpointsAsync ( )
169198 {
0 commit comments