Files
turso/testing/sqltest/docs
Claude 6bcb8e6def sqltest: add a postgres backend that runs tests on a real PostgreSQL server
The PostgreSQL corpus must expect only what PostgreSQL itself does, but
until now it ran only against tursopg. An expectation that only tursopg
meets passed CI, and nothing showed that it was wrong.

`--backend postgres --postgres-dsn <url>` runs the tests on the server at
the URL. For each test, the backend creates a new database from
template0 and drops it after the test, so tests stay isolated when they
run in parallel. At most four CREATE DATABASE and DROP DATABASE
statements run at the same time, so a run uses at most --jobs + 4
connections. A random part in the database names lets two runs share
one server.

`@skip-if postgres "reason"` and `@skip-file-if postgres "reason"` skip
tests of Turso-specific behavior on this backend. `postgres` is parsed
from an identifier, not a keyword token, so `@backend postgres` and
names such as `setup postgres` still parse.

Tests: parser and runner unit tests for the skip condition, and the
pg-sqltests corpus against PostgreSQL 17

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R3hzXhfjBgyLPUF7vd3PHW
2026-10-15 03:04:08 +00:00
..

Turso Test Runner Documentation

This directory contains documentation for the sqltest crate.

Quick Start

# Build (from the repository root)
cargo build --release

# Check test file syntax
./target/release/sqltest check sqlite/conformance/sqlite-sqltests/

# Run tests
./target/release/sqltest run sqlite/conformance/sqlite-sqltests/ --binary ./target/release/tursodb

The .sqltest corpora live in sqlite/conformance/ (sqlite-sqltests/ for SQLite-compatible coverage, turso-sqltests/ for Turso-specific behavior); make -C sqlite/conformance run drives the full suite.

Documentation Index

User Documentation

Document Description
DSL Specification Complete specification of the .sqltest file format
CLI Usage Command-line interface reference

Architecture & Design

Document Description
Architecture System architecture and backend trait design
Parallelism Parallel execution strategy and implementation

Backend Documentation

Document Description
CLI Backend CLI backend implementation details
Adding Backends Guide for implementing new SDK backends

Examples

Example test files are available in the examples/ directory:

  • examples/basic.sqltest - Basic DSL syntax examples
  • examples/joins.sqltest - Setup composition and join tests

Crate Structure

sqltest/
├── src/
│   ├── lib.rs              # Public API exports
│   ├── main.rs             # CLI binary entry point
│   ├── parser/             # DSL parser (Logos lexer)
│   │   ├── mod.rs          # Parser entry point
│   │   ├── lexer.rs        # Tokenizer
│   │   └── ast.rs          # AST types
│   ├── backends/           # SQL execution backends
│   │   ├── mod.rs          # SqlBackend trait
│   │   └── cli.rs          # CLI subprocess backend
│   ├── runner/             # Test execution
│   │   ├── mod.rs          # TestRunner, parallel execution
│   │   └── executor.rs     # Single test executor
│   ├── comparison/         # Result comparison
│   │   ├── mod.rs          # Comparison dispatcher
│   │   ├── exact.rs        # Exact match (with diff)
│   │   ├── pattern.rs      # Regex pattern match
│   │   └── unordered.rs    # Set comparison
│   └── output/             # Output formatting
│       ├── mod.rs          # OutputFormat trait
│       ├── pretty.rs       # Colored terminal output
│       └── json.rs         # JSON output for CI
├── docs/                   # Documentation (this directory)
└── examples/               # Example test files

Key Concepts

Test File Structure

# Database configuration
@database :memory:

# Named setup blocks
setup users {
    CREATE TABLE users (id INT, name TEXT);
}

# Test with setup decorator
@setup users
test select-users {
    SELECT * FROM users;
}
expect {
    1|Alice
}

Isolation Model

All tests are isolated by default:

  • Each test gets a fresh database instance
  • Tests run in parallel
  • No shared state between tests

Backend System

The runner uses a trait-based backend system for extensibility:

trait SqlBackend {
    fn create_database(&self, config: &DatabaseConfig)
        -> Result<Box<dyn DatabaseInstance>>;
}

trait DatabaseInstance {
    async fn execute(&mut self, sql: &str) -> Result<QueryResult>;
    async fn close(self: Box<Self>) -> Result<()>;
}

Dependencies

Crate Purpose
clap CLI argument parsing
logos Lexer generation
tokio Async runtime & parallelism
similar Diff generation for comparisons
colored Terminal colors
serde_json JSON output

License

MIT