This document explains how to run the sql-check test suite locally.
The sql-check crate supports three databases: SQLite, PostgreSQL, and MySQL. Each requires different setup.
No setup required. SQLite tests use an in-memory database.
-
Install PostgreSQL (version 14 or later recommended)
-
Start the PostgreSQL server
-
Create a test database:
createdb sqlcheck
-
Install MySQL (version 8 or later recommended)
-
Start the MySQL server
-
Create a test database:
mysql -u root -p -e "CREATE DATABASE sqlcheck;"
DATABASE_URL="sqlite::memory:" cargo test --features sqlite,_rt-tokio,_tls-rustls-ring-webpki --testsDATABASE_URL="postgres://username:password@localhost:5432/sqlcheck" cargo test \
--features postgres,_rt-tokio,_tls-rustls-ring-webpki --testsReplace username and password with your PostgreSQL credentials.
DATABASE_URL="mysql://root:password@localhost:3306/sqlcheck" cargo test \
--features mysql,_rt-tokio,_tls-rustls-ring-webpki --testsReplace root and password with your MySQL credentials.
To run tests without compile-time SQL validation (check feature disabled):
cargo test --no-default-features --testsThe compile-fail tests verify that invalid SQL produces compilation errors. They use the trybuild crate and are located in tests/compile_fail/.
Each database has its own set of compile-fail tests with database-specific error messages:
tests/compile_fail/sqlite/- SQLite error messagestests/compile_fail/postgres/- PostgreSQL error messagestests/compile_fail/mysql/- MySQL error messages
When the error message format changes or when setting up for a new database, run tests with TRYBUILD=overwrite to capture actual error messages:
# SQLite
DATABASE_URL="sqlite::memory:" TRYBUILD=overwrite cargo test \
--features sqlite,_rt-tokio,_tls-rustls-ring-webpki compile_fail_tests_sqlite
# PostgreSQL
DATABASE_URL="postgres://username:password@localhost:5432/sqlcheck" TRYBUILD=overwrite cargo test \
--features postgres,_rt-tokio,_tls-rustls-ring-webpki compile_fail_tests_postgres
# MySQL
DATABASE_URL="mysql://root:password@localhost:3306/sqlcheck" TRYBUILD=overwrite cargo test \
--features mysql,_rt-tokio,_tls-rustls-ring-webpki compile_fail_tests_mysqlAfter running with TRYBUILD=overwrite, review the generated .stderr files and commit them.
Replace _rt-tokio with one of the following to test different async runtimes:
_rt-tokio- Tokio runtime_rt-async-std- async-std runtime_rt-smol- smol runtime_rt-async-global-executor- async-global-executor runtime
Replace _tls-rustls-ring-webpki with one of the following:
_tls-native-tls- Native TLS (requires OpenSSL on Linux)_tls-rustls-ring-webpki- Rustls with ring and webpki roots_tls-rustls-ring-native-roots- Rustls with ring and native roots_tls-rustls-aws-lc-rs- Rustls with AWS LC
The CI workflow runs tests for each database separately:
- SQLite tests run with
sqlite::memory:(no external dependencies) - PostgreSQL tests run against a PostgreSQL Docker container
- MySQL tests run against a MySQL Docker container
Each database's compile-fail tests only run when that database's feature is enabled, ensuring the correct error messages are validated.