-
Notifications
You must be signed in to change notification settings - Fork 758
/
EmitterTests.cs
72 lines (64 loc) · 2.66 KB
/
EmitterTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Extensions.Compliance.Classification;
using Microsoft.Extensions.Compliance.Redaction;
using Microsoft.Extensions.Compliance.Testing;
using Microsoft.Extensions.Diagnostics.Enrichment;
using Microsoft.Extensions.Logging;
using Microsoft.Gen.Logging.Parsing;
using Microsoft.Gen.Shared;
using Xunit;
namespace Microsoft.Gen.Logging.Test;
public class EmitterTests
{
[Fact]
public async Task TestEmitter()
{
var sources = new List<string>();
foreach (var file in Directory.GetFiles("TestClasses"))
{
sources.Add(File.ReadAllText(file));
}
#if NET6_0_OR_GREATER
var symbols = new[] { "NET7_0_OR_GREATER", "NET6_0_OR_GREATER", "NET5_0_OR_GREATER" };
#else
var symbols = new[] { "NET5_0_OR_GREATER" };
#endif
var (d, r) = await RoslynTestUtils.RunGenerator(
new LoggingGenerator(),
new[]
{
Assembly.GetAssembly(typeof(ILogger))!,
Assembly.GetAssembly(typeof(LoggerMessageAttribute))!,
Assembly.GetAssembly(typeof(IEnrichmentTagCollector))!,
Assembly.GetAssembly(typeof(DataClassification))!,
Assembly.GetAssembly(typeof(IRedactorProvider))!,
Assembly.GetAssembly(typeof(PrivateDataAttribute))!,
Assembly.GetAssembly(typeof(BigInteger))!,
},
sources,
symbols)
.ConfigureAwait(false);
// we need this "Where()" hack because Roslyn 4.0 doesn't recognize #pragma warning disable for generator-produced warnings
#pragma warning disable S1067 // Expressions should not be too complex
Assert.Empty(d.Where(diag
=> diag.Id != DiagDescriptors.ShouldntMentionExceptionInMessage.Id
&& diag.Id != DiagDescriptors.ShouldntMentionLoggerInMessage.Id
&& diag.Id != DiagDescriptors.ShouldntMentionLogLevelInMessage.Id
&& diag.Id != DiagDescriptors.EmptyLoggingMethod.Id
&& diag.Id != DiagDescriptors.ParameterHasNoCorrespondingTemplate.Id));
#pragma warning restore S1067 // Expressions should not be too complex
_ = Assert.Single(r);
#if false
var golden = File.ReadAllText($"GoldenFiles/Microsoft.Gen.Logging/Microsoft.Gen.Logging.LoggingGenerator/Logging.g.cs");
var result = r[0].SourceText.ToString();
Assert.Equal(golden, result);
#endif
}
}