Haiku

Rust

Plain-English Rust tests. .rs.haiku files compile to integration tests and run via cargo test.

Status: available

.rs.haiku files describe what a Rust module or function should do in plain English. Haiku compiles them to integration test files (<base>_test.rs) and runs them through cargo test.

Filename

<base>.rs.haiku — e.g. cache.rs.haiku, haiku_parser.rs.haiku. The generated test file is named <base>_test.rs and is written next to the spec.

Frontmatter

---
intent: Verifies the cache correctly stores and retrieves values
sources:
  - ../src/cache.rs
tags: [cache]
---
FieldRequiredNotes
intentyesOne-line description
sourcesrecommendedOrdered list of source files the test exercises, most-called first
target.modulenoLegacy dotted module path
target.contextnoExtra source files to feed the compiler

Body

One natural-English assertion per line. Idiomatic Rust phrasings — variants, Result returns, lifetimes — are fine; the compiler understands them.

Inserting a value under a new key returns Ok(()).
Looking up a missing key returns None.
The cache evicts the least-recently-used entry once capacity is exceeded.
Cloning the cache produces an independent copy whose mutations do not affect the original.

Running

haiku recite cache.rs.haiku

On the first run Haiku compiles to cache_test.rs and invokes cargo test --test cache_test. The generated file is placed under the nearest ancestor Cargo.toml's tests/ directory so cargo picks it up as an integration test.

Requirements

  • A Cargo.toml somewhere up the directory tree from the spec
  • cargo on PATH

On this page