Skip to content

Commit 549c6a1

Browse files
Fix issue with source generator not generating sample registry to test against
1 parent ecb6693 commit 549c6a1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

common/CommunityToolkit.Labs.Core.SourceGenerators/ToolkitSampleMetadataGenerator.Sample.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void Execute(IncrementalValuesProvider<ISymbol> types, bool skipDiagnostics = fa
107107
var currentAssembly = data.Right;
108108

109109
var isExecutingInSampleProject = currentAssembly?.EndsWith(".Samples") ?? false;
110+
var isExecutingInTestProject = currentAssembly?.EndsWith(".Tests") ?? false;
110111

111112
// Reconstruct sample metadata from attributes
112113
var sampleMetadata = toolkitSampleAttributeData
@@ -132,7 +133,9 @@ void Execute(IncrementalValuesProvider<ISymbol> types, bool skipDiagnostics = fa
132133
ReportDocumentDiagnostics(ctx, sampleMetadata, markdownFileData, toolkitSampleAttributeData, docFrontMatter);
133134
}
134135

135-
if (!isExecutingInSampleProject && !skipRegistry)
136+
// For tests we need one pass to do diagnostics and registry as we're in a contrived environment that'll have both our scenarios. Though we check if we have anything to write, as we will hit both executes.
137+
if ((!isExecutingInSampleProject && !skipRegistry) ||
138+
(isExecutingInTestProject && (docFrontMatter.Any() || sampleMetadata.Any())))
136139
{
137140
CreateDocumentRegistry(ctx, docFrontMatter);
138141
CreateSampleRegistry(ctx, sampleMetadata);

0 commit comments

Comments
 (0)