xtuc / sqllogictest-rs

Sqllogictest parser and runner in Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sqllogictest-rs

Crate Docs CI

Sqllogictest is a testing framework to verify the correctness of an SQL database.

This crate implements a sqllogictest parser and runner in Rust.

Using as Library

Add the following lines to your Cargo.toml file:

[dependencies]
sqllogictest = "0.6"

Implement DB trait for your database structure:

struct Database {...}

impl sqllogictest::DB for Database {
    type Error = ...;
    fn run(&mut self, sql: &str) -> Result<String, Self::Error> {
        ...
    }
}

It should take an SQL query string as input, and output the query result as a string. The runner verifies the results by comparing the string after normalization.

Finally, create a Runner on your database instance, and then run the script:

let mut tester = sqllogictest::Runner::new(Database::new());
let script = std::fs::read_to_string("script.slt").unwrap();
tester.run_script(&script);

You can also parse the script and execute the records separately:

let records = sqllogictest::parse(&script).unwrap();
for record in records {
    tester.run(record);
}

See examples directory for more usages.

Using as CLI

This crate can also be used as a command-line tool.

To install the binary, the bin feature is required:

cargo install sqllogictest-bin

You can use it as follows:

sqllogictest './test/**/*.slt'

This command will run scripts in test directory against postgres with default connection settings.

You can find more options in sqllogictest --help.

Note that only postgres is supported now.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Contributors should add a Signed-off-by line for Developer Certificate of Origin in their commits. Use git commit -s to sign off commits.

Publish the crate

cargo publish -p sqllogictest
cargo publish -p sqllogictest-bin

About

Sqllogictest parser and runner in Rust.

License:Apache License 2.0


Languages

Language:Rust 100.0%