Skip to content

Cross-Language Comparison

How does DocTest compare to doctest implementations in other languages? This page provides a feature-by-feature comparison.

Implementations

LanguageToolSince
Pythondoctest (stdlib)1999
Rustrustdoc --test2015
ElixirExUnit.DocTest2014
Gogo test (testable examples)2012
PHPDocTest2026

Feature Matrix

FeaturePythonRustElixirGoDocTest
Exact output matchingYesYesYesYesYes
Pattern/regex matching+ELLIPSISoutput-matches
Partial output matchingoutput-contains
JSON comparisonoutput-json
Inline result assertioniex> / ...>// =>
Wildcard patterns... only8 patterns ({{uuid}}, {{date}}, etc.)
Unordered outputUnordered output:
Exception testingTraceback blockshould_panic** (Error)throws attribute
Parse error testingcompile_failparse_error attribute
Skip/ignore blocks+SKIPignoreignore attribute
No-run (syntax only)no_runno_run attribute
Block groupinggroup attribute
Setup/teardownsetup / teardown
Framework bootstrapextern cratebootstrap attribute
Parallel executionYesYes--parallel flag
Auto-update expectedACCEPT mode--bless
Watch modecargo watchmix test --stale
Process isolationYesYesYes
Normalize whitespace+NORMALIZE_WHITESPACEAutomatic
Debug dumpIO.inspectdd()
Hidden setup lines# hidden line// # hidden

Key Differences

Assertion Variety

Python and Go support only exact output matching (Python adds +ELLIPSIS for basic wildcards). Rust relies on compilation and panic behavior rather than output assertions. Elixir matches return values via iex> prompts.

DocTest offers 6 distinct assertion types, allowing documentation authors to choose the right level of strictness for each code block.

Wildcard System

Python's ... is the only wildcard available in other implementations -- it matches anything. DocTest provides 8 semantic wildcards ({{uuid}}, {{date}}, {{datetime}}, {{time}}, {{integer}}, {{float}}, {{hash}}, {{any}}) that validate the format of dynamic values, not just their presence.

Block Organization

No other implementation supports grouping related code blocks with shared state. DocTest's group, setup, and teardown attributes allow multi-block sequences where earlier blocks set up context for later ones.

Framework Integration

Rust can use extern crate in doc tests. DocTest's bootstrap attribute allows loading any PHP framework (Laravel, Symfony, etc.) before execution.

Released under the MIT License.