enigma icon indicating copy to clipboard operation
enigma copied to clipboard

Testing macro for BIF

Open RyanSiu1995 opened this issue 5 years ago • 1 comments

I think we can trim the testing code with a macro for calling the bif function. During my development, the following codes were repeatedly entered.

let vm = vm::Machine::new();
let module: *const module::Module = std::ptr::null();
let process = process::allocate(&vm.state, module).wrap();
let args = vec![xxxxxxx];
let res = bif_the_function_I_want_to_test(&vm, &process, &args);

Most of the codes are not used for testing. The code duplication is so high that I think it can be replaced by a macro as a high order function like the following one.

macro_rules! test_it(func: func ; $($arg: expr), *) => {
  // The code as the above
}

I can do this in Elixir but not sure if it is valid in Rust. Does it sound a valid solution to you? @archseer If it is okay, I will do it and refactor the unit tests.

RyanSiu1995 avatar Jan 27 '19 11:01 RyanSiu1995

Take a look at: https://medium.com/@ericdreichert/test-setup-and-teardown-in-rust-without-a-framework-ba32d97aa5ab

On Sun, 27 Jan 2019 at 20:36, Ryan, Siu Long Wa [email protected] wrote:

I think we can trim the testing code with a macro for calling the bif function. During my development, the following codes were repeatedly entered.

let vm = vm::Machine::new();let module: *const module::Module = std::ptr::null();let process = process::allocate(&vm.state, module).wrap();let args = vec![xxxxxxx];let res = bif_the_function_I_want_to_test(&vm, &process, &args);

Most of the codes are not used for testing. The code duplication is so high that I think it can be replaced by a macro as a high order function like the following one.

macro_rules! test_it(func: func ; $($arg: expr), *) => { // The code as the above }

I can do this in Elixir but not sure if it is valid in Rust. Does it sound a valid solution to you? @archseer https://github.com/archseer If it is okay, I will do it and refactor the unit tests.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/archseer/enigma/issues/27, or mute the thread https://github.com/notifications/unsubscribe-auth/ABTy9o48jJhoO70cD_a1FjRjrEyB8pAbks5vHY9JgaJpZM4aUq9F .

archseer avatar Jan 27 '19 11:01 archseer