CLI Integration Tests#
Rust-based integration tests for the mlf command-line interface. These tests verify end-to-end CLI workflows by invoking the actual binary.
Structure#
tests/cli/
├── README.md (this file)
├── check_command/ # mlf check tests
│ ├── valid_file/
│ │ ├── input.mlf
│ │ └── expected.json
│ └── invalid_syntax/
│ ├── input.mlf
│ └── expected.json
├── generate_command/ # mlf generate tests
│ ├── lexicon_output/
│ └── typescript_output/
└── validate_command/ # mlf validate tests
└── basic_validation/
Writing CLI Tests#
Each test case is a directory with:
input.mlf- The MLF source file to testexpected.json- Expected output (status, stdout, stderr)args.txt- CLI arguments (optional, one per line)
Example Test Case#
tests/cli/check_command/valid_file/
├── input.mlf
├── expected.json
└── args.txt
input.mlf:
record post {
text!: string,
createdAt!: datetime,
}
expected.json:
{
"status": "success",
"exit_code": 0,
"stdout": "",
"stderr": ""
}
args.txt:
check
{input}
Running Tests#
# All CLI tests (via just)
just test-cli
# Or via cargo
cargo test -p mlf-integration-tests --test cli_integration -- --nocapture
# Build CLI first if needed
cargo build --release
Test Categories#
check_command#
- ⏳ Valid MLF files pass
- ⏳ Invalid MLF files fail with error
- ⏳ Missing files return proper error
- ⏳ Multiple files are checked
generate_command#
- ⏳ Generate lexicon JSON
- ⏳ Generate TypeScript code
- ⏳ Generate Rust code
- ⏳ Generate Go code
- ⏳ Output to specific directory
validate_command#
- ⏳ Validate JSON against MLF schema
- ⏳ Detect validation errors
- ⏳ Batch validation
fetch_command#
- ⏳ Fetch lexicon from network
- ⏳ Cache downloaded lexicons
- ⏳ Update existing lexicons
init_command#
- ⏳ Initialize new project
- ⏳ Create .mlf directory structure
- ⏳ Don't overwrite existing files
Test Runner Implementation#
The test runner (tests/cli_integration.rs) will:
- Discover test directories automatically
- Build the CLI binary if needed
- Execute commands via
std::process::Command - Compare output against expected results
- Report pass/fail with clear error messages
This follows the same pattern as our codegen tests, providing:
- Automatic discovery - No manual test registration
- File-based tests - Easy to add new test cases
- Clear output - ✓/✗ indicators for each test
- Version control friendly - All test data in files
- No shell scripting - Pure Rust test infrastructure