Skip to content

Replace Pester tests with xunit tests #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
35 changes: 7 additions & 28 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ $script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "C
$script:TargetPlatform = "netstandard2.0"
$script:TargetFrameworksParam = "/p:TargetFrameworks=`"$script:TargetPlatform`""
$script:RequiredSdkVersion = (Get-Content (Join-Path $PSScriptRoot 'global.json') | ConvertFrom-Json).sdk.version
$script:MinimumPesterVersion = '4.7'
$script:NugetApiUriBase = 'https://www.nuget.org/api/v2/package'
$script:ModuleBinPath = "$PSScriptRoot/module/PowerShellEditorServices/bin/"
$script:VSCodeModuleBinPath = "$PSScriptRoot/module/PowerShellEditorServices.VSCode/bin/"
Expand Down Expand Up @@ -173,7 +172,7 @@ function Invoke-WithCreateDefaultHook {
}
}

task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, PackageNuGet {
task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestE2E, PackageNuGet {

$dotnetPath = "$PSScriptRoot/.dotnet"
$dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }
Expand Down Expand Up @@ -324,18 +323,13 @@ task Build {
exec { & $script:dotnetExe build -c $Configuration .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj $script:TargetFrameworksParam }
}

task BuildPsesClientModule SetupDotNet,{
Write-Verbose 'Building PsesPsClient testing module'
& $PSScriptRoot/tools/PsesPsClient/build.ps1 -DotnetExe $script:dotnetExe
}

function DotNetTestFilter {
# Reference https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
if ($TestFilter) { @("--filter",$TestFilter) } else { "" }
}

# task Test TestServer,TestProtocol,TestPester
task Test TestPester
# task Test TestServer,TestProtocol,TestE2E
task Test TestE2E

task TestServer {
Set-Location .\test\PowerShellEditorServices.Test\
Expand Down Expand Up @@ -373,26 +367,11 @@ task TestHost {
exec { & $script:dotnetExe test -f $script:TestRuntime.Core (DotNetTestFilter) }
}

task TestPester Build,BuildPsesClientModule,EnsurePesterInstalled,{
$testParams = @{}
if ($env:TF_BUILD)
{
$testParams += @{
OutputFormat = 'NUnitXml'
OutputFile = 'TestResults.xml'
}
}
$result = Invoke-Pester "$PSScriptRoot/test/Pester/" @testParams -PassThru

if ($result.FailedCount -gt 0)
{
throw "$($result.FailedCount) tests failed."
}
}
task TestE2E {
Set-Location .\test\PowerShellEditorServices.Test.E2E\

task EnsurePesterInstalled -If (-not (Get-Module Pester -ListAvailable | Where-Object Version -ge $script:MinimumPesterVersion)) {
Write-Warning "Required Pester version not found, installing Pester to current user scope"
Install-Module -Scope CurrentUser Pester -Force -SkipPublisherCheck
$env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" }
exec { & $script:dotnetExe test --logger trx -f $script:TestRuntime.Core (DotNetTestFilter) }
}

task LayoutModule -After Build {
Expand Down
15 changes: 15 additions & 0 deletions PowerShellEditorServices.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellEditorServices.VS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerShellEditorServices.Engine", "src\PowerShellEditorServices.Engine\PowerShellEditorServices.Engine.csproj", "{29EEDF03-0990-45F4-846E-2616970D1FA2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerShellEditorServices.Test.E2E", "test\PowerShellEditorServices.Test.E2E\PowerShellEditorServices.Test.E2E.csproj", "{2561F253-8F72-436A-BCC3-AA63AB82EDC0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -148,6 +150,18 @@ Global
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x64.Build.0 = Release|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x86.ActiveCfg = Release|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x86.Build.0 = Release|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Debug|x64.ActiveCfg = Debug|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Debug|x64.Build.0 = Debug|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Debug|x86.ActiveCfg = Debug|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Debug|x86.Build.0 = Debug|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Release|Any CPU.Build.0 = Release|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Release|x64.ActiveCfg = Release|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Release|x64.Build.0 = Release|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Release|x86.ActiveCfg = Release|Any CPU
{2561F253-8F72-436A-BCC3-AA63AB82EDC0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -162,5 +176,6 @@ Global
{E3A5CF5D-6E41-44AC-AE0A-4C227E4BACD4} = {422E561A-8118-4BE7-A54F-9309E4F03AAE}
{3B38E8DA-8BFF-4264-AF16-47929E6398A3} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
{29EEDF03-0990-45F4-846E-2616970D1FA2} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
{2561F253-8F72-436A-BCC3-AA63AB82EDC0} = {422E561A-8118-4BE7-A54F-9309E4F03AAE}
EndGlobalSection
EndGlobal
55 changes: 37 additions & 18 deletions src/PowerShellEditorServices.Engine/Hosting/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Extensions;
using Microsoft.PowerShell.EditorServices.Host;
using Serilog;

namespace Microsoft.PowerShell.EditorServices.Engine
Expand Down Expand Up @@ -234,13 +235,15 @@ public void StartLanguageService(

_logger.LogInformation($"LSP NamedPipe: {config.InOutPipeName}\nLSP OutPipe: {config.OutPipeName}");

var powerShellContext = GetFullyInitializedPowerShellContext(profilePaths);

_serviceCollection
.AddSingleton<WorkspaceService>()
.AddSingleton<SymbolsService>()
.AddSingleton<ConfigurationService>()
.AddSingleton<PowerShellContextService>(powerShellContext)
.AddSingleton<PowerShellContextService>(
(provider) =>
GetFullyInitializedPowerShellContext(
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
profilePaths))
.AddSingleton<EditorOperationsService>()
.AddSingleton<ExtensionService>(
(provider) =>
Expand All @@ -263,14 +266,29 @@ public void StartLanguageService(
_factory.CreateLogger<AnalysisService>());
});

_languageServer = new OmnisharpLanguageServerBuilder(_serviceCollection)
switch (config.TransportType)
{
NamedPipeName = config.InOutPipeName ?? config.InPipeName,
OutNamedPipeName = config.OutPipeName,
LoggerFactory = _factory,
MinimumLogLevel = LogLevel.Trace,
case EditorServiceTransportType.NamedPipe:
_languageServer = new OmnisharpLanguageServerBuilder(_serviceCollection)
{
NamedPipeName = config.InOutPipeName ?? config.InPipeName,
OutNamedPipeName = config.OutPipeName,
LoggerFactory = _factory,
MinimumLogLevel = LogLevel.Trace,
}
.BuildLanguageServer();
break;

case EditorServiceTransportType.Stdio:
_languageServer = new OmnisharpLanguageServerBuilder(_serviceCollection)
{
Stdio = true,
LoggerFactory = _factory,
MinimumLogLevel = LogLevel.Trace,
}
.BuildLanguageServer();
break;
}
.BuildLanguageServer();

_logger.LogInformation("Starting language server");

Expand All @@ -282,21 +300,22 @@ public void StartLanguageService(
config.TransportType, config.Endpoint));
}

private PowerShellContextService GetFullyInitializedPowerShellContext(ProfilePaths profilePaths)
private PowerShellContextService GetFullyInitializedPowerShellContext(
OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer languageServer,
ProfilePaths profilePaths)
{
var logger = _factory.CreateLogger<PowerShellContextService>();

// PSReadLine can only be used when -EnableConsoleRepl is specified otherwise
// issues arise when redirecting stdio.
var powerShellContext = new PowerShellContextService(
logger,
_featureFlags.Contains("PSReadLine"));
_featureFlags.Contains("PSReadLine") && _enableConsoleRepl);

// TODO: Bring this back
//EditorServicesPSHostUserInterface hostUserInterface =
// _enableConsoleRepl
// ? (EditorServicesPSHostUserInterface)new TerminalPSHostUserInterface(powerShellContext, logger, _internalHost)
// : new ProtocolPSHostUserInterface(powerShellContext, messageSender, logger);
EditorServicesPSHostUserInterface hostUserInterface =
new TerminalPSHostUserInterface(powerShellContext, logger, _internalHost);

_enableConsoleRepl
? (EditorServicesPSHostUserInterface) new TerminalPSHostUserInterface(powerShellContext, logger, _internalHost)
: new ProtocolPSHostUserInterface(languageServer, powerShellContext, logger);

EditorServicesPSHost psHost =
new EditorServicesPSHost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System.IO;
using System.IO.Pipes;
using System.Reflection;
using System.Threading.Tasks;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Threading.Tasks;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OS = OmniSharp.Extensions.LanguageServer.Server;
using System.Security.AccessControl;
using Microsoft.PowerShell.EditorServices.TextDocument;
using OmniSharp.Extensions.LanguageServer.Server;
using OS = OmniSharp.Extensions.LanguageServer.Server;
using PowerShellEditorServices.Engine.Services.Handlers;
using Microsoft.PowerShell.EditorServices.TextDocument;
using System.IO;

namespace Microsoft.PowerShell.EditorServices.Engine
{
public class OmnisharpLanguageServer : ILanguageServer
{
public class Configuration
{
public bool Stdio { get; set; }

public string NamedPipeName { get; set; }

public string OutNamedPipeName { get; set; }
Expand Down Expand Up @@ -58,24 +61,33 @@ public OmnisharpLanguageServer(
public async Task StartAsync()
{
_languageServer = await OS.LanguageServer.From(options => {
NamedPipeServerStream namedPipe = CreateNamedPipe(
_configuration.NamedPipeName,
_configuration.OutNamedPipeName,
out NamedPipeServerStream outNamedPipe);

ILogger logger = options.LoggerFactory.CreateLogger("OptionsStartup");

logger.LogInformation("Waiting for connection");
namedPipe.WaitForConnection();
if (outNamedPipe != null)
if (_configuration.Stdio)
{
outNamedPipe.WaitForConnection();
options.WithInput(System.Console.OpenStandardInput());
options.WithOutput(System.Console.OpenStandardOutput());
}
else
{
NamedPipeServerStream namedPipe = CreateNamedPipe(
_configuration.NamedPipeName,
_configuration.OutNamedPipeName,
out NamedPipeServerStream outNamedPipe);

logger.LogInformation("Connected");
logger.LogInformation("Waiting for connection");
namedPipe.WaitForConnection();
if (outNamedPipe != null)
{
outNamedPipe.WaitForConnection();
}

options.Input = namedPipe;
options.Output = outNamedPipe ?? namedPipe;
logger.LogInformation("Connected");

options.Input = namedPipe;
options.Output = outNamedPipe ?? namedPipe;
}

options.LoggerFactory = _configuration.LoggerFactory;
options.MinimumLogLevel = _configuration.MinimumLogLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public OmnisharpLanguageServerBuilder(IServiceCollection serviceCollection)
Services = serviceCollection;
}

public bool Stdio { get; set; }

public string NamedPipeName { get; set; }

public string OutNamedPipeName { get; set; }
Expand All @@ -28,7 +30,8 @@ public ILanguageServer BuildLanguageServer()
MinimumLogLevel = MinimumLogLevel,
NamedPipeName = NamedPipeName,
OutNamedPipeName = OutNamedPipeName,
Services = Services
Services = Services,
Stdio = Stdio
};

return new OmnisharpLanguageServer(config);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

namespace Microsoft.PowerShell.EditorServices.Protocol.Messages
{
public class ShowChoicePromptRequest
{
public bool IsMultiChoice { get; set; }

public string Caption { get; set; }

public string Message { get; set; }

public ChoiceDetails[] Choices { get; set; }

public int[] DefaultChoices { get; set; }
}

public class ShowChoicePromptResponse
{
public bool PromptCancelled { get; set; }

public string ResponseText { get; set; }
}

public class ShowInputPromptRequest
{
/// <summary>
/// Gets or sets the name of the field.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the descriptive label for the field.
/// </summary>
public string Label { get; set; }
}

public class ShowInputPromptResponse
{
public bool PromptCancelled { get; set; }

public string ResponseText { get; set; }
}
}

Loading