Skip to main content

Crate truce_test

Crate truce_test 

Source
Expand description

Test utilities for truce plugins.

Two layers:

  • Audio runs - built on top of truce_driver::PluginDriver. Re-exported here so plugin tests have one crate to depend on. Use the driver! macro for ergonomic builder construction (it wires manifest_dir from the calling crate’s CARGO_MANIFEST_DIR, so state_file paths resolve correctly). Assertions live in assertions.
  • Static plugin checks - assert_state_round_trip, assert_has_editor, AU FourCC, bus config, param defaults, GUI lifecycle, etc. These don’t render audio, just instantiate the plugin and inspect.

§Usage

Add to your plugin crate’s [dev-dependencies]:

[dev-dependencies]
truce-test = { workspace = true }
use truce_test::{assertions, driver, InputSource};
use std::time::Duration;

#[test]
fn passthrough() {
    let result = driver!(MyPlugin)
        .duration(Duration::from_millis(100))
        .input(InputSource::Constant(0.5))
        .run();
    assertions::assert_nonzero(&result);
    assertions::assert_no_nans(&result);
    assertions::assert_peak_below(&result, 1.0);
}

Modules§

assertions
Assertion helpers built on top of crate::DriverResult.

Macros§

driver
Construct a PluginDriver for the given plugin type, with manifest_dir wired to the calling crate’s CARGO_MANIFEST_DIR. That lets .state_file("test_states/foo.pluginstate") resolve against the crate’s own directory regardless of where cargo test was launched.
screenshot
Construct a ScreenshotTest for the given plugin type, with the reference-PNG path required as the second argument. The path is anchored to the calling crate’s CARGO_MANIFEST_DIR when relative, or used as-is when absolute.

Structs§

CaptureSpec
DriverResult
Captured audio + metadata + plugin instance from a PluginDriver run.
PluginDriver
ScreenshotTest
Builder for a screenshot regression test.
Script
Sample-accurate sequence of events fed to the plugin during a run. Cursor advances via wait_ms / wait_samples; events land at the current cursor position.
SetupContext
Context passed to the PluginDriver::setup closure. Carries the driver state that’s been resolved by the time setup runs - in particular the auto-detected channel count, which would otherwise be invisible to the closure (the user’s &mut P doesn’t know).
TransportSpec
Transport state visible to the plugin’s ProcessContext.

Enums§

InputSource
What audio gets fed into the plugin’s input bus each block.
MeterCapture
MeterReadings

Functions§

assert_au_type_codes_ascii
Assert AU type codes are valid 4-char ASCII.
assert_bus_config_effect
Assert bus config is correct for an effect (has inputs and outputs).
assert_bus_config_instrument
Assert bus config is correct for an instrument (no inputs, has outputs).
assert_corrupt_state_no_crash
Assert corrupt state data doesn’t crash.
assert_editor_lifecycle
Assert editor can be created multiple times without issues.
assert_editor_size_consistent
Assert editor size is consistent across multiple calls.
assert_empty_state_no_crash
Assert empty state data doesn’t crash.
assert_fourcc_roundtrip
Assert AU FourCharCode round-trips through big-endian u32.
assert_has_editor
Assert the plugin has a working editor with valid dimensions.
assert_no_duplicate_param_ids
Assert all parameter IDs are unique.
assert_param_count_matches
Assert param count matches param_infos length.
assert_param_defaults_match
Assert all parameter default values match their declared defaults.
assert_param_normalized_clamped
Assert normalized param values are clamped to [0, 1].
assert_param_normalized_roundtrip
Assert set_normalizedget_normalized round-trips for all params.
assert_state_round_trip
Assert state save/load round-trips correctly.
assert_valid_info
Assert plugin_info!() returns valid metadata.
for_test_params
Re-export of truce_core::editor::for_test_params for plugin authors who want to drive snapshot tests directly without the assert_screenshot! macro. Build a PluginContext backed only by params. All write closures are no-ops; reads delegate to the params Arc; the transport reports the deterministic crate::events::TransportInfo::for_screenshot state so screenshot tests stay reproducible across CI runs.
save_png
Write RGBA bytes to a PNG with 144 DPI metadata so the file renders at half pixel size in viewers and on GitHub.