use mumu::{
parser::interpreter::Interpreter,
parser::types::{FunctionValue, Value},
};
use std::sync::{Arc, Mutex};
use crate::describe_it::{describe_bridge_fn, it_bridge_fn};
use crate::asserts::{expect_equal_bridge_fn, expect_not_equal_bridge_fn, has_key_bridge_fn, prop_equals_bridge_fn};
use crate::expect_error::expect_error_bridge_fn;
use crate::file_asserts::register_file_asserts;
use crate::lorem_file::register_lorem_file;
use crate::unique_filename::register_unique_filename;
use crate::runner::run_all::runner_all_bridge;
#[export_name = "Cargo_lock"]
pub unsafe extern "C" fn cargo_lock(
interp_ptr: *mut std::ffi::c_void,
extra_str: *const std::ffi::c_void,
) -> i32 {
if interp_ptr.is_null() {
return 1;
}
let interp = &mut *(interp_ptr as *mut Interpreter);
if interp.is_verbose() {
eprintln!("[test:Cargo.lock] => dynamic plugin init => bridging...");
if !extra_str.is_null() {
use std::ffi::CStr;
let c_str = CStr::from_ptr(extra_str as *const i8);
eprintln!("[test:Cargo.lock] => extra arg='{}'", c_str.to_string_lossy());
}
}
let dfn = Arc::new(Mutex::new(describe_bridge_fn));
interp.register_dynamic_function("describe", dfn);
interp.set_variable(
"describe",
Value::Function(Box::new(FunctionValue::Named("describe".into())))
);
let ifn = Arc::new(Mutex::new(it_bridge_fn));
interp.register_dynamic_function("it", ifn);
interp.set_variable(
"it",
Value::Function(Box::new(FunctionValue::Named("it".into())))
);
let efn = Arc::new(Mutex::new(expect_equal_bridge_fn));
interp.register_dynamic_function("expect_equal", efn);
interp.set_variable(
"expect_equal",
Value::Function(Box::new(FunctionValue::Named("expect_equal".into())))
);
let nefn = Arc::new(Mutex::new(expect_not_equal_bridge_fn));
interp.register_dynamic_function("expect_not_equal", nefn);
interp.set_variable(
"expect_not_equal",
Value::Function(Box::new(FunctionValue::Named("expect_not_equal".into())))
);
let has_key_fn = Arc::new(Mutex::new(has_key_bridge_fn));
interp.register_dynamic_function("has_key", has_key_fn);
interp.set_variable(
"has_key",
Value::Function(Box::new(FunctionValue::Named("has_key".into())))
);
let prop_eq_fn = Arc::new(Mutex::new(prop_equals_bridge_fn));
interp.register_dynamic_function("prop_equals", prop_eq_fn);
interp.set_variable(
"prop_equals",
Value::Function(Box::new(FunctionValue::Named("prop_equals".into())))
);
let ee_fn = Arc::new(Mutex::new(expect_error_bridge_fn));
interp.register_dynamic_function("test:expect_error", ee_fn);
interp.set_variable(
"test:expect_error",
Value::Function(Box::new(FunctionValue::Named("test:expect_error".into())))
);
let afn = Arc::new(Mutex::new(runner_all_bridge));
interp.register_dynamic_function("test:all", afn.clone());
interp.set_variable(
"test:all",
Value::Function(Box::new(FunctionValue::Named("test:all".into())))
);
register_file_asserts(interp);
register_lorem_file(interp);
register_unique_filename(interp);
if interp.is_verbose() {
eprintln!("[test:Cargo.lock] => dynamic plugin init => success");
}
0
}