Expand description
Unit-test support for plugins: run a Plugin against an in-memory
mock host.
use eov_plugin_api::prelude::*;
use eov_plugin_api::testing::TestHarness;
struct Counter {
host: Host,
}
impl Plugin for Counter {
fn create(host: Host, _init: PluginInit) -> Result<Self, String> {
Ok(Self { host })
}
fn on_event(&self, event: HostEvent) -> Result<(), String> {
if let HostEvent::FileOpened { file } = event {
self.host.info(format!("opened {}", file.filename));
}
Ok(())
}
}
let harness = TestHarness::<Counter>::new().unwrap();
harness
.send(HostEvent::FileOpened {
file: FileInfo {
file_id: 1,
filename: "a.svs".into(),
..Default::default()
},
})
.unwrap();
assert_eq!(harness.calls_to("log").len(), 1);The mock answers every method the real host knows with a plausible result, keeps layers, surfaces, settings and contributions in memory so tests can inspect them, and records every call.
Structs§
- Mock
Host - The mock host object handed to the plugin.
- Mock
Layer - A layer as the mock host stores it.
- Mock
State - Everything the mock host knows. Tests may read and modify it freely.
- Mock
Surface - A surface as the mock host stores it.
- Recorded
Call - One recorded host call.
- Test
Harness - Drives a plugin through the same FFI adapter the host uses.
- Test
Slide - A slide opened with
TestHarness::open_slide.
Functions§
- test_
init - Default init for tests: unique, writable temporary directories.