Skip to content

Commit

Permalink
test: fix snapshot tests on net9
Browse files Browse the repository at this point in the history
  • Loading branch information
Alxandr committed Dec 6, 2024
1 parent 8d251db commit a54a46b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-and-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
dotnet-version: |
8.0.x
9.0.x
- uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -48,6 +49,7 @@ jobs:
with:
dotnet-version: |
8.0.x
9.0.x
# Not used here - but used in the release job
# If this breaks, make sure to update both here
Expand Down Expand Up @@ -104,6 +106,7 @@ jobs:
with:
dotnet-version: |
8.0.x
9.0.x
- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
with:
dotnet-version: |
8.0.x
9.0.x
- uses: actions/setup-node@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageVersion Include="Microsoft.Build.Artifacts" Version="6.1.48" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.7.8" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.12.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ private void ParseMethodCandidate(MethodDeclarationSyntax method, CancellationTo
{
foreach (var attribute in attributeList.Attributes)
{
var attributeCtorSymbol = _semanticModel.GetSymbolInfo(attribute, ct).Symbol as IMethodSymbol;
var attributeCtorSymbolInfo = _semanticModel.GetSymbolInfo(attribute, ct);
var attributeCtorSymbol = attributeCtorSymbolInfo.Symbol as IMethodSymbol;
if (attributeCtorSymbol is null || !attributeCtorSymbol.ContainingType.Equals(_symbols.UrnKeyAttribute, SymbolEqualityComparer.Default))
{
// badly formed attribute definition, or not the right attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task VerifySourceGeneratorOutput(string source, DiagnosticDe

// Create a compilation for the source code
var compilation = await BaseCompilation.Value;
compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(sourceFile, new CSharpParseOptions(LanguageVersion.CSharp12)));
compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(sourceFile, new CSharpParseOptions(compilation.LanguageVersion)));

// Create an instance of our generator
var generator = new UrnGenerator();
Expand Down Expand Up @@ -49,16 +49,17 @@ public static async Task VerifySourceGeneratorOutput(string source, DiagnosticDe
remaining.Should().BeEmpty("All expected exceptions should be present");
}

private static readonly Lazy<Task<Compilation>> BaseCompilation = new(async () =>
private static readonly Lazy<Task<CSharpCompilation>> BaseCompilation = new(async () =>
{
var workspace = MSBuildWorkspace.Create();
var projectFile = FindUp("Altinn.Urn.SourceGenerator.Tests.csproj");
var projectFile = Path.Combine(
Path.GetDirectoryName(Path.GetDirectoryName(FindUp("Altinn.Urn.SourceGenerator.Tests.csproj")))!,
"Altinn.Urn.SourceGenerator.IntegrationTests",
"Altinn.Urn.SourceGenerator.IntegrationTests.csproj");
var project = await workspace.OpenProjectAsync(projectFile);

project = project
.WithProjectReferences([])
.WithAnalyzerReferences([]);
project = project.AddMetadataReference(Reference<KeyValueUrnAttribute>());

var compilation = await project.GetCompilationAsync();
if (compilation == null)
Expand All @@ -68,7 +69,7 @@ public static async Task VerifySourceGeneratorOutput(string source, DiagnosticDe

compilation = compilation.RemoveAllSyntaxTrees();

return compilation;
return (CSharpCompilation)compilation;
}, LazyThreadSafetyMode.ExecutionAndPublication);

private static string FindUp(string fileName)
Expand All @@ -87,10 +88,4 @@ private static string FindUp(string fileName)

throw new FileNotFoundException($"Could not find file '{fileName}'");
}

static MetadataReference Reference(string name) =>
MetadataReference.CreateFromFile(AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(name)).Location);

static MetadataReference Reference<T>() =>
MetadataReference.CreateFromFile(typeof(T).Assembly.Location);
}

0 comments on commit a54a46b

Please sign in to comment.