Skip to content

Test outputs are corrupted in TerminalLogger in some scenarios #15268

@baronfel

Description

@baronfel

(This is a manual transfer of dotnet/msbuild#12433)

Issue Description

The live logger is somehow corrupting the output of dotnet test, turning ~ characters into _ characters, but not all of them 🙃.

Steps to Reproduce

Repro

  1. dotnet new xunit (I haven't tried other frameworks to know whether this is xunit specific).
  2. Add the following test:
    [Fact]
    public void Test1()
    {
            var tildeString = new string('~', 5);
            Console.WriteLine($"String length: {tildeString.Length}");
            Console.WriteLine($"Each char code: {string.Join(", ", tildeString.Select(c => (int)c))}");
            Console.WriteLine($"Hex dump: {BitConverter.ToString(System.Text.Encoding.UTF8.GetBytes(tildeString))}");
            Console.WriteLine($"String: {tildeString}");
            Assert.True(false, tildeString);
    }

Live logger disabled

When run as MSBUILDLIVELOGGER=false dotnet test (or the equivalent powershell), the following output happens:

➜ MSBUILDLIVELOGGER=false dotnet test
  Determining projects to restore...
  All projects are up-to-date for restore.
/home/fred/.local/share/dnvm/dn/sdk/10.0.100-preview.6.25358.103/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(335,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/tmp/test-vb/test-cs/test-cs.csproj]
  test-cs -> /tmp/test-cs/bin/Debug/net10.0/test-cs.dll
Test run for /tmp/test-cs/bin/Debug/net10.0/test-cs.dll (.NETCoreApp,Version=v10.0)
VSTest version 17.15.0-preview-25358-103 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.11]     test_cs.UnitTest1.Test1 [FAIL]
  Failed test_cs.UnitTest1.Test1 [6 ms]
  Error Message:
   ~~~~~
  Stack Trace:
     at test_cs.UnitTest1.Test1() in /tmp/test-cs/UnitTest1.cs:line 13
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: 6 ms - test-cs.dll (net10.0)

Live logger enabled

When run as MSBUILDLIVELOGGER=true dotnet test (or the equivalent powershell), this output is received. Note the ____~ strings:

➜ MSBUILDLIVELOGGER=true dotnet test                    
Restore complete (0.4s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  test-cs succeeded with 1 warning(s) (1.8s) → bin/Debug/net10.0/test-cs.dll
    /tmp/test-vb/test-cs/UnitTest1.cs(13,13): warning xUnit2020: Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0-preview.6.25358.103)
[xUnit.net 00:00:00.04]   Discovering: test-cs
[xUnit.net 00:00:00.07]   Discovered:  test-cs
[xUnit.net 00:00:00.07]   Starting:    test-cs
String length: 5
Each char code: 126, 126, 126, 126, 126
Hex dump: 7E-7E-7E-7E-7E
String: ____~
[xUnit.net 00:00:00.11]     test_cs.UnitTest1.Test1 [FAIL]
[xUnit.net 00:00:00.11]       ____~
[xUnit.net 00:00:00.11]       Stack Trace:
[xUnit.net 00:00:00.11]         /tmp/test-vb/test-cs/UnitTest1.cs(13,0): at test_cs.UnitTest1.Test1()
[xUnit.net 00:00:00.11]            at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
[xUnit.net 00:00:00.11]            at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
[xUnit.net 00:00:00.12]   Finished:    test-cs
  test-cs test failed with 1 error(s) (0.6s)
    /tmp/test-vb/test-cs/UnitTest1.cs(13): error TESTERROR: 
      test_cs.UnitTest1.Test1 (6ms): Error Message: ____~
      Stack Trace:
         at test_cs.UnitTest1.Test1() in /tmp/test-vb/test-cs/UnitTest1.cs:line 13
         at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
         at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Test summary: total: 1, failed: 1, succeeded: 0, skipped: 0, duration: 0.6s
Build failed with 1 error(s) and 1 warning(s) in 3.0s

Analysis

No response

Versions & Configurations

I've reproduced this on various versions between 9.0.106 and 10p7, on bash and zsh (Ubuntu 24.04) and powershell (Windows 11). I was unable to reproduce this on any version of .NET 8 that I tried. I also tested a few other characters, and did not see any other corruption.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions