Reorganize and refactor CGP test suite#246
Merged
Merged
Conversation
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.
AI Overview
This PR restructures the CGP test suite so that tests are grouped by the feature they exercise rather than by the macro that happens to appear in them. The old layout bucketed tests under construct names like
cgp_fn_tests,component_tests, anddispatcher_macro_tests, which mixed unrelated concerns — a single construct such asdelegate_components!served basic delegation,opendispatch, and namespaces all at once, so its bucket revealed nothing about what was actually being verified. The new layout replaces those buckets with concept targets likebasic_delegation,abstract_types,namespaces, andhigher_order_providers, each named for the behavior under test. No test coverage was removed in the process; every runtime test, compile-time wiring check, and provider/context definition from the old suite is preserved.The structural change
Each concept is now its own Cargo integration test target, which gives it an isolated coherence scope — the same property a separate crate has, and one that matters because CGP tests are dominated by type-level wiring that lives at module scope. A target is two things: an entrypoint file
tests/<concept>_tests.rsthat carries the module doc comment and a singlepub mod, and a module directorytests/<concept>/whosemod.rslists one file per unit test. Within a target, every unit test lives in its own self-contained file that defines its own components, providers, and context types, because separate files are the only reliable isolation for module-scope constructs.The suite also moved out of the library crate entirely. On
main, some tests lived undersrc/tests/(compiled via#[cfg(test)]) and some namespace fixtures lived undersrc/namespaces/; both are now integration targets undertests/, andsrc/lib.rsholds only shared support code (currently none). The macro-test crate was reorganized the same way and gained two new failure-case targets,parser_rejectionsandinvalid_expansion, that are seeded and ready to grow. Two auxiliary packages,cgp-test-crate-aandcgp-test-crate-b, were added to exercise cross-crate behavior under Rust's coherence and orphan rules.How snapshots were consolidated
A key discipline in the new layout is that each macro is snapshotted only in the concept target that owns its feature, and invoked plainly everywhere else. A macro snapshot pins the pretty-printed generated code as a golden assertion, so a redundant snapshot in a non-owning file adds nothing but a golden string that breaks whenever unrelated codegen changes. The reorg therefore stripped the incidental
snapshot_*!wrappers that the old by-construct files scattered across the suite, leaving one canonical snapshot (plus its genuinely distinct variants) per macro in its owning target. This removes only golden-string assertions, never compile or runtime coverage, because the plain macro still expands and runs.Impacts
The changes ripple through the test suite, its supporting crates, and its documentation. The following list captures the concrete effects a reviewer should expect to see in the diff:
src/totests/. The library-based tests and namespace fixtures became integration targets;src/lib.rsis now effectively empty.parser_rejectionsandinvalid_expansionfailure-case targets as a foundation for future corner cases.cgp-test-crate-a/cgp-test-crate-bpackages verify that a downstream crate can wire a foreign component, define a local provider for a foreign provider trait, and participate in an upstream namespace.#[cgp_impl]snapshots were restored. The#[cgp_impl]+#[implicit]expansion (inimplicit_arguments) and the#[cgp_impl]+#[use_provider]expansion (inhigher_order_providers) are pinned again, matching the ownership table and recovering golden coverage that had existed before the reorg.These changes are structural and organizational: they change where tests live and how their generated code is pinned, not what behavior the suite verifies. A reviewer can therefore focus on whether the concept groupings are sensible and whether the snapshot ownership is placed correctly, confident that the behavioral coverage is unchanged from
main.