mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-04 15:09:08 +00:00
new assert_fail command #3
This commit is contained in:
parent
a2b8fb6672
commit
4f24f9a601
|
@ -2,6 +2,7 @@
|
|||
|
||||
### v0.1.2
|
||||
|
||||
* New **assert_fail** command #3
|
||||
* New **assert** command #2
|
||||
* New **touch** command #4
|
||||
* New **dirname** command #6
|
||||
|
|
32
docs/sdk.md
32
docs/sdk.md
|
@ -26,6 +26,7 @@
|
|||
* [sdk::process::Execute](#sdk__process__Execute)
|
||||
* [sdk::process::Exit](#sdk__process__Exit)
|
||||
* [sdk::test::Assert](#sdk__test__Assert)
|
||||
* [sdk::test::AssertFail](#sdk__test__AssertFail)
|
||||
* [sdk::thread::Sleep](#sdk__thread__Sleep)
|
||||
|
||||
|
||||
|
@ -1070,7 +1071,7 @@ It is considered falsy and will exist with an error.
|
|||
|
||||
#### Return Value
|
||||
|
||||
**true** is truthy.
|
||||
**true** if truthy.
|
||||
|
||||
#### Examples
|
||||
|
||||
|
@ -1098,6 +1099,35 @@ assert false "This is my error message"
|
|||
#### Aliases:
|
||||
assert
|
||||
|
||||
<a name="sdk__test__AssertFail"></a>
|
||||
## sdk::test::AssertFail
|
||||
```sh
|
||||
assert_fail [error message]
|
||||
```
|
||||
|
||||
This command will exist with an error.<br>
|
||||
If error message is provided, it will be used as part of the error output.
|
||||
|
||||
#### Parameters
|
||||
|
||||
Optional error message.
|
||||
|
||||
#### Return Value
|
||||
|
||||
None
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
assert_fail
|
||||
|
||||
assert_fail "This is my error message"
|
||||
```
|
||||
|
||||
|
||||
#### Aliases:
|
||||
assert_fail
|
||||
|
||||
<a name="sdk__thread__Sleep"></a>
|
||||
## sdk::thread::Sleep
|
||||
```sh
|
||||
|
|
|
@ -20,7 +20,7 @@ It is considered falsy and will exist with an error.
|
|||
|
||||
#### Return Value
|
||||
|
||||
**true** is truthy.
|
||||
**true** if truthy.
|
||||
|
||||
#### Examples
|
||||
|
||||
|
|
22
duckscript_sdk/src/sdk/std/test/assert_fail/help.md
Normal file
22
duckscript_sdk/src/sdk/std/test/assert_fail/help.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
```sh
|
||||
assert_fail [error message]
|
||||
```
|
||||
|
||||
This command will exist with an error.<br>
|
||||
If error message is provided, it will be used as part of the error output.
|
||||
|
||||
#### Parameters
|
||||
|
||||
Optional error message.
|
||||
|
||||
#### Return Value
|
||||
|
||||
None
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
assert_fail
|
||||
|
||||
assert_fail "This is my error message"
|
||||
```
|
40
duckscript_sdk/src/sdk/std/test/assert_fail/mod.rs
Executable file
40
duckscript_sdk/src/sdk/std/test/assert_fail/mod.rs
Executable file
|
@ -0,0 +1,40 @@
|
|||
use crate::utils::pckg;
|
||||
use duckscript::types::command::{Command, CommandResult};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "./mod_test.rs"]
|
||||
mod mod_test;
|
||||
|
||||
struct CommandImpl {
|
||||
package: String,
|
||||
}
|
||||
|
||||
impl Command for CommandImpl {
|
||||
fn name(&self) -> String {
|
||||
pckg::concat(&self.package, "AssertFail")
|
||||
}
|
||||
|
||||
fn aliases(&self) -> Vec<String> {
|
||||
vec!["assert_fail".to_string()]
|
||||
}
|
||||
|
||||
fn help(&self) -> String {
|
||||
include_str!("help.md").to_string()
|
||||
}
|
||||
|
||||
fn run(&self, arguments: Vec<String>) -> CommandResult {
|
||||
let error_message = if arguments.is_empty() {
|
||||
"Assert failed.".to_string()
|
||||
} else {
|
||||
arguments[0].clone()
|
||||
};
|
||||
|
||||
CommandResult::Error(error_message)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create(package: &str) -> Box<dyn Command> {
|
||||
Box::new(CommandImpl {
|
||||
package: package.to_string(),
|
||||
})
|
||||
}
|
17
duckscript_sdk/src/sdk/std/test/assert_fail/mod_test.rs
Normal file
17
duckscript_sdk/src/sdk/std/test/assert_fail/mod_test.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use super::*;
|
||||
use crate::test;
|
||||
|
||||
#[test]
|
||||
fn common_functions() {
|
||||
test::test_common_command_functions(create(""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_no_args() {
|
||||
test::run_script_and_fail(vec![create("")], "assert_fail");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_with_message() {
|
||||
test::run_script_and_fail(vec![create("")], "assert_fail error");
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
mod assert;
|
||||
mod assert_fail;
|
||||
|
||||
use crate::utils::pckg;
|
||||
use duckscript::types::command::Commands;
|
||||
|
@ -10,6 +11,7 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
|
|||
let package = pckg::concat(parent, PACKAGE);
|
||||
|
||||
commands.set(assert::create(&package))?;
|
||||
commands.set(assert_fail::create(&package))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue