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

Set encoding in console to UTF8 #2491

Open
nohwnd opened this issue Mar 1, 2024 · 5 comments
Open

Set encoding in console to UTF8 #2491

nohwnd opened this issue Mar 1, 2024 · 5 comments
Labels
Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library Discussion Resolution: By Design

Comments

@nohwnd
Copy link
Member

nohwnd commented Mar 1, 2024

Describe the bug

Frameworks or users might use utf8 characters in their output messages. Set console encoding to utf8 (as we do in vstest.console, and as xunit.console does). microsoft/vstest#4605

Optionally put this under environment variable feature flag.

Steps To Reproduce

image

<!-- file mstest108.csproj -->
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
    <EnableMSTestRunner>true</EnableMSTestRunner>
    <OutputType>Exe</OutputType>
    <GenerateTestingPlatformEntryPoint>false</GenerateTestingPlatformEntryPoint>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MSTest" Version="3.2.0" />
    <PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.10.1" />
  </ItemGroup>

  <ItemGroup>
    <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
  </ItemGroup>

</Project>
// file MSTestSettings.cs
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
// file UnitTest1.cs
namespace mstest108;

using Microsoft.Testing.Platform;
using Microsoft.Testing;
using Microsoft.Testing.Framework;
using Microsoft.Testing.Platform.Builder;

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        Console.OutputEncoding = System.Text.Encoding.UTF8;
        Assert.AreEqual("a", "🤨😘");
    }
}


public static class Program {
    public static async Task<int> Main(string[] args)  {

        Console.OutputEncoding = System.Text.Encoding.UTF8;
                ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args);
        Microsoft.Testing.Platform.MSBuild.TestingPlatformBuilderHook.AddExtensions(builder, args);
        Microsoft.Testing.Extensions.Telemetry.TestingPlatformBuilderHook.AddExtensions(builder, args);
        Microsoft.VisualStudio.TestTools.UnitTesting.TestingPlatformBuilderHook.AddExtensions(builder, args);
        Microsoft.Testing.Extensions.CodeCoverage.TestingPlatformBuilderHook.AddExtensions(builder, args);
        using ITestApplication app = await builder.BuildAsync();
        return await app.RunAsync();
    }
}

mstest108.zip

Expected behavior

I can see the smileys.

Actual behavior

I see ??

Additional context

@MarcoRossignoli
Copy link
Contributor

MarcoRossignoli commented Mar 1, 2024

I don't think it's a bug...we don't do nothing and we use the default of the platform.

I think that the adapter should take this responsibility as platform we don't own or know nothing about "what" the plugged testing platform does...it could not send messages to the output device at all.

Another idea can be if we think that's a good "default" for our default console "set by default" utf-8 and provide some "command line args" to change it to something else like '--console-output-encoding xxx'

Waiting for @Evangelink thought

@Evangelink
Copy link
Member

Evangelink commented Mar 2, 2024

Another idea can be if we think that's a good "default" for our default console "set by default" utf-8 and provide some "command line args" to change it to something else like '--console-output-encoding xxx'

Haven't put much thoughts but this seems the best. A "good" default and an easy way to change it.

I don't know how busy is the sprint but if there is some room for it, I would try to work on it for 3.4 (not sure if you already did the feature complete preview release for 3.3).

@nohwnd
Copy link
Member Author

nohwnd commented Mar 4, 2024

I don't think this can be purely testing framework concern. The encoding needs to align with msbuild integration for dotnet test, if we want to transport the standard output data correctly, otherwise we are losing encoding and information. This is not so painful for english speaking countries, where utf-8 is mostly used in form of emojis that are rarely used in test names and output, but without this we will be breaking chinese and other characters.

@MarcoRossignoli
Copy link
Contributor

The encoding needs to align with msbuild integration for dotnet test, if we want to transport the standard output data correctly, otherwise we are losing encoding and information.

Yep, this needs to be followed also for "custom" possible output display in case.

@Evangelink
Copy link
Member

The encoding needs to align with msbuild integration for dotnet test

Seems like having an option to change the encoding and having dotnet test logic calling this option based on current msbuild setting is the logical split. Platform allows to change console encoding and dotnet test that is aware of MSBuild sets the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library Discussion Resolution: By Design
Projects
None yet
Development

No branches or pull requests

3 participants