Skip to content

Commit

Permalink
- Use DefaultVerifier instead of NUnitVerifier in unit tests as sugge…
Browse files Browse the repository at this point in the history
…sted (dotnet/roslyn-sdk#1127 (comment)) to fix issues when upgrading to NUnit 4.

- Upgrade to Nunit 4 and upgrade source generation nuget packages to latest stable versions.
  • Loading branch information
CodingFlow committed Jun 6, 2024
1 parent 134f8b8 commit 2132a79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
16 changes: 6 additions & 10 deletions DecoratorGenerator.UnitTests/CSharpSourceGeneratorVerifier.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
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<TSourceGenerator> where TSourceGenerator : ISourceGenerator, new()
{
public class Test : CSharpSourceGeneratorTest<TSourceGenerator, NUnitVerifier>
public class Test : CSharpSourceGeneratorTest<TSourceGenerator, DefaultVerifier>
{
public Test()
{
public Test() {
}

protected override CompilationOptions CreateCompilationOptions()
{
protected override CompilationOptions CreateCompilationOptions() {
var compilationOptions = base.CreateCompilationOptions();
return compilationOptions.WithSpecificDiagnosticOptions(
compilationOptions.SpecificDiagnosticOptions.SetItems(GetNullableWarningsFromCompiler()));
}

public LanguageVersion LanguageVersion { get; set; } = LanguageVersion.Default;

private static ImmutableDictionary<string, ReportDiagnostic> GetNullableWarningsFromCompiler()
{
private static ImmutableDictionary<string, ReportDiagnostic> GetNullableWarningsFromCompiler() {
string[] args = { "/warnaserror:nullable" };
var commandLineArguments = CSharpCommandLineParser.Default.Parse(args, baseDirectory: Environment.CurrentDirectory, sdkDirectory: Environment.CurrentDirectory);
var nullableWarnings = commandLineArguments.CompilationOptions.SpecificDiagnosticOptions;

return nullableWarnings;
}

protected override ParseOptions CreateParseOptions()
{
protected override ParseOptions CreateParseOptions() {
return ((CSharpParseOptions)base.CreateParseOptions()).WithLanguageVersion(LanguageVersion);
}
}
Expand Down
15 changes: 9 additions & 6 deletions DecoratorGenerator.UnitTests/DecoratorGenerator.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.103.8" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0">
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions DecoratorGenerator/DecoratorGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit 2132a79

Please sign in to comment.