test: harden memento generator coverage#467
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
Hardens MementoGenerator coverage by adding TinyBDD scenarios that exercise explicit capture strategies, read-only state, empty/record fallbacks, and ignored primary-constructor parameters, while fixing two emission bugs (invalid private parameterless struct constructor for empty mementos and missing constructor arguments on record restore fallback). Also adds a scenario covering the PKDEC004 inaccessible-property diagnostic in DecoratorGenerator.
Changes:
- Skip emitting the private memento struct constructor when there are no captured members.
- For record restore fallback, invoke the smallest public constructor with
default!arguments before the object initializer. - Add MementoGenerator/DecoratorGenerator test scenarios for the newly exercised branches and a missing diagnostic.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/PatternKit.Generators/MementoGenerator.cs | Guards the empty-member constructor and introduces AppendRecordFallbackConstructor for record fallback restore. |
| test/PatternKit.Generators.Tests/MementoGeneratorTests.cs | Adds scenarios for explicit strategies, record-without-primary-ctor, read-only members, empty record, and ignored primary-ctor member. |
| test/PatternKit.Generators.Tests/DecoratorGeneratorTests.cs | Adds a scenario asserting PKDEC004 fires for private protected abstract properties while public members still generate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private static void AppendRecordFallbackConstructor(StringBuilder sb, TypeInfo typeInfo) | ||
| { | ||
| var fallbackCtor = typeInfo.TypeSymbol.Constructors | ||
| .Where(c => !c.IsStatic && c.DeclaredAccessibility == Accessibility.Public) | ||
| .OrderBy(c => c.Parameters.Length) | ||
| .FirstOrDefault(); | ||
|
|
||
| if (fallbackCtor is null || fallbackCtor.Parameters.Length == 0) | ||
| { | ||
| sb.AppendLine("()"); | ||
| return; | ||
| } | ||
|
|
||
| sb.Append("("); | ||
| sb.Append(string.Join(", ", fallbackCtor.Parameters.Select(_ => "default!"))); | ||
| sb.AppendLine(")"); | ||
| } |
Test Results 12 files 12 suites 11m 0s ⏱️ Results for commit 4abaf37. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #467 +/- ##
==========================================
+ Coverage 97.00% 97.14% +0.14%
==========================================
Files 579 579
Lines 47156 47168 +12
Branches 3089 6762 +3673
==========================================
+ Hits 45743 45823 +80
+ Misses 1413 1345 -68
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Coverage |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
Refs #413.
Summary
Validation
Note: dotnet test PatternKit.slnx --configuration Release -p:TestTfmsInParallel=false --no-restore timed out locally after 10 minutes before returning a failure summary.