// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using Xunit; using VerifyIncremental = osu.Framework.SourceGeneration.Tests.Verifiers.CSharpMultiPhaseSourceGeneratorVerifier; namespace osu.Framework.SourceGeneration.Tests.Dependencies { public class DependencyInjectionMultiPhaseSourceGeneratorTests : AbstractGeneratorTests { protected override string ResourceNamespace => "DependencyInjection"; // this function has support for the same test cases as DependencyInjectionSourceGeneratorTests.Check // but since the new verifier used here doesn't support creating nice diffs yet, // DependencyInjectionSourceGeneratorTests.Check is still preferred for now for single phase tests. [Theory] // Multi-phase tests: [InlineData("MultiPartialResolvedMember")] public void Check(string name) { GetTestSources(name, out (string filename, string content)[] commonSources, out (string filename, string content)[] sources, out (string filename, string content)[] commonGenerated, out (string filename, string content)[] generated ); VerifyIncremental.Verify(commonSources, sources, commonGenerated, generated); } public static TheoryData CheckWithStatisticsData => new TheoryData { { "GeneratorCached", new[] { (2, 2, 2), (0, 0, 0), } }, // TODO: fix this failing case // { "MultiPhasePartialCachedInterface", new[] { // (3, 3, 3), // (3, 2, 2), // should be (3, 2, 2) but current implementation returns (3, 1, 1), and generates invalid code due to a caching issue with single partials // } }, }; [Theory] [MemberData(nameof(CheckWithStatisticsData))] public void CheckWithStatistics(string name, (int syntaxTargetCreated, int semanticTargetCreated, int emitHits)[] expectedStatistics) { GetTestSources(name, out (string filename, string content)[] commonSources, out (string filename, string content)[] sources, out (string filename, string content)[] commonGenerated, out (string filename, string content)[] generated ); VerifyIncremental.Verify(commonSources, sources, commonGenerated, generated, test => test.AddStatisticsVerification(expectedStatistics)); } } }