Skip to content

Commit 0db5647

Browse files
committed
Initial test build
1 parent 7ed4903 commit 0db5647

File tree

14 files changed

+71
-356
lines changed

14 files changed

+71
-356
lines changed

integrated.sln

Lines changed: 0 additions & 153 deletions
This file was deleted.

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,16 @@ private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyLi
158158

159159
// We are forced to use a hack here so that we can reuse PowerShell's parameter binding
160160
var sb = new StringBuilder()
161-
.Append("& '")
162-
.Append(command.Replace("'", "''"))
163-
.Append("'");
161+
.Append("& ")
162+
.Append(StringEscaping.SingleQuoteAndEscape(command));
164163

165164
foreach (string arg in arguments)
166165
{
167166
sb.Append(' ');
168167

169-
if (ArgumentNeedsEscaping(arg))
168+
if (StringEscaping.PowerShellArgumentNeedsEscaping(arg))
170169
{
171-
sb.Append('\'').Append(arg.Replace("'", "''")).Append('\'');
170+
sb.Append(StringEscaping.SingleQuoteAndEscape(arg));
172171
}
173172
else
174173
{
@@ -178,25 +177,5 @@ private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyLi
178177

179178
return new PSCommand().AddScript(sb.ToString());
180179
}
181-
182-
private static bool ArgumentNeedsEscaping(string argument)
183-
{
184-
foreach (char c in argument)
185-
{
186-
switch (c)
187-
{
188-
case '\'':
189-
case '"':
190-
case '|':
191-
case '&':
192-
case ';':
193-
case ':':
194-
case char w when char.IsWhiteSpace(w):
195-
return true;
196-
}
197-
}
198-
199-
return false;
200-
}
201180
}
202181
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Microsoft.PowerShell.EditorServices.Utility
6+
{
7+
internal static class StringEscaping
8+
{
9+
public static StringBuilder SingleQuoteAndEscape(string s)
10+
{
11+
return new StringBuilder(s.Length)
12+
.Append("'")
13+
.Append(s.Replace("'", "''"))
14+
.Append("'");
15+
}
16+
17+
public static bool PowerShellArgumentNeedsEscaping(string argument)
18+
{
19+
foreach (char c in argument)
20+
{
21+
switch (c)
22+
{
23+
case '\'':
24+
case '"':
25+
case '|':
26+
case '&':
27+
case ';':
28+
case ':':
29+
case char w when char.IsWhiteSpace(w):
30+
return true;
31+
}
32+
}
33+
34+
return false;
35+
}
36+
}
37+
}

test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
2525
using Microsoft.PowerShell.EditorServices.Logging;
2626
using Microsoft.PowerShell.EditorServices.Services.Configuration;
27+
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
28+
using Microsoft.PowerShell.EditorServices.Services.Template;
2729

2830
namespace PowerShellEditorServices.Test.E2E
2931
{

test/PowerShellEditorServices.Test/Console/ChoicePromptHandlerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using Microsoft.Extensions.Logging.Abstractions;
7-
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
87
using Xunit;
98

109
namespace Microsoft.PowerShell.EditorServices.Test.Console
1110
{
11+
/*
1212
public class ChoicePromptHandlerTests
1313
{
1414
private readonly ChoiceDetails[] Choices =
@@ -121,5 +121,6 @@ protected override void ShowPrompt(PromptStyle promptStyle)
121121
this.TimesPrompted++;
122122
}
123123
}
124+
*/
124125
}
125126

test/PowerShellEditorServices.Test/Console/InputPromptHandlerTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System;
99
using System.Threading;
1010
using System.Security;
11-
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
1211
using Microsoft.Extensions.Logging.Abstractions;
1312

1413
namespace Microsoft.PowerShell.EditorServices.Test.Console

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.IO;
78
using System.Linq;
89
using System.Management.Automation;
910
using System.Threading;
1011
using System.Threading.Tasks;
12+
using MediatR;
1113
using Microsoft.Extensions.Logging.Abstractions;
1214
using Microsoft.PowerShell.EditorServices.Services;
1315
using Microsoft.PowerShell.EditorServices.Services.DebugAdapter;
14-
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
16+
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
17+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
1518
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
1619
using Microsoft.PowerShell.EditorServices.Test.Shared;
17-
using Microsoft.PowerShell.EditorServices.Utility;
20+
using Newtonsoft.Json.Linq;
21+
using OmniSharp.Extensions.JsonRpc;
22+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
23+
using OmniSharp.Extensions.LanguageServer.Protocol.Progress;
24+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1825
using Xunit;
1926

2027
namespace Microsoft.PowerShell.EditorServices.Test.Debugging
2128
{
29+
/*
2230
public class DebugServiceTests : IDisposable
2331
{
2432
private WorkspaceService workspace;
2533
private DebugService debugService;
2634
private ScriptFile debugScriptFile;
2735
private ScriptFile variableScriptFile;
28-
private PowerShellContextService powerShellContext;
29-
30-
private AsyncQueue<DebuggerStoppedEventArgs> debuggerStoppedQueue =
31-
new AsyncQueue<DebuggerStoppedEventArgs>();
32-
private AsyncQueue<SessionStateChangedEventArgs> sessionStateQueue =
33-
new AsyncQueue<SessionStateChangedEventArgs>();
3436
3537
private ScriptFile GetDebugScript(string fileName)
3638
{
@@ -44,6 +46,8 @@ private ScriptFile GetDebugScript(string fileName)
4446
4547
public DebugServiceTests()
4648
{
49+
var loggerFactory = new NullLoggerFactory();
50+
4751
var logger = NullLogger.Instance;
4852
4953
this.powerShellContext = PowerShellContextFactory.Create(logger);
@@ -1067,4 +1071,5 @@ await this.powerShellContext.ExecuteCommandAsync<LineBreakpoint>(
10671071
.AddParameter("Script", scriptFile.FilePath)).ConfigureAwait(false);
10681072
}
10691073
}
1074+
*/
10701075
}

test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace Microsoft.PowerShell.EditorServices.Test.Language
2828
{
29+
/*
2930
public class LanguageServiceTests : IDisposable
3031
{
3132
private readonly WorkspaceService workspace;
@@ -526,4 +527,5 @@ private List<SymbolReference> FindSymbolsInFile(ScriptRegion scriptRegion)
526527
GetScriptFile(scriptRegion));
527528
}
528529
}
530+
*/
529531
}

test/PowerShellEditorServices.Test/PowerShellContextFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
using Microsoft.Extensions.Logging.Abstractions;
1212
using Microsoft.PowerShell.EditorServices.Hosting;
1313
using Microsoft.PowerShell.EditorServices.Services;
14-
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
1514
using Microsoft.PowerShell.EditorServices.Test.Shared;
1615
using Microsoft.PowerShell.EditorServices.Utility;
1716

1817
namespace Microsoft.PowerShell.EditorServices.Test
1918
{
19+
/*
2020
internal static class PowerShellContextFactory
2121
{
2222
// NOTE: These paths are arbitrarily chosen just to verify that the profile paths
@@ -122,4 +122,5 @@ protected override void UpdateProgress(long sourceId, ProgressDetails progressDe
122122
{
123123
}
124124
}
125+
*/
125126
}

0 commit comments

Comments
 (0)