Skip to content

Commit

Permalink
Fix analyzer messages not localized (#4434)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 authored Dec 23, 2024
1 parent d0e61e2 commit 2564c52
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion eng/verify-nupkgs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Confirm-NugetPackages {
"MSTest.TestFramework" = 148;
"MSTest.TestAdapter" = 74;
"MSTest" = 6;
"MSTest.Analyzers" = 10;
"MSTest.Analyzers" = 50;
}

$packageDirectory = Resolve-Path "$PSScriptRoot/../artifacts/packages/$configuration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@

<Target Name="_AddAnalyzersToOutput">
<ItemGroup>
<!-- Analyzer works for both C# and VB.NET -->
<TfmSpecificPackageFile Include="$(OutputPath)\MSTest.Analyzers.dll" PackagePath="analyzers/dotnet" />
<!-- This code fix is C# specific -->
<TfmSpecificPackageFile Include="$(OutputPath)\MSTest.Analyzers.dll" PackagePath="analyzers/dotnet/cs" />
<TfmSpecificPackageFile Include="$(OutputPath)\MSTest.Analyzers.CodeFixes.dll" PackagePath="analyzers/dotnet/cs" />
<TfmSpecificPackageFile Include="$(OutputPath)\**\MSTest.Analyzers.resources.dll" PackagePath="analyzers/dotnet/cs/" />
<TfmSpecificPackageFile Include="$(OutputPath)\**\MSTest.Analyzers.CodeFixes.resources.dll" PackagePath="analyzers/dotnet/cs/" />

<!-- NOTE: Currently, code fixes are C# only. -->
<TfmSpecificPackageFile Include="$(OutputPath)\MSTest.Analyzers.dll" PackagePath="analyzers/dotnet/vb" />
<TfmSpecificPackageFile Include="$(OutputPath)\**\MSTest.Analyzers.resources.dll" PackagePath="analyzers/dotnet/vb/" />
</ItemGroup>
</Target>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Platform.Acceptance.IntegrationTests;
using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;

namespace MSTest.Acceptance.IntegrationTests;

[TestClass]
public sealed class AnalyzersTests : AcceptanceTestBase<NopAssetFixture>
{
[TestMethod]
public async Task AnalyzerMessagesShouldBeLocalized()
{
string code = """
#file Analyzers.csproj
<Project Sdk="MSTest.Sdk/$MSTestVersion$">
<PropertyGroup>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
<RunAnalyzers>true</RunAnalyzers>
</PropertyGroup>
</Project>
#file UnitTest1.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class UnitTest1
{
[DataRow(0)]
public void TestMethod()
{
}
}
""".PatchTargetFrameworks(TargetFrameworks.NetCurrent)
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion);

using TestAsset testAsset = await TestAsset.GenerateAssetAsync("Analyzers", code);
DotnetMuxerResult result = await DotnetCli.RunAsync($"build {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path, environmentVariables: new()
{
["DOTNET_CLI_UI_LANGUAGE"] = "it-IT",
["PreferredUILang"] = "it-IT",
["VSLang"] = "1040",
}, warnAsError: false);
result.AssertOutputContains("DataRow deve essere impostato solo su un metodo di test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public static async Task<DotnetMuxerResult> RunAsync(
}
}

environmentVariables.Add(key!, entry.Value!.ToString()!);
// We use TryAdd to let tests "overwrite" existing environment variables.
// Consider that the given dictionary has "TESTINGPLATFORM_UI_LANGUAGE" as a key.
// And also Environment.GetEnvironmentVariables() is returning TESTINGPLATFORM_UI_LANGUAGE.
// In that case, we do a "TryAdd" which effectively means the value from the original dictionary wins.
environmentVariables.TryAdd(key!, entry.Value!.ToString()!);
}

if (disableTelemetry)
Expand Down

0 comments on commit 2564c52

Please sign in to comment.