From cad9a8e93f479ba9905996c21058d6d0e07cd6da Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Tue, 11 Nov 2025 17:58:10 -0800 Subject: [PATCH] Only track steps when needed --- .../RazorSourceGeneratorTests.cs | 2 +- .../RazorSourceGeneratorTestsBase.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs index ac91bdf7606..b815d4fbc97 100644 --- a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs @@ -2617,7 +2617,7 @@ public async Task SourceGenerator_DoesNotUpdateSources_WhenSourceGeneratorIsSupp }); var compilation = await project.GetCompilationAsync(); - var (driver, additionalTexts, optionsProvider) = await GetDriverWithAdditionalTextAndProviderAsync(project); + var (driver, additionalTexts, optionsProvider) = await GetDriverWithAdditionalTextAndProviderAsync(project, trackSteps: true); // start with the generator suppressed (this is the default state in VS) driver = SetSuppressionState(true); diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTestsBase.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTestsBase.cs index 527a44e5232..ee4fc3ecb9e 100644 --- a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTestsBase.cs +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTestsBase.cs @@ -57,11 +57,11 @@ protected static async ValueTask GetDriverAsync(Project project return (result.Item1, result.Item2); } - protected static async ValueTask<(GeneratorDriver, ImmutableArray, TestAnalyzerConfigOptionsProvider)> GetDriverWithAdditionalTextAndProviderAsync(Project project, Action? configureGlobalOptions = null, bool hostOutputs = false) + protected static async ValueTask<(GeneratorDriver, ImmutableArray, TestAnalyzerConfigOptionsProvider)> GetDriverWithAdditionalTextAndProviderAsync(Project project, Action? configureGlobalOptions = null, bool hostOutputs = false, bool trackSteps = false) { var razorSourceGenerator = new RazorSourceGenerator(testUniqueIds: "test").AsSourceGenerator(); var disabledOutputs = hostOutputs ? IncrementalGeneratorOutputKind.None : (IncrementalGeneratorOutputKind)0b100000; - var driver = (GeneratorDriver)CSharpGeneratorDriver.Create(new[] { razorSourceGenerator }, parseOptions: (CSharpParseOptions)project.ParseOptions!, driverOptions: new GeneratorDriverOptions(disabledOutputs, true)); + var driver = (GeneratorDriver)CSharpGeneratorDriver.Create(new[] { razorSourceGenerator }, parseOptions: (CSharpParseOptions)project.ParseOptions!, driverOptions: new GeneratorDriverOptions(disabledOutputs, trackSteps)); var optionsProvider = new TestAnalyzerConfigOptionsProvider(); optionsProvider.TestGlobalOptions["build_property.RazorConfiguration"] = "Default"; @@ -479,6 +479,9 @@ public static void VerifyTextMatchesBaseline(string actualText, string fileName, [Conditional("GENERATE_BASELINES")] private static void GenerateOutputBaseline(string baselinePath, string text) { + var directory = Path.GetDirectoryName(baselinePath)!; + Directory.CreateDirectory(directory); + text = text.Replace("\r", "").Replace("\n", "\r\n"); File.WriteAllText(baselinePath, text, _baselineEncoding); }