Skip to content

Testing: assert a union error's case without matching on it (net11.0) #210

Open

Description

@CaffeinatedCoder

What you're trying to do

Assert which case of a union error a Result failed with. With a union TError (public union OrderFault(NotFound, Conflict);), ShouldBeError() returns the union, and the test then has to match on it. On Metalama 2026.1 (2.3.x) a woven test project can't do that at all (CS8652, decision 120); 2.4.0 moves to Metalama 2027.0 (decision 129), where it can, and the assertion still saves the match.

What you'd like

A net11.0-only member in CodoMetis.TypeKit.Testing that does the matching inside TypeKit's own C# 15 build, so the test only names the case type:

NotFound fault = result.ShouldBeErrorCase<NotFound>();
  • TError is constrained to IUnion, and the case is read through IUnion.Value, so a custom union works too.
  • On failure, the message names the expected case and the actual case's type, never the content. That is the same rule as the rest of the Testing package.
  • The name, and whether Option<TUnion> gets a sibling, are decided in the PR.
  • Async forms like the existing ShouldBeError overloads, if the package's pattern asks for them.

To measure: that a woven net11.0 project on Metalama 2027.0 calls it, and a net10.0 one does not see it.

A claim in test/oracles/claims.json for the new member; the changelog says it's net11.0 only.

Does it change something that compiles or works today?

No, it only adds, on net11.0.

Activity

  1. added this to the 2.4.0 milestone on Oct 30, 2026
  2. added
    enhancement
    package/testing
    area/option-result
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/option-resultenhancementpackage/testing

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions