This Rust program is used to perform simple integration tests on programs through a JSON configuration file.
Usage: tiny-integration-tester [options]
| Arg | Long name | Description | |-----|-----------------|----------------------------------------------| | -f | --file NAME | set json tests file name | | -t | --timeout VALUE | set the default timeout in ms for all tests | | -h | --help | print this help menu | | -v | --version | print the program version |
After creating a new project with the command cargo new hello
, create a file named test.json like this :
[
{
"command" : "./target/debug/hello",
"stdout" : "Hello, world!\n"
},
{
"command" : "./target/debug/hello",
"stdout" : "Hello, dummy!\n"
}
]
Then simply run cargo build then tiny-integration-tester
:
Executing command: "./target/debug/hello" with args: []
OK!
Executing command: "./target/debug/hello" with args: []
FAIL!
YOU GOT: Output {
status: ExitStatus(
unix_wait_status(
0,
),
),
stdout: "Hello, world!\n",
stderr: "",
}
BUT DESIRED OUTPUT IS: Output {
status: ExitStatus(
unix_wait_status(
0,
),
),
stdout: "Hello, dummy!\n",
stderr: "",
}
result: 1 / 2
You can set these values into the json test file :
| Field | Definition | Type | Comment | |-----------|-------------------------|---------------------------|-----------------------| | command | command to run | String | Mandatory | | stdout | FD stdout | String | | | stderr | FD stderr | String | | | stdin | FD stdin | String | | | args | command arguments | Array of String | | | envs | command envs args | Array of (String, String) | json tuple is [1, 2] | | env_clear | clear environment | Boolean | clear all env if true | | status | process exit status | Hexadecimal String | 0xHHLL depends of OS | | timeout | kill process after X ms | Unsigned Integer | unit ms |
text
[
{
"command" : "./fibonacci",
"args" : ["3"],
"stdout" : "fibo(3) = 2\n",
"timeout" : 1000
},
{
"command" : "./fibonacci",
"args" : ["1", ""],
"status" : -1,
"stderr" : "Usage: ./fibonacci POSITIF_NUMBER\n"
},
{
"command" : "./fibonacci",
"args" : ["7"],
"stdout" : "fibo(7) = 13\n"
},
{
"timeout" : 500,
"command" : "./fibonacci",
"args" : ["15"],
"status" : 0,
"stdout" : "fibo(15) = 610\n"
},
{
"command" : "./fibonacci",
"args" : ["164neuf"],
"status" : -1,
"stderr" : "Bad number format\n"
},
{
"command" : "./fibonacci",
"status" : -1,
"stderr" : "Bad number format\n"
},
"command" : "./readline-tester",
"status" : "0x0",
"stdin" : "carrots are cooked\nbananas\n",
"stdout" : "1 carrots are cooked\n2 bananas\n"
},
{
"command" : "./env-tester",
"stdout" : "1 = foo\n2 = bar\n",
"env_clear" : true,
"envs": [["1", "foo"], ["2", "bar"], ["CLUTTER_IM_MODULE", "dummy"]]
}
]
Be careful with trailing commas at the end in a JSON file.