test_file command is now documented and public

This commit is contained in:
sagie gur ari 2020-07-31 08:26:57 +00:00
parent 4bc3045a7c
commit 2879050cab
4 changed files with 41 additions and 2 deletions

View file

@ -4,6 +4,8 @@
* New json_encode command #124
* New json_parse command #124
* Module level documentation #125
* test_file command is now documented and public.
### v0.6.3 (2020-07-24)

View file

@ -77,7 +77,7 @@ impl Command for CommandImpl {
let test_script = format!(
r#"
result = std::test::TestFile {} {}
result = test_file {} {}
assert result
"#,
&file, &test_name

View file

@ -0,0 +1,33 @@
```sh
test_file file [test name]
```
This command can be used to run unit tests written in duckscript.<br>
It will run all test functions that start with **test_** in the given file.<br>
Each such function is considered as a test and can run any type of code and check itself using assert commands.
#### Parameters
* The file name containing the test functions.
* Optional pattern for the test function to limit invocation of only those tests.
#### Return Value
**true** if successful.
#### Examples
This is an example of a test function:
```sh
function test_set_get_unset
unset_env TEST_SET_GET_UNSET
value = get_env TEST_SET_GET_UNSET
assert_false ${value}
value = set_env TEST_SET_GET_UNSET "test value"
assert ${value}
value = get_env TEST_SET_GET_UNSET
assert_eq ${value} "test value"
end
```

View file

@ -30,8 +30,12 @@ impl Command for CommandImpl {
pckg::concat(&self.package, "TestFile")
}
fn aliases(&self) -> Vec<String> {
vec!["test_file".to_string()]
}
fn help(&self) -> String {
"".to_string()
include_str!("help.md").to_string()
}
fn clone_and_box(&self) -> Box<dyn Command> {