Skip to content

Canonicalize tests around @safetestset (isolation, matches OrdinaryDiffEq)#45

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:mainfrom
ChrisRackauckas-Claude:canonicalize-safetestset
Closed

Canonicalize tests around @safetestset (isolation, matches OrdinaryDiffEq)#45
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:mainfrom
ChrisRackauckas-Claude:canonicalize-safetestset

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor

What

Canonicalizes the test suite around @safetestset so each independent top-level test unit runs in its own fresh module, matching OrdinaryDiffEq's structure (per-unit isolation + world-age safety). This is the pilot for a fan-out across SciML repos.

Classification

ConcreteStructs.jl was a plain-@testset repo: independent units were plain @testset blocks at file scope, sharing module-level setup. Converted to @safetestset.

Before -> after pattern

Each independent unit @testset "X" begin BODY end becomes @safetestset "X" begin BODY end. A @safetestset body expands to a fresh module and is macroexpanded as one unit, so an in-body using ConcreteStructs does not take effect before in-body @concrete usage is resolved (UndefVarError). The canonical fix (same as OrdinaryDiffEq) is:

@safetestset "X" begin include("x.jl") end

where x.jl carries its own top-level using lines (resolved before the package macros are reached).

  • test/core.jl is now a thin @safetestset ... include(...) dispatcher. Its four units are split into self-contained files: unit_tests.jl, end_to_end_tests.jl, issue_3.jl, commutation_tests.jl, each with its own using lines (ConcreteStructs, and as needed LinearAlgebra: Adjoint, Suppressor, Test, or the internal ConcreteStructs: _parse_line, ... helpers).
  • Nested grouping @testsets inside a unit (e.g. _parse_line, _parse_head inside "Unit tests") stay plain @testset — the unit-level @safetestset already isolates.
  • test/qa/qa.jl: the Aqua and JET units become @safetestset with their own using lines.
  • test/runtests.jl: the top-level "Invalid usage error path" unit becomes @safetestset (self-contained using ConcreteStructs; using Test); using SafeTestsets added at the top.

SafeTestsets added to test/Project.toml and test/qa/Project.toml deps + [compat] SafeTestsets = "0.1, 1".

Unchanged

GROUP dispatch ladder, run logic, and all assertions are untouched. The run_tests/harness migration is a separate branch.

Verification (Julia 1.11, local)

Identical assertion counts to the pre-conversion baseline:

  • GROUP=Core: Unit tests 23, End-to-end 11, Issue Feature Request: Type Constraints #3 1, Commutation 4, Invalid usage 1 — passed
  • GROUP=QA: Aqua 11, JET 1, Invalid usage 1 — passed
  • All (GROUP unset): all of the above — passed

Ignore until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

…ffEq)

Wrap each independent top-level test unit in `@safetestset` so it runs in
its own fresh module, matching OrdinaryDiffEq's canonical structure
(per-unit isolation + world-age safety).

The `@safetestset` body must be self-contained: a body is macroexpanded as
one unit, so `using ConcreteStructs` followed by in-body `@concrete` usage
fails (the import hasn't taken effect when `@concrete` is resolved). The
canonical fix is `@safetestset "X" begin include("x.jl") end`, where the
included file carries its own top-level `using` lines (resolved before the
macros are reached). The unit bodies of core.jl are therefore split into
unit_tests.jl, end_to_end_tests.jl, issue_3.jl, commutation_tests.jl, each
self-contained. qa.jl's Aqua/JET units and the "Invalid usage error path"
unit in runtests.jl become `@safetestset` with their own imports.

Nested grouping `@testset`s inside a unit stay plain (the unit-level
`@safetestset` already isolates). GROUP dispatch, run logic, and assertions
are unchanged.

SafeTestsets added to test/Project.toml and test/qa/Project.toml deps +
compat ("0.1, 1").

Behavior-preserving, verified locally on Julia 1.11:
  GROUP=Core: Unit 23, End-to-end 11, Issue SciML#3 1, Commutation 4, Invalid 1
  GROUP=QA:   Aqua 11, JET 1, Invalid 1
  All:        all of the above
identical to the pre-conversion baseline.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor Author

Superseded by the v1.2 folder conversion on sciml-testing-rollout (#44).

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