Repository navigation
Conversation
Add MemoryPack.Tests.NetStandard, which links the sources of MemoryPack.Tests and references MemoryPack.Core and MemoryPack.Streaming with SetTargetFramework=netstandard2.1. NET*_OR_GREATER symbols are disabled so that test code and generated code take the same path as netstandard2.1 consumers (e.g. Unity). - Exclude source generator tests and MemoryLayoutTest, which do not depend on the target framework of the libraries. - Skip SerializerStructBufferWriterTest when NET7_0_OR_GREATER is not defined, because the netstandard2.1 build requires TBufferWriter to be a reference type. - Register external union formatters manually in UnionTest when NET5_0_OR_GREATER is not defined, because generated initializers have [ModuleInitializer] only in that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
CI confirmation is still needed that the new suite resolves and executes against the intended netstandard2.1 assemblies.
No open issues 🎉
What changed in this PR
Adds coverage for the netstandard2.1 library builds used by Unity, preparing for the collection changes discussed in #460. Tests still run on .NET 8, not Mono or IL2CPP.
Changes:
- Reuses existing test sources in a new project targeting netstandard2.1 library assemblies.
- Adjusts conditional compilation and union registration for that build.
- Integrates the new project into the solution.
| File | Description |
|---|---|
| tests/MemoryPack.Tests/UnionTest.cs | Registers external union formatters when module initializers are disabled. |
| tests/MemoryPack.Tests/SerializerStructBufferWriterTest.cs | Excludes unsupported struct buffer-writer tests. |
| tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj | Links shared tests and selects netstandard2.1 library builds. |
| MemoryPack.sln | Adds the new test project and build configurations. |
Review effort: Balanced
Microsoft.NET.Test.Sdk 17.3.1 is distributed under the Microsoft .NET Library license (LICENSE_NET.txt), which is not in the allow list of dependency-review. 17.10.0 and later use the MIT license expression. Update both test projects to the same version, because they share the same test sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Both test projects are updated from 17.3.1 to 17.14.1. Version 17.3.1 is distributed under the Microsoft .NET Library license ( |
Summary
Adds
MemoryPack.Tests.NetStandard, a test project that runs the existing tests ofMemoryPack.Testsagainst the netstandard2.1 build ofMemoryPack.CoreandMemoryPack.Streaming.Today, the tests run only on net8.0, so code that ships only in the netstandard2.1 build is never tested. This includes the
#elseside of#if NET7_0_OR_GREATER/NET8_0_OR_GREATER. That build is the one Unity uses through NuGetForUnity.This is preparation for #460. Several of the affected code paths (
BitArrayFormatter,StackFormatter,ImmutableArrayFormatter) also run in the netstandard2.1 build, so I want them covered by tests before changing them.How it works
MemoryPack.Testsinstead of duplicating them.MemoryPack.CoreandMemoryPack.Streamingare referenced withSetTargetFramework="TargetFramework=netstandard2.1".DisableImplicitFrameworkDefinesremoves theNET*_OR_GREATERsymbols. The generator chooses its output based onNET7_0_OR_GREATERin the consuming project, so without this the generated code would not compile against the netstandard2.1 build. With it, both the test code and the generated code take the same path as netstandard2.1 consumers such as Unity.Changes to existing tests
SerializerStructBufferWriterTest: wrapped in#if NET7_0_OR_GREATER, because the netstandard2.1 build requiresTBufferWriterto be a reference type.UnionTest: whenNET5_0_OR_GREATERis not defined, the external union formatters are registered manually in the constructor. Generated initializers have[ModuleInitializer]only when that symbol is defined, which matches the manual registration that the README describes for Unity.Excluded from the new project:
SourceGeneratorTests/**andUtils/CSharpGeneratorRunner.cs: these run the generator on their own in-memory compilation and do not depend on the target framework of the libraries. The TypeScript tests also write to a shared file in the temp directory, which could conflict when both test projects run in parallel.MemoryLayoutTest: this only checks the struct layout of the runtime, which is the same in both projects.🤖 Generated with Claude Code