From a0a655531fffccb2a93a0a029db7089f39addd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 10 Feb 2025 20:37:35 +0100 Subject: [PATCH] Use MSTest.Sdk with VSTest + parallelize --- .../CommunityToolkit.Tooling.SampleGen.Tests.csproj | 8 ++------ CommunityToolkit.Tooling.SampleGen.Tests/MSTestConfig.cs | 8 ++++++++ .../ToolkitSampleGeneratedPaneTests.cs | 2 -- .../ToolkitSampleMetadataTests.Documentation.cs | 4 ++-- .../ToolkitSampleMetadataTests.cs | 2 -- .../CommunityToolkit.Tooling.TestGen.Tests.csproj | 8 ++------ CommunityToolkit.Tooling.TestGen.Tests/MSTestConfig.cs | 8 ++++++++ .../UIThreadTestMethodTests.cs | 4 ++-- ProjectHeads/Tests.Head.WinAppSdk.props | 2 +- ProjectHeads/Tests.Head.props | 3 +-- global.json | 5 +++-- 11 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 CommunityToolkit.Tooling.SampleGen.Tests/MSTestConfig.cs create mode 100644 CommunityToolkit.Tooling.TestGen.Tests/MSTestConfig.cs diff --git a/CommunityToolkit.Tooling.SampleGen.Tests/CommunityToolkit.Tooling.SampleGen.Tests.csproj b/CommunityToolkit.Tooling.SampleGen.Tests/CommunityToolkit.Tooling.SampleGen.Tests.csproj index 629c9e54..ce89f17f 100644 --- a/CommunityToolkit.Tooling.SampleGen.Tests/CommunityToolkit.Tooling.SampleGen.Tests.csproj +++ b/CommunityToolkit.Tooling.SampleGen.Tests/CommunityToolkit.Tooling.SampleGen.Tests.csproj @@ -1,18 +1,14 @@ - + net8.0 enable - - false preview + true - - - diff --git a/CommunityToolkit.Tooling.SampleGen.Tests/MSTestConfig.cs b/CommunityToolkit.Tooling.SampleGen.Tests/MSTestConfig.cs new file mode 100644 index 00000000..53a77439 --- /dev/null +++ b/CommunityToolkit.Tooling.SampleGen.Tests/MSTestConfig.cs @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] diff --git a/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleGeneratedPaneTests.cs b/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleGeneratedPaneTests.cs index 6189b329..0e2ea3b1 100644 --- a/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleGeneratedPaneTests.cs +++ b/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleGeneratedPaneTests.cs @@ -4,9 +4,7 @@ using CommunityToolkit.Tooling.SampleGen.Diagnostics; using CommunityToolkit.Tooling.SampleGen.Tests.Helpers; -using Microsoft.CodeAnalysis; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; namespace CommunityToolkit.Tooling.SampleGen.Tests; diff --git a/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.Documentation.cs b/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.Documentation.cs index a61df3b0..ce4c166f 100644 --- a/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.Documentation.cs +++ b/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.Documentation.cs @@ -300,7 +300,7 @@ Which is valid. result.AssertNoCompilationErrors(); - Assert.AreEqual(result.Compilation.GetFileContentsByName("ToolkitDocumentRegistry.g.cs"), """ + Assert.AreEqual(""" #nullable enable namespace CommunityToolkit.Tooling.SampleGen; @@ -311,6 +311,6 @@ public static class ToolkitDocumentRegistry yield return new CommunityToolkit.Tooling.SampleGen.Metadata.ToolkitFrontMatter() { ComponentName = "Primitives", Title = "Canvas Layout", Author = "mhawker", Description = "A canvas-like VirtualizingLayout for use in an ItemsRepeater", Keywords = "CanvasLayout, ItemsRepeater, VirtualizingLayout, Canvas, Layout, Panel, Arrange", Category = ToolkitSampleCategory.Controls, Subcategory = ToolkitSampleSubcategory.Layout, DiscussionId = 0, IssueId = 0, Icon = @"assets/icon.png", FilePath = @"experiment\samples\documentation.md", SampleIdReferences = new string[] { "Sample" }, IsExperimental = true, CsProjName = @"componentname.csproj" }; } } - """, "Unexpected code generated"); + """, result.Compilation.GetFileContentsByName("ToolkitDocumentRegistry.g.cs"), "Unexpected code generated"); } } diff --git a/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.cs b/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.cs index 218a332e..4be5bca1 100644 --- a/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.cs +++ b/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.cs @@ -5,8 +5,6 @@ using CommunityToolkit.Tooling.SampleGen.Diagnostics; using CommunityToolkit.Tooling.SampleGen.Tests.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Immutable; -using System.ComponentModel.DataAnnotations; namespace CommunityToolkit.Tooling.SampleGen.Tests; diff --git a/CommunityToolkit.Tooling.TestGen.Tests/CommunityToolkit.Tooling.TestGen.Tests.csproj b/CommunityToolkit.Tooling.TestGen.Tests/CommunityToolkit.Tooling.TestGen.Tests.csproj index c68f7e0c..5d948528 100644 --- a/CommunityToolkit.Tooling.TestGen.Tests/CommunityToolkit.Tooling.TestGen.Tests.csproj +++ b/CommunityToolkit.Tooling.TestGen.Tests/CommunityToolkit.Tooling.TestGen.Tests.csproj @@ -1,17 +1,13 @@ - + net8.0 enable - - false + true - - - diff --git a/CommunityToolkit.Tooling.TestGen.Tests/MSTestConfig.cs b/CommunityToolkit.Tooling.TestGen.Tests/MSTestConfig.cs new file mode 100644 index 00000000..53a77439 --- /dev/null +++ b/CommunityToolkit.Tooling.TestGen.Tests/MSTestConfig.cs @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] diff --git a/CommunityToolkit.Tooling.TestGen.Tests/UIThreadTestMethodTests.cs b/CommunityToolkit.Tooling.TestGen.Tests/UIThreadTestMethodTests.cs index fa484c1f..7d751a85 100644 --- a/CommunityToolkit.Tooling.TestGen.Tests/UIThreadTestMethodTests.cs +++ b/CommunityToolkit.Tooling.TestGen.Tests/UIThreadTestMethodTests.cs @@ -340,10 +340,10 @@ from assembly in AppDomain.CurrentDomain.GetAssemblies() driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out Compilation outputCompilation, out ImmutableArray diagnostics); HashSet resultingIds = diagnostics.Select(diagnostic => diagnostic.Id).ToHashSet(); - var generatedCompilationDiaghostics = outputCompilation.GetDiagnostics(); + var generatedCompilationDiagnostics = outputCompilation.GetDiagnostics(); Assert.IsTrue(resultingIds.SetEquals(diagnosticsIds), $"Expected one of [{string.Join(", ", diagnosticsIds)}] diagnostic Ids. Got [{string.Join(", ", resultingIds)}]"); - Assert.IsTrue(generatedCompilationDiaghostics.All(x => x.Severity != DiagnosticSeverity.Error), $"Expected no generated compilation errors. Got: \n{string.Join("\n", generatedCompilationDiaghostics.Where(x => x.Severity == DiagnosticSeverity.Error).Select(x => $"[{x.Id}: {x.GetMessage()}]"))}"); + Assert.IsTrue(generatedCompilationDiagnostics.All(x => x.Severity != DiagnosticSeverity.Error), $"Expected no generated compilation errors. Got: \n{string.Join("\n", generatedCompilationDiagnostics.Where(x => x.Severity == DiagnosticSeverity.Error).Select(x => $"[{x.Id}: {x.GetMessage()}]"))}"); GC.KeepAlive(attributeType); diff --git a/ProjectHeads/Tests.Head.WinAppSdk.props b/ProjectHeads/Tests.Head.WinAppSdk.props index 2e306263..ef652c61 100644 --- a/ProjectHeads/Tests.Head.WinAppSdk.props +++ b/ProjectHeads/Tests.Head.WinAppSdk.props @@ -6,7 +6,7 @@ - + build diff --git a/ProjectHeads/Tests.Head.props b/ProjectHeads/Tests.Head.props index 447cef55..382fb141 100644 --- a/ProjectHeads/Tests.Head.props +++ b/ProjectHeads/Tests.Head.props @@ -10,8 +10,7 @@ - - + diff --git a/global.json b/global.json index 27a18775..8210b417 100644 --- a/global.json +++ b/global.json @@ -3,8 +3,9 @@ "version": "9.0.101", "rollForward": "latestFeature" }, - "msbuild-sdks": + "msbuild-sdks": { - "MSBuild.Sdk.Extras":"3.0.23" + "MSBuild.Sdk.Extras":"3.0.23", + "MSTest.Sdk": "3.7.3" } }