Repository navigation
Add unit tests for the weaver - #4
Merged
Merged
Conversation
….Tests) xUnit v3 on Microsoft Testing Platform, net10.0. Covers the equivalence comparers and Program.Annotate/AnnotateType on in-memory Cecil modules, including the by-ref generic instance regression from #1. Runs in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up 3 from #1: the only tests were whole-project builds under
tests/, which is how theTypeReferenceEquivalenceComparerbug (Cecil'sGetElementType()returns the innermost type, soNullable<bool>&compared equal toNullable<byte>&) went unnoticed. This adds a small, fast unit test project for the weaver and runs it in CI.ICSharpCode.ReferenceAssemblyAnnotator.Tests: xUnit v3 (xunit.v3.mtp-v24.0.3) on Microsoft Testing Platform,net10.0. The tests build tiny Cecil modules in memory (CecilBuilder), so they need no files and no real reference assemblies, and run in about a second.What the tests cover (12 tests)
Nullable<bool>vsNullable<byte>(the regression); array rank; nested vs top-level types; generic arity; the same type shape from two different modules/assemblies compares equal (and has the same hash code).Program.AnnotateType(the full type walk, includingFindMatchingMethod): theM(out bool?)/M(out byte?)case that used to throw inSingleOrDefault(MSB4018 for consumers); each overload now gets its own annotation.Program.Annotate: existing nullability attributes are replaced, not duplicated; unrelated attributes are kept.IsExcludedAnnotation:[DisallowNull]is not copied ontoEqualityComparer<T>.GetHashCode/IEqualityComparer<T>.GetHashCode(theory over both types), while other annotations on the same parameter still are.Changes
ICSharpCode.ReferenceAssemblyAnnotator.Tests/, added toReferenceAssemblyAnnotator.slnx. It inherits signing, nullable, StyleCop and warnings-as-errors fromDirectory.Build.props;IsPackable=false.<PackageDownload Remove="Microsoft.NETCore.App.Ref" />: net10.0 isn't annotated, and the SDK adds its own targeting pack download when the pack isn't installed, so the repo-wide one would fail with NU1505 (same reason as thetests/projects).InternalsVisibleTofor the test assembly (sameKey.snk, so the same public key asCecilBasedAnnotator), andProgram.AnnotateType/Program.Annotatechanged fromprivatetointernal. No behavior change.global.json:"test": { "runner": "Microsoft.Testing.Platform" }, sodotnet testruns in MTP mode.dotnet test --project ICSharpCode.ReferenceAssemblyAnnotator.Tests -c Release --no-build).setup-dotnetnow installs10.0.xalongside11.0.x, because the net10.0 test app needs the .NET 10 runtime and MTP apps don't roll forward across major versions.CLAUDE.md: the "There is no unit test project" line is replaced with how the unit tests work and how to run them.Validation
dotnet build ReferenceAssemblyAnnotator.slnx -c Release: 0 warnings, 0 errors.GetElementType(), 4 tests fail (ByReference_…,Pointer_…,MethodDefinition_…,AnnotateType_MatchesByRefGenericOverloads). The fix was restored afterwards..nupkgis produced (the test project isn't packed).build/test.ps1 -Configuration Release -Engine dotnet: all 17 test builds pass. Themsbuildengine wasn't run locally; CI covers it.Not done, on purpose
Program.Main(it needs real files and a resolvable core library); thetests/projects already cover that path.🤖 Generated with Claude Code