test(interface-types) Add test cases for errors.

This commit is contained in:
Ivan Enderlin 2020-03-03 17:04:26 +01:00
parent 87a3606836
commit cac6b4ae01

View File

@ -23,11 +23,17 @@ macro_rules! lowering_lifting {
)?))
}
Some(_) => {
return Err(concat!(
"Instruction `",
$instruction_name,
"` expects a `i32` value on the stack."
Some(wrong_value) => {
return Err(format!(
concat!(
"Instruction `",
$instruction_name,
"` expects a `",
stringify!($from_variant),
"` value on the stack, got `{:?}`.",
),
wrong_value
)
.to_string())
},
@ -92,6 +98,22 @@ mod tests {
stack: [InterfaceValue::S8(42)],
);
test_executable_instruction!(
test_type_mismatch =
instructions: [Instruction::ArgumentGet { index: 0}, Instruction::I32ToS8],
invocation_inputs: [InterfaceValue::I64(42)],
instance: Instance::new(),
error: "Instruction `i32-to-s8` expects a `I32` value on the stack, got `I64(42)`."
);
test_executable_instruction!(
test_no_value_on_the_stack =
instructions: [Instruction::I32ToS8],
invocation_inputs: [InterfaceValue::I32(42)],
instance: Instance::new(),
error: "Instruction `i32-to-s8` needs one value on the stack."
);
test_executable_instruction!(
test_i32_to_u8 =
instructions: [Instruction::ArgumentGet { index: 0 }, Instruction::I32ToU8],