Skip to content

feat: show the built-in test framework on the home page - #214

Merged
magnus-madsen merged 1 commit into
masterfrom
test-framework-section
Aug 9, 2026
Merged

feat: show the built-in test framework on the home page#214
magnus-madsen merged 1 commit into
masterfrom
test-framework-section

Conversation

@magnus-madsen

Copy link
Copy Markdown
Member

The tooling comparison table further down the page claims that flix is its own test framework, but nothing on the page showed what a test actually looks like.

Adds a section between Termination Checking and First-class Datalog Constraints, text-left / code-right so the alternation across the page continues.

The example

use Assert.{assertEq, assertErr}

def divide(x: Int32, y: Int32): Result[String, Int32] =
    if (y == 0) Err("Division by zero") else Ok(x / y)

@Test
def testDivide01(): Unit \ Assert =
    assertEq(expected = Ok(5), divide(10, 2))

@Test
def testDivide02(): Unit \ Assert =
    assertErr(divide(10, 0))

It shows @Test, two assertions from the Assert module including the labelled expected argument, and the \ Assert effect — which lets the card tie testing back to the effect system the preceding twenty sections build up: asserting is an effect, so the test runner is just its handler.

Underneath the snippet is the output of flix test:

Running 2 tests...

   PASS  testDivide01 1.4ms
   PASS  testDivide02 0.3ms

Passed: 2, Failed: 0. Skipped: 0. Elapsed: 2.1ms.

Notes

The output is terminal text, not Flix, so it bypasses CodeSnippet and renders through a plain <pre> that reuses the component's frame — CodeSnippet only knows the Flix grammar and would colour the PASS lines as if they were code. No new CSS; overflow-x is set inline because Astro's <Code> ships that on the <pre> it renders and a bare one has nothing.

Timings are written with a decimal point. The book shows 1,4ms, which is the runner picking up a Danish locale.

Rebased onto #212 and #213; the diff is 62 insertions and no deletions. npm run check and npm run build both pass.

🤖 Generated with Claude Code

The tooling comparison table claims that flix is its own test framework, but
nothing on the page showed what a test looks like.

Adds a section between termination checking and Datalog: two @test functions
using assertEq and assertErr from the Assert module, followed by the output of
`flix test`. The example carries the Assert effect in its signature, which ties
testing back to the effect system the surrounding sections build up.

The output is terminal text rather than Flix, so it renders through a plain
<pre> that reuses the CodeSnippet frame; the component only knows the Flix
grammar and would colour the PASS lines as code.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@magnus-madsen
magnus-madsen merged commit 5356aff into master Aug 9, 2026
2 checks passed
@magnus-madsen
magnus-madsen deleted the test-framework-section branch August 9, 2026 07:17
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.

1 participant