Skip to content
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

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

Open
FrankRay78 opened this issue Jan 18, 2025 · 0 comments
Labels
area-Testing-Framework Spectre.Console testing framework for developers. bug Something isn't working needs triage

Comments

@FrankRay78
Copy link
Contributor

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 👍 this issue if you are interested in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Testing-Framework Spectre.Console testing framework for developers. bug Something isn't working needs triage
Projects
Status: Todo 🕑
Development

No branches or pull requests

1 participant