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 thedriver!macro for ergonomic builder construction (it wiresmanifest_dirfrom the calling crate’sCARGO_MANIFEST_DIR, sostate_filepaths resolve correctly). Assertions live inassertions. - Static plugin checks -
assert_state_round_trip,assert_has_editor, AUFourCC, 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
PluginDriverfor the given plugin type, withmanifest_dirwired to the calling crate’sCARGO_MANIFEST_DIR. That lets.state_file("test_states/foo.pluginstate")resolve against the crate’s own directory regardless of wherecargo testwas launched. - screenshot
- Construct a
ScreenshotTestfor the given plugin type, with the reference-PNG path required as the second argument. The path is anchored to the calling crate’sCARGO_MANIFEST_DIRwhen relative, or used as-is when absolute.
Structs§
- Capture
Spec - Driver
Result - Captured audio + metadata + plugin instance from a
PluginDriverrun. - Plugin
Driver - Screenshot
Test - 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. - Setup
Context - Context passed to the
PluginDriver::setupclosure. 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 Pdoesn’t know). - Transport
Spec - Transport state visible to the plugin’s
ProcessContext.
Enums§
- Input
Source - What audio gets fed into the plugin’s input bus each block.
- Meter
Capture - Meter
Readings
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
FourCharCoderound-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_infoslength. - 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_normalized→get_normalizedround-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_paramsfor plugin authors who want to drive snapshot tests directly without theassert_screenshot!macro. Build aPluginContextbacked only byparams. All write closures are no-ops; reads delegate to the paramsArc; the transport reports the deterministiccrate::events::TransportInfo::for_screenshotstate 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.