mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
Invoking a command that does not exist should crash and not error
This commit is contained in:
parent
9c1800417f
commit
99b18562ca
|
@ -3,8 +3,10 @@
|
||||||
### v0.1.7
|
### v0.1.7
|
||||||
|
|
||||||
* Fixed runner to return an error if on_error requested crash or exit and not just end the script.
|
* Fixed runner to return an error if on_error requested crash or exit and not just end the script.
|
||||||
* Unalias can remove aliases not created from the alias command.
|
* \[Breaking Change\] Unalias can remove aliases not created from the alias command.
|
||||||
* New properties read/write commands #61
|
* New properties read/write commands #61
|
||||||
|
* Default command run implementation should crash and not error #63
|
||||||
|
* \[Breaking Change\] Invoking a command that does not exist should crash and not error
|
||||||
|
|
||||||
### v0.1.6 (2020-01-12)
|
### v0.1.6 (2020-01-12)
|
||||||
|
|
||||||
|
|
|
@ -259,7 +259,7 @@ pub fn run_instruction(
|
||||||
|
|
||||||
command_result
|
command_result
|
||||||
}
|
}
|
||||||
None => CommandResult::Error(format!("Command: {} not found.", &command)),
|
None => CommandResult::Crash(format!("Command: {} not found.", &command)),
|
||||||
},
|
},
|
||||||
None => CommandResult::Continue(None),
|
None => CommandResult::Continue(None),
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ fn run_instructions_unknown_command() {
|
||||||
|
|
||||||
let context_result = run_instructions(runtime, 0);
|
let context_result = run_instructions(runtime, 0);
|
||||||
|
|
||||||
assert!(context_result.is_ok());
|
assert!(context_result.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -175,24 +175,26 @@ fn run_instructions_start_bigger_then_script() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_instructions_start_after_exit() {
|
fn run_instructions_start_after_bad_command() {
|
||||||
let mut instructions = vec![];
|
let mut instructions = vec![];
|
||||||
|
|
||||||
let mut script_instruction = ScriptInstruction::new();
|
let mut script_instruction = ScriptInstruction::new();
|
||||||
script_instruction.command = Some("exit".to_string());
|
script_instruction.command = Some("bad".to_string());
|
||||||
instructions.push(Instruction {
|
instructions.push(Instruction {
|
||||||
meta_info: InstructionMetaInfo::new(),
|
meta_info: InstructionMetaInfo::new(),
|
||||||
instruction_type: InstructionType::Script(script_instruction),
|
instruction_type: InstructionType::Script(script_instruction),
|
||||||
});
|
});
|
||||||
script_instruction = ScriptInstruction::new();
|
script_instruction = ScriptInstruction::new();
|
||||||
script_instruction.command = Some("bad".to_string());
|
script_instruction.command = Some("set".to_string());
|
||||||
instructions.push(Instruction {
|
instructions.push(Instruction {
|
||||||
meta_info: InstructionMetaInfo::new(),
|
meta_info: InstructionMetaInfo::new(),
|
||||||
instruction_type: InstructionType::Script(script_instruction),
|
instruction_type: InstructionType::Script(script_instruction),
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
let result = context.commands.set(Box::new(ExitCommand {}));
|
let mut result = context.commands.set(Box::new(ExitCommand {}));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
result = context.commands.set(Box::new(SetCommand {}));
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
let runtime = create_runtime(instructions, context);
|
let runtime = create_runtime(instructions, context);
|
||||||
|
@ -724,7 +726,7 @@ fn run_instruction_script_instruction_unknown_command() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(output_variable.is_none());
|
assert!(output_variable.is_none());
|
||||||
assert!(test::validate_error_result(&command_result));
|
assert!(test::validate_crash_result(&command_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -282,3 +282,10 @@ pub(crate) fn validate_error_result(result: &CommandResult) -> bool {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn validate_crash_result(result: &CommandResult) -> bool {
|
||||||
|
match result {
|
||||||
|
CommandResult::Crash(_) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@ fn common_functions() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_no_args() {
|
fn run_no_args() {
|
||||||
test::run_script_and_error(vec![create("")], "out = assert_fail", "out");
|
test::run_script_and_error(vec![create("")], "out = assert_error", "out");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_with_message() {
|
fn run_with_message() {
|
||||||
test::run_script_and_error(vec![create("")], "out = assert_fail error", "out");
|
test::run_script_and_error(vec![create("")], "out = assert_error error", "out");
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ fn run_valid_alias_defined() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_after_unalias() {
|
fn run_after_unalias() {
|
||||||
test::run_script_and_error(
|
test::run_script_and_crash(
|
||||||
vec![create(""), alias::create(""), Box::new(SetCommand {})],
|
vec![create(""), alias::create(""), Box::new(SetCommand {})],
|
||||||
r#"
|
r#"
|
||||||
alias set test_set
|
alias set test_set
|
||||||
|
@ -47,6 +47,5 @@ fn run_after_unalias() {
|
||||||
out = unalias set
|
out = unalias set
|
||||||
out = set test
|
out = set test
|
||||||
"#,
|
"#,
|
||||||
"out",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,10 @@ pub(crate) fn eval_with_error(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
) -> CommandResult {
|
) -> CommandResult {
|
||||||
match eval(arguments, state, variables, commands) {
|
match eval(arguments, state, variables, commands) {
|
||||||
Ok(command_result) => command_result,
|
Ok(command_result) => match command_result.clone() {
|
||||||
|
CommandResult::Crash(error) => CommandResult::Error(error),
|
||||||
|
_ => command_result,
|
||||||
|
},
|
||||||
Err(error) => CommandResult::Error(error.to_string()),
|
Err(error) => CommandResult::Error(error.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue