| 1 |
using Microsoft.CodeAnalysis; |
| 2 |
using Microsoft.CodeAnalysis.CodeFixes; |
| 3 |
using Microsoft.CodeAnalysis.CSharp.Testing; |
| 4 |
using Microsoft.CodeAnalysis.Diagnostics; |
| 5 |
using Microsoft.CodeAnalysis.Testing; |
| 6 |
using System.IO; |
| 7 |
using System.Threading.Tasks; |
| 8 |
|
| 9 |
namespace Godot.SourceGenerators.Tests; |
| 10 |
|
| 11 |
public static class CSharpCodeFixVerifier<TCodeFix, TAnalyzer> |
| 12 |
where TCodeFix : CodeFixProvider, new() |
| 13 |
where TAnalyzer : DiagnosticAnalyzer, new() |
| 14 |
{ |
| 15 |
public class Test : CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier> |
| 16 |
{ |
| 17 |
public Test() |
| 18 |
{ |
| 19 |
ReferenceAssemblies = Constants.Net80; |
| 20 |
SolutionTransforms.Add((Solution solution, ProjectId projectId) => |
| 21 |
{ |
| 22 |
Project project = solution.GetProject(projectId)! |
| 23 |
.AddMetadataReference(Constants.GodotSharpAssembly.CreateMetadataReference()); |
| 24 |
return project.Solution; |
| 25 |
}); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
public static Task Verify(string sources, string fixedSources) |
| 30 |
{ |
| 31 |
return MakeVerifier(sources, fixedSources).RunAsync(); |
| 32 |
} |
| 33 |
|
| 34 |
public static Test MakeVerifier(string source, string results) |
| 35 |
{ |
| 36 |
var verifier = new Test(); |
| 37 |
|
| 38 |
verifier.TestCode = File.ReadAllText(Path.Combine(Constants.SourceFolderPath, source)); |
| 39 |
verifier.FixedCode = File.ReadAllText(Path.Combine(Constants.GeneratedSourceFolderPath, results)); |
| 40 |
|
| 41 |
verifier.TestState.AnalyzerConfigFiles.Add(("/.globalconfig", $""" |
| 42 |
is_global = true |
| 43 |
build_property.GodotProjectDir = {Constants.ExecutingAssemblyPath} |
| 44 |
""")); |
| 45 |
|
| 46 |
return verifier; |
| 47 |
} |
| 48 |
} |