Skip to main content

Executable tutorial testing - make documentation tutorials runnable as tests

Project description

validoc

Executable Tutorial Testing Tool

validoc makes documentation tutorials executable. The tutorial is the test. Single source of truth.

Problem

Documentation tutorials suffer from documentation rot: they become outdated as software evolves, but there's no automated way to detect this. Users follow broken tutorials and blame themselves.

Solution

Annotate markdown code blocks to make them executable:

```bash exec
echo "Hello, World!"
```

```output contains
Hello
```

Run the tutorial as a test:

validoc run docs/tutorials/getting-started.md

Installation

# Install with uv
uv add validoc

# Or install with pip
pip install validoc

For development:

git clone https://github.com/abilian/validoc.git
cd validoc
uv sync --all-extras

Quick Start

# Run a tutorial
validoc run examples/01-hello-world.md

# Run with verbose output
validoc run examples/01-hello-world.md -v

# Keep files for debugging
validoc run tutorial.md --workdir /tmp/test --no-teardown

# Validate without executing
validoc check tutorial.md

# List executable blocks
validoc list tutorial.md

Features

  • Readable first - Tutorials remain beautiful, human-readable markdown
  • Standard markdown - Works with GitHub, MkDocs, VS Code without modification
  • Multiple block types - Execute commands, create files, verify output, assert conditions
  • Sandbox execution - Runs in temporary directory, cleans up after
  • Debug-friendly - --no-teardown preserves files for inspection

Block Types

Type Syntax Purpose
Execute ```bash exec Run shell commands
File ```file path=config.yml Create files
Output ```output contains Verify command output
Assert ```assert file-exists path=app.py Check conditions

Execute Block Attributes

Attribute Description
id=name Unique identifier
dir=path Working directory
timeout=60 Timeout in seconds
expect=1 Expected exit code
skip Skip this block
continue-on-error Don't stop on failure

Output Matching Modes

Mode Description
output contains Text appears in output (default)
output exact Exact match
output regex Regular expression

Tutorial Configuration

Use YAML frontmatter for configuration:

---
tutorial:
  name: my-tutorial
  env:
    DEBUG: "true"
  setup:
    - echo "Setting up..."
  teardown:
    - rm -rf myapp || true
---

Examples

The examples/ directory contains tutorials demonstrating all features:

  • 01-hello-world.md - Minimal example
  • 02-file-creation.md - Creating files
  • 03-output-matching.md - Output verification modes
  • 04-assertions.md - Assertion types
  • 05-frontmatter.md - YAML configuration

Run all examples:

uv run pytest tests/c_examples -v

Documentation

Document Description
docs/TUTORIAL.md Comprehensive user guide
notes/SPECS.md Complete specification
notes/DESIGN.md Architecture and design

Development

# Install with dev dependencies
uv sync --all-extras

# Run all tests (98 tests)
uv run pytest

# Run specific test categories
uv run pytest tests/a_unit           # Unit tests
uv run pytest tests/b_integration    # Integration tests
uv run pytest tests/c_examples       # Example tests

# Linting
uv run ruff check src tests

Package Structure

src/validoc/
├── cli.py         # Command-line interface
├── parser.py      # Markdown parser
├── executor.py    # Block execution
├── runner.py      # Orchestration
├── reporter.py    # Console output
├── models.py      # Data structures
└── constants.py   # Enums

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

validoc-0.1.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

validoc-0.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file validoc-0.1.0.tar.gz.

File metadata

  • Download URL: validoc-0.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for validoc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 599a8f5d42317880dcfb4cd930051ef45d3ec034c011e4eaf68fc73dd8c9b292
MD5 dcc1b3a67398db564dc4d4bce176e184
BLAKE2b-256 8c808b3af1b6ccf4d8d72680e94c4a0cbf6def967fa837a83053cb5cae0701f5

See more details on using hashes here.

File details

Details for the file validoc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: validoc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for validoc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b40b6216fd1042e1b869bd3457a84557a34e4d0a100dd804a4cee6a4906a4198
MD5 6349c8464a99a4962fd19c7fbe86c818
BLAKE2b-256 529bc3d5bee5198ba15decda96bef003c791fa44e443c13bba04f20cf07c3a5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page