using StellaOps.Scanner.Analyzers.Lang; namespace StellaOps.Scanner.Analyzers.Lang.Node.SmokeTests; internal static class LanguageAnalyzerSmokeHarness { public static async Task AssertDeterministicAsync(string fixturePath, string goldenPath, ILanguageAnalyzer analyzer, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(fixturePath)) throw new ArgumentException("fixturePath required", nameof(fixturePath)); if (string.IsNullOrWhiteSpace(goldenPath)) throw new ArgumentException("goldenPath required", nameof(goldenPath)); var engine = new LanguageAnalyzerEngine(new[] { analyzer }); var context = new LanguageAnalyzerContext(fixturePath, TimeProvider.System); var result = await engine.AnalyzeAsync(context, cancellationToken).ConfigureAwait(false); var actual = Normalize(result.ToJson(indent: true)); var expected = Normalize(await File.ReadAllTextAsync(goldenPath, cancellationToken).ConfigureAwait(false)); if (!string.Equals(actual, expected, StringComparison.Ordinal)) { var actualPath = goldenPath + ".actual"; Directory.CreateDirectory(Path.GetDirectoryName(actualPath)!); await File.WriteAllTextAsync(actualPath, actual, cancellationToken).ConfigureAwait(false); } Assert.Equal(expected, actual); } private static string Normalize(string value) { return value.Replace("\r\n", "\n", StringComparison.Ordinal).TrimEnd(); } }