Skip to content

feat: add test runner support types for compiler-agnostic testing#368

Draft
decofe wants to merge 5 commits intomainfrom
zerosnacks/test-runner-support
Draft

feat: add test runner support types for compiler-agnostic testing#368
decofe wants to merge 5 commits intomainfrom
zerosnacks/test-runner-support

Conversation

@decofe
Copy link
Copy Markdown
Contributor

@decofe decofe commented Apr 10, 2026

Summary

Add types and traits that enable non-Solidity compilers to plug into Foundry's test runner (fuzzing, cheatcodes, invariant testing) without depending on solar/NatSpec internals.

Motivation

Tweet thread from @real_philogy requesting the ability to plug a custom compiler into Foundry and reuse the fuzzing, testing, and cheatcode-augmented EVM runtime. This is the foundry-compilers side of that work.

Changes

New test_support module with:

Types:

  • FuzzLiteral — enum of literal values (addresses, ints, bytes, strings) a compiler can extract from source to seed the fuzzer dictionary. FixedBytes variant includes explicit size: u8 for type-safe bytesN width.
  • InlineConfigEntries / InlineConfigEntry — per-test config overrides (Solidity uses NatSpec /// forge-config: comments; other languages use their own syntax)
  • All types are #[non_exhaustive] for forward compatibility

Trait:

  • TestRunnerSupport — supertrait of Compiler with fuzz_literals() and inline_config() methods. Default implementations return empty results, so compilers work out of the box. Uses #[auto_impl] matching the Compiler trait pattern.

Testing

Types + trait with defaults (no complex logic), verified with cargo check and cargo clippy.

Next steps

  • Implement TestRunnerSupport for SolcCompiler (move solar literal extraction + NatSpec parsing here)
  • Implement TestRunnerSupport for MultiCompiler (delegate to inner compilers)
  • Once foundry-compilers publishes, update foundry to use these types directly instead of local mirrors

Prompted by: zerosnacks

Add FuzzLiteral, InlineConfigEntries, and InlineConfigEntry types that
compilers can use to provide source-level analysis to Foundry's test
runner. This enables non-Solidity compilers to seed the fuzz dictionary
and provide per-test config overrides without depending on solar/NatSpec.

All types are #[non_exhaustive] for forward compatibility.

Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
decofe and others added 4 commits April 10, 2026 18:49
Add the TestRunnerSupport trait that compilers can implement to provide
source-level metadata (fuzz literals, inline config) to Foundry's test
runner. Default implementations return empty results, so compilers work
out of the box without implementing this trait.

Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
…quirement

- Remove unused `source: PathBuf` field from InlineConfigEntry
- Update docs to clarify config_values should NOT include the
  forge-config: prefix (bridge adds it automatically)

Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Use Self::CompilationError and Self::CompilerContract instead of
generic <E, C> params. This makes the trait actually useful for
downstream compilers that need to inspect their own output types.

Remove #[auto_impl] since the trait has default impls and Compiler
already provides auto_impl for wrapper types.

Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
@decofe decofe marked this pull request as ready for review April 10, 2026 19:36
@decofe decofe marked this pull request as draft April 10, 2026 19:46
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