Skip to content

Commit

Permalink
Initial test build
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmholt committed Oct 28, 2021
1 parent 16cd6c4 commit 8c568bc
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 356 deletions.
153 changes: 0 additions & 153 deletions integrated.sln

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,16 @@ private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyLi

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

foreach (string arg in arguments)
{
sb.Append(' ');

if (ArgumentNeedsEscaping(arg))
if (StringEscaping.PowerShellArgumentNeedsEscaping(arg))
{
sb.Append('\'').Append(arg.Replace("'", "''")).Append('\'');
sb.Append(StringEscaping.SingleQuoteAndEscape(arg));
}
else
{
Expand All @@ -178,25 +177,5 @@ private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyLi

return new PSCommand().AddScript(sb.ToString());
}

private static bool ArgumentNeedsEscaping(string argument)
{
foreach (char c in argument)
{
switch (c)
{
case '\'':
case '"':
case '|':
case '&':
case ';':
case ':':
case char w when char.IsWhiteSpace(w):
return true;
}
}

return false;
}
}
}
37 changes: 37 additions & 0 deletions src/PowerShellEditorServices/Utility/StringEscaping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.PowerShell.EditorServices.Utility
{
internal static class StringEscaping
{
public static StringBuilder SingleQuoteAndEscape(string s)
{
return new StringBuilder(s.Length)
.Append("'")
.Append(s.Replace("'", "''"))
.Append("'");
}

public static bool PowerShellArgumentNeedsEscaping(string argument)
{
foreach (char c in argument)
{
switch (c)
{
case '\'':
case '"':
case '|':
case '&':
case ';':
case ':':
case char w when char.IsWhiteSpace(w):
return true;
}
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
using Microsoft.PowerShell.EditorServices.Logging;
using Microsoft.PowerShell.EditorServices.Services.Configuration;
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
using Microsoft.PowerShell.EditorServices.Services.Template;

namespace PowerShellEditorServices.Test.E2E
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using Xunit;

namespace Microsoft.PowerShell.EditorServices.Test.Console
{
/*
public class ChoicePromptHandlerTests
{
private readonly ChoiceDetails[] Choices =
Expand Down Expand Up @@ -121,5 +121,6 @@ protected override void ShowPrompt(PromptStyle promptStyle)
this.TimesPrompted++;
}
}
*/
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System;
using System.Threading;
using System.Security;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using Microsoft.Extensions.Logging.Abstractions;

namespace Microsoft.PowerShell.EditorServices.Test.Console
Expand Down
21 changes: 13 additions & 8 deletions test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,36 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.DebugAdapter;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Microsoft.PowerShell.EditorServices.Test.Shared;
using Microsoft.PowerShell.EditorServices.Utility;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Progress;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using Xunit;

namespace Microsoft.PowerShell.EditorServices.Test.Debugging
{
/*
public class DebugServiceTests : IDisposable
{
private WorkspaceService workspace;
private DebugService debugService;
private ScriptFile debugScriptFile;
private ScriptFile variableScriptFile;
private PowerShellContextService powerShellContext;

private AsyncQueue<DebuggerStoppedEventArgs> debuggerStoppedQueue =
new AsyncQueue<DebuggerStoppedEventArgs>();
private AsyncQueue<SessionStateChangedEventArgs> sessionStateQueue =
new AsyncQueue<SessionStateChangedEventArgs>();
private ScriptFile GetDebugScript(string fileName)
{
Expand All @@ -44,6 +46,8 @@ private ScriptFile GetDebugScript(string fileName)
public DebugServiceTests()
{
var loggerFactory = new NullLoggerFactory();
var logger = NullLogger.Instance;
this.powerShellContext = PowerShellContextFactory.Create(logger);
Expand Down Expand Up @@ -1067,4 +1071,5 @@ await this.powerShellContext.ExecuteCommandAsync<LineBreakpoint>(
.AddParameter("Script", scriptFile.FilePath)).ConfigureAwait(false);
}
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace Microsoft.PowerShell.EditorServices.Test.Language
{
/*
public class LanguageServiceTests : IDisposable
{
private readonly WorkspaceService workspace;
Expand Down Expand Up @@ -526,4 +527,5 @@ private List<SymbolReference> FindSymbolsInFile(ScriptRegion scriptRegion)
GetScriptFile(scriptRegion));
}
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Hosting;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using Microsoft.PowerShell.EditorServices.Test.Shared;
using Microsoft.PowerShell.EditorServices.Utility;

namespace Microsoft.PowerShell.EditorServices.Test
{
/*
internal static class PowerShellContextFactory
{
// NOTE: These paths are arbitrarily chosen just to verify that the profile paths
Expand Down Expand Up @@ -122,4 +122,5 @@ protected override void UpdateProgress(long sourceId, ProgressDetails progressDe
{
}
}
*/
}
Loading

0 comments on commit 8c568bc

Please sign in to comment.