PowerShellEditorServices
PowerShellEditorServices copied to clipboard
Add regression test for ANSI escape bug
Hm, well this is as far as I got with the test and I think I'm going to postpone getting a test for this so we can just get the fix in:
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Threading;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
using Xunit;
namespace Microsoft.PowerShell.EditorServices.Test.Console
{
public class PSHostTests : IDisposable
{
private readonly PsesInternalHost _psesHost;
public PSHostTests()
{
_psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance);
}
public void Dispose()
{
_psesHost.StopAsync().GetAwaiter().GetResult();
}
[Trait("Category", "LengthInBufferCells")]
[Fact]
public void HasLengthInBufferCells()
{
var script = @"[pscustomobject]@{ a = ""`e[30mtest`e[0m"" } | Format-Table @{ Width = 4; Expression = 'a' } | Out-Default";
IReadOnlyList<string> results = _psesHost.InvokePSCommand<string>(
new PSCommand().AddScript(script),
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, ThrowOnError = false, InterruptCurrentForeground = true },
CancellationToken.None);
Assert.NotEmpty(results);
}
}
}
Originally posted by @andschwa in https://github.com/PowerShell/PowerShellEditorServices/issues/1606#issuecomment-959910355
The missing piece is a test PSHost
that inherits EditorServicesConsolePSHost
and overwrites WriteLine
to something that just adds to a StringBuilder
.
Ah! _psesHost
has a host that is EditorServicesConsolePSHost
. I'll try to create a test harness that does what you say.