19
19
namespace PowerShellEditorServices . Test . E2E
20
20
{
21
21
[ Trait ( "Category" , "DAP" ) ]
22
- public class DebugAdapterProtocolMessageTests : IAsyncLifetime
22
+ public class DebugAdapterProtocolMessageTests : IAsyncLifetime , IDisposable
23
23
{
24
24
private const string TestOutputFileName = "__dapTestOutputFile.txt" ;
25
25
private static readonly bool s_isWindows = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
@@ -104,7 +104,13 @@ await PsesDebugAdapterClient.RequestDisconnect(new DisconnectArguments
104
104
TerminateDebuggee = true
105
105
} ) . ConfigureAwait ( true ) ;
106
106
await _psesProcess . Stop ( ) . ConfigureAwait ( true ) ;
107
+ }
108
+
109
+ public void Dispose ( )
110
+ {
111
+ GC . SuppressFinalize ( this ) ;
107
112
PsesDebugAdapterClient ? . Dispose ( ) ;
113
+ _psesProcess ? . Dispose ( ) ;
108
114
}
109
115
110
116
private static string NewTestFile ( string script , bool isPester = false )
@@ -130,11 +136,23 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements
130
136
}
131
137
132
138
// 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
+
134
147
for ( int i = 1 ; i < logStatements . Length ; i ++ )
135
148
{
136
149
// 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 ( "'" ) ;
138
156
}
139
157
140
158
_output . WriteLine ( "Script is:" ) ;
@@ -144,7 +162,7 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements
144
162
145
163
private static async Task < string [ ] > GetLog ( )
146
164
{
147
- while ( ! File . Exists ( s_testOutputPath ) )
165
+ for ( int i = 0 ; ! File . Exists ( s_testOutputPath ) && i < 10 ; i ++ )
148
166
{
149
167
await Task . Delay ( 1000 ) . ConfigureAwait ( true ) ;
150
168
}
@@ -164,6 +182,17 @@ public void CanInitializeWithCorrectServerSettings()
164
182
Assert . True ( PsesDebugAdapterClient . ServerSettings . SupportsSetVariable ) ;
165
183
}
166
184
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
+
167
196
[ Fact ]
168
197
public async Task CanLaunchScriptWithNoBreakpointsAsync ( )
169
198
{
0 commit comments