Skip to content

test: run tests against the netstandard2.1 build - #468

Open
aetos382 wants to merge 2 commits into
Cysharp:mainfrom
aetos382:test/netstandard
Open

aetos382 wants to merge 2 commits into
Cysharp:mainfrom
aetos382:test/netstandard

Conversation

@aetos382

Copy link
Copy Markdown
Contributor

Summary

Adds MemoryPack.Tests.NetStandard, a test project that runs the existing tests of MemoryPack.Tests against the netstandard2.1 build of MemoryPack.Core and MemoryPack.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 #else side 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

  • The project links the sources of MemoryPack.Tests instead of duplicating them.
  • MemoryPack.Core and MemoryPack.Streaming are referenced with SetTargetFramework="TargetFramework=netstandard2.1".
  • DisableImplicitFrameworkDefines removes the NET*_OR_GREATER symbols. The generator chooses its output based on NET7_0_OR_GREATER in 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.
  • The tests still run on the .NET 8 runtime. This does not test the behavior of Mono or IL2CPP.

Changes to existing tests

  • SerializerStructBufferWriterTest: wrapped in #if NET7_0_OR_GREATER, because the netstandard2.1 build requires TBufferWriter to be a reference type.
  • UnionTest: when NET5_0_OR_GREATER is 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/** and Utils/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

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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>
@aetos382

Copy link
Copy Markdown
Contributor Author

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 (LICENSE_NET.txt), so dependency-review reports it as NOASSERTION. That license is not in the allow list. Versions 17.10.0 and later use the MIT license expression. MemoryPack.Tests is updated as well, because the two projects share the same test sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants