Summary
Two pieces of generator testing infrastructure in this repo are as reusable as the generators themselves, and both currently exist only here.
1. The CSharpGeneratorDriver harness
Semantics.Test/Quantities/SourceGeneratorTests.cs drives each generator directly: builds a compilation, supplies the metadata JSON as AdditionalTexts, runs the driver, and asserts on the emitted sources. The only Semantics-specific parts are the generator list and the expected header.
Setting that up is fiddly — reference resolution, AdditionalText shims, and the packaging escape hatch this project needed:
<!-- A consumer that references this project as a plain library rather than as an analyzer
(the test project, which drives the generators through CSharpGeneratorDriver) must opt
out via AdditionalProperties="BundleAnalyzerDependencies=false" -->
Every project that writes a generator repeats that discovery. A small harness package — "given a generator and a set of metadata files, run it and give me the outputs and diagnostics" — removes it.
Worth adding while extracting:
- Assert on diagnostics, not just on their absence. The current test asserts
result.Diagnostics is empty; there is no coverage that SEM001–SEM005 actually fire on the inputs that should trigger them, so a diagnostic could silently stop working.
- Incrementality checks. These are
IIncrementalGenerators, and nothing verifies that unchanged metadata produces cached steps. GeneratorDriverRunResult.TrackedSteps makes this testable.
2. The committed-output drift check
.github/workflows/verify-generated.yml rebuilds, regenerates, and fails if anything under Semantics.Quantities/Generated/ or the alias props has drifted. Its own comment flags that it is a standalone workflow because dotnet.yml is centrally synced:
NOTE: this is a standalone workflow on purpose — dotnet.yml is centrally synced from a shared template across ktsu repos, so a step added there would be overwritten. If this check belongs in the shared KtsuBuild pipeline long-term, move it there and delete this.
"Committed generator output must match what the generator produces" applies to any repo that commits generator output. Candidates, in preference order:
- A reusable workflow (
workflow_call) in the shared ktsu workflow repo, invoked with the paths to verify.
- An MSBuild target in the toolkit package, so the check runs locally on build as well as in CI — which would catch drift before the push rather than 10 minutes after it.
Either way the goal is that the next repo committing generator output does not copy this YAML.
Acceptance criteria
Context
Part of #181.
Summary
Two pieces of generator testing infrastructure in this repo are as reusable as the generators themselves, and both currently exist only here.
1. The
CSharpGeneratorDriverharnessSemantics.Test/Quantities/SourceGeneratorTests.csdrives each generator directly: builds a compilation, supplies the metadata JSON asAdditionalTexts, runs the driver, and asserts on the emitted sources. The only Semantics-specific parts are the generator list and the expected header.Setting that up is fiddly — reference resolution,
AdditionalTextshims, and the packaging escape hatch this project needed:Every project that writes a generator repeats that discovery. A small harness package — "given a generator and a set of metadata files, run it and give me the outputs and diagnostics" — removes it.
Worth adding while extracting:
result.Diagnosticsis empty; there is no coverage that SEM001–SEM005 actually fire on the inputs that should trigger them, so a diagnostic could silently stop working.IIncrementalGenerators, and nothing verifies that unchanged metadata produces cached steps.GeneratorDriverRunResult.TrackedStepsmakes this testable.2. The committed-output drift check
.github/workflows/verify-generated.ymlrebuilds, regenerates, and fails if anything underSemantics.Quantities/Generated/or the alias props has drifted. Its own comment flags that it is a standalone workflow becausedotnet.ymlis centrally synced:"Committed generator output must match what the generator produces" applies to any repo that commits generator output. Candidates, in preference order:
workflow_call) in the shared ktsu workflow repo, invoked with the paths to verify.Either way the goal is that the next repo committing generator output does not copy this YAML.
Acceptance criteria
CSharpGeneratorDriversetup left inSemantics.Test.verify-generated.ymlshrinks to a call site or disappears.Context
Part of #181.