From cac6b4ae012a9222086559d6b27f2848c4e0d3dc Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 3 Mar 2020 17:04:26 +0100 Subject: [PATCH] test(interface-types) Add test cases for errors. --- .../instructions/lowering_lifting.rs | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/interpreter/instructions/lowering_lifting.rs b/src/interpreter/instructions/lowering_lifting.rs index cd43104..1ba8a38 100644 --- a/src/interpreter/instructions/lowering_lifting.rs +++ b/src/interpreter/instructions/lowering_lifting.rs @@ -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],