Skip to content

CommandAppTester is trimming TestConsole output, requiring expected outputs to be manually adjusted #1738

Closed
@FrankRay78

Description

@FrankRay78

Information

  • OS: Windows 10
  • Version: Spectre.Console 0.49.1, XUnit 2.9.3
  • Terminal: Windows Terminal

Describe the bug
CommandAppTester is trimming TestConsole output, requiring expected outputs to be manually adjusted.

To Reproduce
Run the below, self-contained, unit test:

using Spectre.Console;
using Spectre.Console.Cli;
using Spectre.Console.Testing;
using Xunit;


public class HelloCommand : Command
{
    private IAnsiConsole console;

    public HelloCommand(IAnsiConsole console)
    {
        this.console = console;
    }

    public override int Execute(CommandContext context)
    {
        console.Write(
            new FigletText(" -- Hello -- ")
                //.Centered()
                .Color(Color.Red));

        return 0;
    }
}

public class Tests
{
    [Fact]
    public void Should_Output_Centered_FigletText()
    {
        // Given
        var app = new CommandAppTester();
        app.Configure(config => config.PropagateExceptions());

        app.SetDefaultCommand<HelloCommand>();

        // When
        var result = app.Run();

        // Then
        Assert.Equal(0, result.ExitCode);
    }
}

Expected behavior
Whitespace is trimmed from the TestConsole output (see screenshot below)

Screenshots

Image

Additional context
Here is the culprit:

Image

nb. I don't see a good reason for the literal command output to be manipulated after the command has executed (please tell me if you know why this is necessary). We saw a similar thing happening in the CLI command parser stripping out whitespace, which we eventually abandoned because it was causing inaccurate discarding of whitespace.


Please upvote 👍 this issue if you are interested in it.

Metadata

Metadata

Assignees

Labels

area-Testing-FrameworkSpectre.Console testing framework for developers.bugSomething isn't working

Type

Projects

  • Status

    Done 🚀

Relationships

None yet

Development

No branches or pull requests

Issue actions