From 2132a79ab60655d7a2988672edf97d7bdbf06a45 Mon Sep 17 00:00:00 2001 From: CodingFlow <3643313+CodingFlow@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:07:16 -0400 Subject: [PATCH] - Use DefaultVerifier instead of NUnitVerifier in unit tests as suggested (https://github.com/dotnet/roslyn-sdk/issues/1127#issuecomment-2057446130) to fix issues when upgrading to NUnit 4. - Upgrade to Nunit 4 and upgrade source generation nuget packages to latest stable versions. --- .../CSharpSourceGeneratorVerifier.cs | 16 ++++++---------- .../DecoratorGenerator.UnitTests.csproj | 15 +++++++++------ DecoratorGenerator/DecoratorGenerator.csproj | 4 ++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/DecoratorGenerator.UnitTests/CSharpSourceGeneratorVerifier.cs b/DecoratorGenerator.UnitTests/CSharpSourceGeneratorVerifier.cs index 446a57c..27020e2 100644 --- a/DecoratorGenerator.UnitTests/CSharpSourceGeneratorVerifier.cs +++ b/DecoratorGenerator.UnitTests/CSharpSourceGeneratorVerifier.cs @@ -1,21 +1,19 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Testing; using System.Collections.Immutable; namespace DecoratorGenerator.UnitTests; public static class CSharpSourceGeneratorVerifier where TSourceGenerator : ISourceGenerator, new() { - public class Test : CSharpSourceGeneratorTest + public class Test : CSharpSourceGeneratorTest { - public Test() - { + public Test() { } - protected override CompilationOptions CreateCompilationOptions() - { + protected override CompilationOptions CreateCompilationOptions() { var compilationOptions = base.CreateCompilationOptions(); return compilationOptions.WithSpecificDiagnosticOptions( compilationOptions.SpecificDiagnosticOptions.SetItems(GetNullableWarningsFromCompiler())); @@ -23,8 +21,7 @@ protected override CompilationOptions CreateCompilationOptions() public LanguageVersion LanguageVersion { get; set; } = LanguageVersion.Default; - private static ImmutableDictionary GetNullableWarningsFromCompiler() - { + private static ImmutableDictionary GetNullableWarningsFromCompiler() { string[] args = { "/warnaserror:nullable" }; var commandLineArguments = CSharpCommandLineParser.Default.Parse(args, baseDirectory: Environment.CurrentDirectory, sdkDirectory: Environment.CurrentDirectory); var nullableWarnings = commandLineArguments.CompilationOptions.SpecificDiagnosticOptions; @@ -32,8 +29,7 @@ private static ImmutableDictionary GetNullableWarnings return nullableWarnings; } - protected override ParseOptions CreateParseOptions() - { + protected override ParseOptions CreateParseOptions() { return ((CSharpParseOptions)base.CreateParseOptions()).WithLanguageVersion(LanguageVersion); } } diff --git a/DecoratorGenerator.UnitTests/DecoratorGenerator.UnitTests.csproj b/DecoratorGenerator.UnitTests/DecoratorGenerator.UnitTests.csproj index 3cf83c7..c690225 100644 --- a/DecoratorGenerator.UnitTests/DecoratorGenerator.UnitTests.csproj +++ b/DecoratorGenerator.UnitTests/DecoratorGenerator.UnitTests.csproj @@ -11,17 +11,20 @@ - + - - - + + + - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + all runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/DecoratorGenerator/DecoratorGenerator.csproj b/DecoratorGenerator/DecoratorGenerator.csproj index 9353a1b..9d9bd27 100644 --- a/DecoratorGenerator/DecoratorGenerator.csproj +++ b/DecoratorGenerator/DecoratorGenerator.csproj @@ -53,8 +53,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive