Skip to content

End-to-end test harness for the #[contract] macro #29

@moCello

Description

@moCello

Problem

The #[contract] macro's test surface has a structural gap. Today's layers:

Layer Coverage
Unit tests in src/ modules Pure-Rust helpers — extract::*, validate::*, resolve::*. No macro expansion involved.
tests/compile_fail.rs + tests/compile-fail/ A handful of trybuild fixtures asserting invalid inputs are rejected.
tests/test-contract/ One reference contract that exercises the macro end-to-end into a WASM build.

What's missing is "this attribute combination expands and compiles" coverage of variations. The single test-contract pins one fixed shape; the compile-fail bench is sparse relative to the dozens of validation paths in validate.rs. There is no compile-pass harness at all.

Recent macro-internal refactors have shown that validator unit tests aren't sufficient: a validate.rs change can leave the validation function happy while the downstream generate.rs chokes on the resulting IR. That regression class needs a dedicated guard.

Proposal

Build out the test-harness layer:

  1. Reorganize existing compile-fail fixtures under topic dirs (directives/, feature_gates/, methods/, traits/, events/).
  2. Add one compile-fail fixture per rejection rule in validate.rs, with a // Pins: <rule-id> header tying each fixture back to the reject branch it guards.
  3. Add a compile-pass harness covering valid contract shapes that the reference test-contract does not exercise (e.g. new() -> ContractName instead of -> Self, contracts without an init method, init(&mut self) with no parameters).
  4. Document the topic taxonomy and fixture conventions in tests/README.md so contributors adding a rule know where the fixture goes and what header it needs.

Out of scope

  • Changes to validate.rs itself. If a rule is broken, unreachable, or duplicated, that's a separate issue.
  • Changes to tests/test-contract/ (the reference contract stays as-is).
  • macrotest-style token-stream drift detection. The existing make expand / make expand-dd baselines already cover that for the single test-contract shape; a parameterised version is deferrable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions