Skip to content

passed/failed/skipped {TestDisplayName} interprets escape characters #5133

Closed

Description

Publishing a test node with a display name containing an escape character causes it to be escaped in the console output also.

internal class DummyAdapter : ITestFramework, IDataProducer
{
    public string Uid => nameof(DummyAdapter);

    public string Version => string.Empty;

    public string DisplayName => string.Empty;

    public string Description => string.Empty;

    public Type[] DataTypesProduced => [typeof(TestNodeUpdateMessage)];

    public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) => Task.FromResult(new CloseTestSessionResult { IsSuccess = true });

    public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context) => Task.FromResult(new CreateTestSessionResult { IsSuccess = true });

    public async Task ExecuteRequestAsync(ExecuteRequestContext context)
    {
        for (int i = 0; i < 15; i++)
        {
            await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(new SessionUid("1"), new TestNode
            {
                Uid = $"{i}",
                DisplayName = $"Hello(\nWorld {i})",
                Properties = new PropertyBag(GetRandomState())
            }));
        }
     
        context.Complete();
    }

    private static IProperty GetRandomState()
    {
        IProperty[] states = [ PassedTestNodeStateProperty.CachedInstance, SkippedTestNodeStateProperty.CachedInstance, new FailedTestNodeStateProperty("Oops") ];
        
        Random.Shared.Shuffle(states);

        return states.First();
    }

    public Task<bool> IsEnabledAsync() => Task.FromResult(true);
}

dotnet run --output Detailed

Results in:

Image

These should probably be shown literally to avoid weird console display

Activity

  1. added
    area/mtp
    on Feb 26, 2025
  2. added
    type/discussion
    and removed
    needs/triage
    on Feb 26, 2025
  3. nohwnd commented on Feb 26, 2025

    @nohwnd
    Member

    We need to replace them with their control pictures ( https://github.com/pester/Pester/pull/2615/files#diff-d46236d014c39e3384c78b140721e505d4cba4bea2ac0a65d3e4471e541ae144R66 ), like we do in few places in tests, especially the ESC character, which has the potential to break all our output. We also need to think about which special chars to replace where, replacing newline in test name is probably good idea, but not a good idea to do that in assertion output.

    And also should this be done on the platform level, or we leave it up to the frameworks to handle it?

    And last consideration, special chars (like 0x00) break XML, so we probably should always replace offending characters in TRX.

    For discussion:

    • because this has potentially big impact on perf (since we basically need to touch all strings, and probably want to escape then earlier rather than later to do it as few times as possible. What is the best way to replace the chars with least overhead?

    • And because we need to decide if this should be done on platform level.

  4. thomhurst commented on Feb 26, 2025

    @thomhurst
    ContributorAuthor

    And also should this be done on the platform level, or we leave it up to the frameworks to handle it?

    For this specific scenario I reckon so - Because MTP is the part spitting out that line, so makes sense for you to handle the formatting of it too imo. Also means it's consistent across frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/mtptype/discussion

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions