Skip to content

Testing

Terminal window
# All tests
cargo nextest run
# Specific test
cargo nextest run test_splitter_basic
# With output
cargo nextest run --no-capture

In-module tests for specific functions:

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_create_table() {
// ...
}
}

End-to-end tests in tests/:

tests/splitter_integration_test.rs
#[test]
fn test_split_mysql_dump() {
let output = Command::new("./target/release/sql-splitter")
.args(["split", "tests/fixtures/static/mssql/simple.sql", "-o", "output/"])
.output()
.expect("failed to execute");
assert!(output.status.success());
}

Test against real SQL dumps:

Terminal window
just verify-realworld

The model_yaml target mutates complete generate model files. It exercises UTF-8 and YAML rejection, error formatting, model compilation, bounded row generation, and SQL rendering to an I/O sink. The target runs the public in-process pipeline. CLI integration tests cover argument parsing and file handling.

Install cargo-fuzz and the Rust nightly toolchain once:

Terminal window
cargo install cargo-fuzz
rustup toolchain install nightly

Run it for 60 seconds, or pass a longer duration:

Terminal window
just fuzz-model-yaml
just fuzz-model-yaml 600

The run limits each input to 64 KiB, each table to eight rows, each input to five seconds, and each process to explicit allocation and resident-memory bounds. Minimize the accumulated corpus after a long or parallel run:

Terminal window
just fuzz-model-yaml-cmin

Crashing inputs are written to fuzz/artifacts/model_yaml/. Reproduce and minimize one with:

Terminal window
cargo +nightly fuzz run model_yaml fuzz/artifacts/model_yaml/<artifact>
cargo +nightly fuzz tmin model_yaml fuzz/artifacts/model_yaml/<artifact>

Located in tests/fixtures/:

tests/fixtures/
├── generated/ # Test data generated at test time (gitignored)
└── static/
├── mysql/
│ ├── duplicate_pk.sql
│ ├── escaped_strings.sql
│ ├── fk_missing_parent.sql
│ └── missing_table.sql
├── postgres/
│ └── copy_with_nulls.sql
├── sqlite/
│ └── minimal_tenant.sql
└── mssql/
├── edge_cases.sql
├── multi_tenant.sql
└── simple.sql
  1. Create fixture files in tests/fixtures/static/
  2. Write unit tests in the module
  3. Write integration test in tests/
  4. Run cargo nextest run
-- tests/fixtures/static/mysql/my_feature.sql
CREATE TABLE test (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100)
);
INSERT INTO test VALUES (1, 'Alice');
INSERT INTO test VALUES (2, 'Bob');
#[test]
fn test_my_feature() {
let result = my_function("tests/fixtures/static/mysql/my_feature.sql");
assert!(result.is_ok());
assert_eq!(result.unwrap().table_count, 1);
}
Terminal window
cargo install cargo-tarpaulin
cargo tarpaulin --out Html

Open tarpaulin-report.html to view coverage.