https://github.com/sambacha/climaxxing
autogenerate tests via shell completion
https://github.com/sambacha/climaxxing
autogenerate bash bash-bats bats posix shell-testing
Last synced: about 2 months ago
JSON representation
autogenerate tests via shell completion
- Host: GitHub
- URL: https://github.com/sambacha/climaxxing
- Owner: sambacha
- Created: 2024-08-11T15:08:51.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-11T15:29:21.000Z (almost 2 years ago)
- Last Synced: 2025-10-11T01:57:08.631Z (8 months ago)
- Topics: autogenerate, bash, bash-bats, bats, posix, shell-testing
- Language: Shell
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CLIMaxxing
> Ensure that your CLI tool's bash completion script is working correctly for all commands and options, including edge cases like partial inputs and invalid commands.
## Overview
CLIMaxxing follows these steps to generate and run tests:
1. **Parsing**: The tool reads the bash completion script and parses it to extract all commands, subcommands, and their respective options.
2. **Test Generation**: Using the parsed information, CLIMaxxing generates a series of BATS tests. These include:
- Full completion tests for each command and subcommand
- Incremental completion tests, checking partial option lists
- Tests for invalid inputs
- Tests for partial command inputs
3. **Mock Creation**: The tool generates a mock version of the CLI tool being tested. This mock intercepts completion requests and returns predefined outputs, allowing for controlled testing.
4. **BATS Test Suite**: All generated tests are written into a BATS test file. This file includes setup and teardown functions to manage the testing environment.
5. **Test Execution**: The generated BATS tests can then be run using the BATS framework, providing a detailed report of passing and failing completions.
## Example
Let's say we're testing the completions for a CLI tool called `cast`. Here's how you might use CLIMaxxing:
1. Run the CLIMaxxing generator:
```
cargo run -- cast.d
```
2. This generates two files:
- `test_cast_completion.bats`: The BATS test file
- `cast_mock`: The mock cast script
3. The generated `test_cast_completion.bats` might include tests like:
```bash
@test "Test completion for 'cast call'" {
mock_set_output "$CAST_MOCK" "--rpc-url --from --interactive --private-key"
run cast call --generate-bash-completion
assert_success
assert_output --partial "--rpc-url --from --interactive --private-key"
}
@test "Test incremental completion for 'cast call' (2 options)" {
mock_set_output "$CAST_MOCK" "--rpc-url --from"
run cast call --generate-bash-completion
assert_success
assert_output --partial "--rpc-url --from"
}
```
4. Run the BATS tests:
```
bats test_cast_completion.bats
```
5. BATS will execute all the tests and provide a report, for example:
```
✓ Test completion for 'cast call'
✓ Test incremental completion for 'cast call' (2 options)
✓ Test completion for invalid input
✓ Test completion for partial input 'cast to-'
```