Cargo Regression
Collect test task from input files, execute them and compare results with golden.
Usage
cargo install cargo-regression
Build your test files like ./demo, then
cargo regression ./demo --debug
The tests will be exectued in ./tmp in default, change the dir by --work-dir path.
Set Extension(s)
cargo-regression will collect all files that match extensions as test tasks, you can set extensions in two ways:
- By commmand arguments
cargo regression ./demo --extensions py sh
- By
__all__.toml
# override for all sub-dir
= ["py", "sh"]
And the arguments --extensions is equivalent to set it in the most top __all__.toml.
Other Configurations
There are many other configs that hold the same behavior as extensions:
| Argument | __all__.toml |
Description |
|---|---|---|
--exe-path bash |
exe-path = "bash" |
The executable path to execute task |
--args {{name}}.sh arg1 |
args = ["{{name}}.sh", "arg1"] |
The arguements for execute task |
--permits 2 |
permits = 2 |
The total permits to limit max parallelism |
| NA | ignore = true |
Ignore that task |
Variable Table
| Variable | Description |
|---|---|
{{root-dir}} |
The absolute path of test root. |
{{name}} |
The name of task file. |
{{extension}} |
The extension of task file. |
Advanced Features
Test Filter
Only test specified tasks.
cargo regression ./demo
cargo regression ./demo --filter demo/trybuild/*
Schedule Parallelism
permits and permit are virtual resource costs, you can define permits in arguments (default=1), and define permit in task toml config file (default=0).
cargo regression ./demo --filter demo/test-premit/* --permits 1
cargo regression ./demo --filter demo/test-premit/* --permits 2
assertion
exit-code
Assert the exit code, default is 0.
[]
= 1
equal
The output file should equal to the golden
[]
= true
match
Match pattern and assert the number (count) of it.
[[]]
= "{{name}}.stdout"
= [
# regular expression match
{ = 'f.*o', = 4 },
# should contain word "fo" at least once
{ = '\bfo\b', = 1 },
# should contain word "fo" at most once
{ = '\bfo0\b', = 1 },
]
Use it as API
see ./examples
use ;
async
TODO
- regolden
- assert value
- full config
- document