Skip to main content

Module testing

Module testing 

Source
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§

MockHost
The mock host object handed to the plugin.
MockLayer
A layer as the mock host stores it.
MockState
Everything the mock host knows. Tests may read and modify it freely.
MockSurface
A surface as the mock host stores it.
RecordedCall
One recorded host call.
TestHarness
Drives a plugin through the same FFI adapter the host uses.
TestSlide
A slide opened with TestHarness::open_slide.

Functions§

test_init
Default init for tests: unique, writable temporary directories.