Testing
TMT’s test suite lives in the tests/ directory and covers two main areas.
Configuration Validation Tests (tests/config_validation.rs)
These tests exercise the RuntimeConfig::try_from validation logic by constructing Cli structs with deliberate constraint violations and asserting that the correct AppError variant is returned.
Covered scenarios include:
- Missing API token (neither
--api-tokennorTMT_API_TOKENset). - Whitespace-only API token.
--concurrency 0(must be ≥ 1).- Identical source and target language codes.
--dpi 0(must be ≥ 1).--jpeg-quality 0and--jpeg-quality 101(must be in [1, 100]).--font-pathpointing to a non-existent file.
Retry-After Parsing & Sentence Splitting Tests
tests/parse_retry_after.rs
Validates the HTTP Retry-After header parser used by TmtClient. Tests cover:
- Integer values (
Retry-After: 30). - HTTP-date values (
Retry-After: Wed, 21 Oct 2025 07:28:00 GMT). - Missing or malformed headers.
tests/sentence_split.rs
Validates split_sentences from src/translate/sentence.rs. Tests cover:
- Splitting on
.,!,?. - Splitting on the Devanagari danda
।. - Fragment merging behaviour for short (<5 character) fragments.
- Empty strings and strings with no delimiters.
Running the Tests
# All tests
cargo test
# A specific test file
cargo test --test config_validation
# With PDF feature enabled
cargo test --features pdf
Adding New Tests
Integration tests belong in tests/. Unit tests for a module can be added inline in the source file in a #[cfg(test)] block:
#![allow(unused)]
fn main() {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn my_test() {
// ...
}
}
}