diff --git a/.github/workflows/includes.yml b/.github/workflows/includes.yml index 9cdae21a..15a781ed 100644 --- a/.github/workflows/includes.yml +++ b/.github/workflows/includes.yml @@ -31,7 +31,7 @@ jobs: - name: ✍ pull request uses: peter-evans/create-pull-request@v6 with: - add-paths: '**/*.md' + add-paths: '**.md' base: main branch: markdown-includes delete-branch: true diff --git a/.netconfig b/.netconfig index 890af614..b8b6f0a0 100644 --- a/.netconfig +++ b/.netconfig @@ -63,9 +63,9 @@ sha = e732f6a2c44a2f7940a1868a92cd66523f74ed24 [file "Directory.Build.rsp"] url = https://github.com/devlooped/oss/blob/main/Directory.Build.rsp - etag = 6a6c6e1d3895df953abf14c82b0899e3eea75cdcd679f6212dcfea15183d73d6 + etag = 0ccae83fc51f400bfd7058170bfec7aba11455e24a46a0d7e6a358da6486e255 weak - sha = ae25fae9d7daf0cb47d537ba870914aa3052f0c9 + sha = 0f7f7f7e8a29de9b535676f75fe7c67e629a5e8c [file "_config.yml"] url = https://github.com/devlooped/oss/blob/main/_config.yml etag = 9139148f845adf503fd3c3c140eb64421fc476a1f9c027fc50825c0efb05f557 @@ -114,8 +114,8 @@ weak [file ".github/workflows/includes.yml"] url = https://github.com/devlooped/oss/blob/main/.github/workflows/includes.yml - sha = 5fb172362c767bef7c36478f1a6bdc264723f8f9 - etag = e5ee22e115c925fb85ec931cda3ac811fcc453c03904554fa3f573935b221d34 + sha = d152e7437fd0d6f6d9363d23cb3b78c07335ea49 + etag = ec40db34f379d0c6d83b2ec15624f330318a172cc4f85b5417c63e86eaf601df weak [file ".github/workflows/combine-prs.yml"] url = https://github.com/devlooped/oss/blob/main/.github/workflows/combine-prs.yml @@ -189,11 +189,6 @@ sha = f47528874a6d9192b5546f84b455f5ccc474a707 etag = 5002ac8c5bbeee60c13937a32c1b6c1a5dbf0065617c8f2550e6eca6fded256d weak -[file "src/SponsorLink/SponsorLink.Tests.targets"] - url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink.Tests.targets - sha = f47528874a6d9192b5546f84b455f5ccc474a707 - etag = 5be3b99c0049cbe98c305f5af2fd482a3a995960c3a1fc6dd2bffcbf3b7e4d52 - weak [file "src/SponsorLink/SponsorLink/AppDomainDictionary.cs"] url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/AppDomainDictionary.cs sha = f47528874a6d9192b5546f84b455f5ccc474a707 @@ -271,8 +266,8 @@ weak [file "src/SponsorLink/Tests/AnalyzerTests.cs"] url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/Tests/AnalyzerTests.cs - sha = f47528874a6d9192b5546f84b455f5ccc474a707 - etag = 39227dc53df109e4d450cfe075ded530a8d23f9ea7b293dca58a6fdd3746875b + sha = 2a5e198c982593da18b016161741c75846f67a71 + etag = 9a86f7482a4401a8dd30148976f47e2a98cb9cfe9c64153d336989146ce7b4b7 weak [file "src/SponsorLink/Tests/Attributes.cs"] url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/Tests/Attributes.cs @@ -364,3 +359,8 @@ sha = 06ad2df230e2de316655ae6073d493bf04805d46 etag = 4d2939c5005cd6136065bf2b1cd62f96351a8d94d904d141bcb11186e8c16b3b weak +[file "src/SponsorLink/SponsorLink.Analyzer.Tests.targets"] + url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink.Analyzer.Tests.targets + sha = e2d7e6f3b23ef5d5ead947f48c63efc77f3d4741 + etag = 6959847d7e6425906530095e564f46bdfddf26995e6663142cfd2b065c0bb3c4 + weak diff --git a/Directory.Build.rsp b/Directory.Build.rsp index 7c0dbc1e..509cc660 100644 --- a/Directory.Build.rsp +++ b/Directory.Build.rsp @@ -2,4 +2,4 @@ -nr:false -m:1 -v:m --clp:Summary;ForceNoAlign \ No newline at end of file +-clp:Summary;ForceNoAlign diff --git a/src/SponsorLink/SponsorLink.Tests.targets b/src/SponsorLink/SponsorLink.Analyzer.Tests.targets similarity index 91% rename from src/SponsorLink/SponsorLink.Tests.targets rename to src/SponsorLink/SponsorLink.Analyzer.Tests.targets index 1ca1eb63..346777a5 100644 --- a/src/SponsorLink/SponsorLink.Tests.targets +++ b/src/SponsorLink/SponsorLink.Analyzer.Tests.targets @@ -26,11 +26,12 @@ !$([MSBuild]::ValueOrDefault('%(FileName)', '').StartsWith('Microsoft.CSharp', StringComparison.OrdinalIgnoreCase)) And !$([MSBuild]::ValueOrDefault('%(FileName)', '').StartsWith('System.', StringComparison.OrdinalIgnoreCase))" /> - + diff --git a/src/SponsorLink/Tests/AnalyzerTests.cs b/src/SponsorLink/Tests/AnalyzerTests.cs index daed0fb2..dc9ed215 100644 --- a/src/SponsorLink/Tests/AnalyzerTests.cs +++ b/src/SponsorLink/Tests/AnalyzerTests.cs @@ -44,7 +44,14 @@ void IDisposable.Dispose() public async Task WhenNoAdditionalFiles_ThenReportsUnknown() { var compilation = CSharpCompilation.Create("test", [CSharpSyntaxTree.ParseText("//")]) - .WithAnalyzers([new SponsorLinkAnalyzer()]); + .WithAnalyzers([new SponsorLinkAnalyzer()], + new AnalyzerOptions([], new TestAnalyzerConfigOptionsProvider(new()) + { + // Force reporting without wait period + { "build_property.SponsorLinkNoInstallGrace", "true" }, + // Simulate directly referenced package + { "build_property.SponsorableLib", "1.0.0" }, + })); var diagnostics = await compilation.GetAnalyzerDiagnosticsAsync(); @@ -91,7 +98,9 @@ public async Task WhenUnknownAndNoGraceOption_ThenReportsUnknown() { { "build_property.SponsorLinkNoInstallGrace", "true" }, { "build_metadata.Analyzer.ItemType", "Analyzer" }, - { "build_metadata.Analyzer.NuGetPackageId", "SponsorableLib" } + { "build_metadata.Analyzer.NuGetPackageId", "SponsorableLib" }, + // Simulate directly referenced package + { "build_property.SponsorableLib", "1.0.0" }, })); var diagnostics = await compilation.GetAnalyzerDiagnosticsAsync(); @@ -119,7 +128,9 @@ public async Task WhenUnknownAndGraceExpired_ThenReportsUnknown() .WithAnalyzers([new SponsorLinkAnalyzer()], new AnalyzerOptions([new AdditionalTextFile(dll)], new TestAnalyzerConfigOptionsProvider(new()) { { "build_metadata.Analyzer.ItemType", "Analyzer" }, - { "build_metadata.Analyzer.NuGetPackageId", "SponsorableLib" } + { "build_metadata.Analyzer.NuGetPackageId", "SponsorableLib" }, + // Simulate directly referenced package + { "build_property.SponsorableLib", "1.0.0" }, })); var diagnostics = await compilation.GetAnalyzerDiagnosticsAsync(); @@ -144,7 +155,9 @@ public async Task WhenSponsoring_ThenReportsSponsor() var compilation = CSharpCompilation.Create("test", [CSharpSyntaxTree.ParseText("//")]) .WithAnalyzers([new SponsorLinkAnalyzer()], new AnalyzerOptions([new AdditionalTextFile(jwt)], new TestAnalyzerConfigOptionsProvider(new()) { - { "build_metadata.SponsorManifest.ItemType", "SponsorManifest" } + { "build_metadata.SponsorManifest.ItemType", "SponsorManifest" }, + // Simulate directly referenced package + { "build_property.SponsorableLib", "1.0.0" }, })); var diagnostics = await compilation.GetAnalyzerDiagnosticsAsync(); @@ -163,21 +176,41 @@ public async Task WhenSponsoring_ThenReportsSponsor() public async Task WhenMultipleAnalyzers_ThenReportsOnce() { var compilation = CSharpCompilation.Create("test", [CSharpSyntaxTree.ParseText("//")]) - .WithAnalyzers([new SponsorLinkAnalyzer(), new SponsorLinkAnalyzer()]); - - var diagnostics = await compilation.GetAnalyzerDiagnosticsAsync(); + .WithAnalyzers([new SponsorLinkAnalyzer(), new SponsorLinkAnalyzer()], + new AnalyzerOptions([], new TestAnalyzerConfigOptionsProvider(new()) + { + // Force reporting without wait period + { "build_property.SponsorLinkNoInstallGrace", "true" }, + // Simulate directly referenced package + { "build_property.SponsorableLib", "1.0.0" }, + { "build_property.SponsorLink", "1.0.0" }, + })); + + var diagnostics = (await compilation.GetAnalyzerDiagnosticsAsync()) + .Where(x => x.Properties.TryGetValue(nameof(SponsorStatus), out var _)); Assert.NotEmpty(diagnostics); + Assert.Single(diagnostics.Where(x => x.Properties.TryGetValue(nameof(SponsorStatus), out var value))); + } - var diagnostic = diagnostics.Single(x => x.Properties.TryGetValue(nameof(SponsorStatus), out var value)); + [Fact] + public async Task WhenAnalyzerNotDirectlyReferenced_ThenDoesNotReport() + { + var compilation = CSharpCompilation.Create("test", [CSharpSyntaxTree.ParseText("//")]) + .WithAnalyzers([new SponsorLinkAnalyzer()], + new AnalyzerOptions([], new TestAnalyzerConfigOptionsProvider(new()) + { + // Force reporting if necessary without wait period + { "build_property.SponsorLinkNoInstallGrace", "true" }, + // Directly referenced package would result in a compiler visible property like: + //{ "build_property.SponsorableLib", "1.0.0" }, + })); - Assert.True(diagnostic.Properties.TryGetValue(nameof(SponsorStatus), out var value)); - var status = Enum.Parse(value); + var diagnostics = await compilation.GetAnalyzerDiagnosticsAsync(); - Assert.Equal(SponsorStatus.Unknown, status); + Assert.Empty(diagnostics); } - string GetTempPath([CallerMemberName] string? test = default) { var path = Path.Combine(Path.GetTempPath(), test ?? nameof(AnalyzerTests));