Skip to content

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

@thomhurst

Description

@thomhurst

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

Metadata

Metadata

Assignees

Labels

Area: MTPBelongs to the Microsoft.Testing.Platform core libraryDiscussion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions