Skip to main content

mock_function

Function mock_function 

Source
pub fn mock_function<F: 'static + Send>(name: &str, mock_fn: F)
Expand description

Mock a function with a closure

§Safety

This is a safe version that requires explicit checking in the function being mocked. For true runtime function replacement, unsafe code would be needed.

§Example

use windjammer_runtime::mock_function::{mock_function, is_mocked, clear_mock};

// Simple example showing mock registration
mock_function("get_time", || 12345i64);

// Verify mock is registered
assert!(is_mocked("get_time"));

// Clear the mock
clear_mock("get_time");
assert!(!is_mocked("get_time"));