mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Add ForceRun flag to fix source generator tests
This commit is contained in:
@@ -34,6 +34,9 @@ namespace osu.Framework.SourceGeneration.Tests.Verifiers
|
||||
{
|
||||
driver = CSharpGeneratorDriver.Create(generator = new TSourceGenerator());
|
||||
driver = driver.WithUpdatedParseOptions(CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion));
|
||||
|
||||
generator.ForceRun = true;
|
||||
|
||||
this.commonSources = commonSources;
|
||||
this.commonGenerated = commonGenerated;
|
||||
this.multiPhaseSources = multiPhaseSources;
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using osu.Framework.SourceGeneration.Generators;
|
||||
|
||||
namespace osu.Framework.SourceGeneration.Tests.Verifiers
|
||||
{
|
||||
public partial class CSharpSourceGeneratorVerifier<TSourceGenerator>
|
||||
where TSourceGenerator : IIncrementalGenerator, new()
|
||||
where TSourceGenerator : AbstractIncrementalGenerator, new()
|
||||
{
|
||||
public static async Task VerifyAsync(
|
||||
(string filename, string content)[] commonSources,
|
||||
|
||||
@@ -7,11 +7,12 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Testing;
|
||||
using Microsoft.CodeAnalysis.Testing;
|
||||
using Microsoft.CodeAnalysis.Testing.Verifiers;
|
||||
using osu.Framework.SourceGeneration.Generators;
|
||||
|
||||
namespace osu.Framework.SourceGeneration.Tests.Verifiers
|
||||
{
|
||||
public partial class CSharpSourceGeneratorVerifier<TSourceGenerator>
|
||||
where TSourceGenerator : IIncrementalGenerator, new()
|
||||
where TSourceGenerator : AbstractIncrementalGenerator, new()
|
||||
{
|
||||
public class Test : CSharpSourceGeneratorTest<EmptySourceGeneratorProvider, XUnitVerifier>
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace osu.Framework.SourceGeneration.Tests.Verifiers
|
||||
|
||||
protected override IEnumerable<ISourceGenerator> GetSourceGenerators() => new[]
|
||||
{
|
||||
new TSourceGenerator().AsSourceGenerator()
|
||||
new TSourceGenerator { ForceRun = true }.AsSourceGenerator()
|
||||
};
|
||||
|
||||
protected override ParseOptions CreateParseOptions()
|
||||
|
||||
@@ -14,6 +14,11 @@ namespace osu.Framework.SourceGeneration.Generators
|
||||
{
|
||||
public readonly GeneratorEventDriver EventDriver = new GeneratorEventDriver();
|
||||
|
||||
/// <summary>
|
||||
/// Whether the generator should be forcefully run, even if building as debug.
|
||||
/// </summary>
|
||||
public bool ForceRun;
|
||||
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
// Stage 1: Create SyntaxTarget objects for all classes.
|
||||
@@ -23,7 +28,7 @@ namespace osu.Framework.SourceGeneration.Generators
|
||||
(ctx, _) => returnWithEvent(new IncrementalSyntaxTarget((ClassDeclarationSyntax)ctx.Node, ctx.SemanticModel), EventDriver.OnSyntaxTargetCreated))
|
||||
.Select((t, _) => t.WithName())
|
||||
.Combine(context.CompilationProvider)
|
||||
.Where(c => c.Right.Options.OptimizationLevel == OptimizationLevel.Release)
|
||||
.Where(c => ForceRun || c.Right.Options.OptimizationLevel == OptimizationLevel.Release)
|
||||
.Select((t, _) => t.Item1)
|
||||
.Select((t, _) => returnWithEvent(t.WithSemanticTarget(CreateSemanticTarget), EventDriver.OnSemanticTargetCreated));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user