spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Center aligned FigletText throws System.OutOfMemoryException exception when run with CommandAppTester

Open FrankRay78 opened this issue 10 months ago • 0 comments

Information

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

Describe the bug Center aligned FigletText throws System.OutOfMemoryException when run with CommandAppTester.

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 Should output centered FigletText ie:

[xUnit.net 00:00:00.13]   Starting:    ConsoleApp1
                          _   _          _   _         
                         | | | |   ___  | | | |   ___  
                         | |_| |  / _ \ | | | |  / _ \ 
                         |  _  | |  __/ | | | | | (_) |
                         |_| |_|  \___| |_| |_|  \___/ 
[xUnit.net 00:00:00.21]   Finished:    ConsoleApp1

The following test that uses AnsiConsole executes correctly FYI:

    public void Should_Output_Centered_FigletText()
    {
        AnsiConsole.Write(
            new FigletText("Hello")
                .Centered()
                .Color(Color.Red));
     }

Screenshots

Image

Additional context The following line in CommandAppTester is the culprit:

Image

Which overrides the TestConsole default of 80 lines:

Image

And causes the out of memory exception in RenderableExtensions.cs:

Image


Please upvote :+1: this issue if you are interested in it.

FrankRay78 avatar Jan 18 '25 15:01 FrankRay78