Skip to main content

Module assertions

Module assertions 

Source
Expand description

Assertion helpers built on top of crate::DriverResult.

Run a crate::PluginDriver (typically via the crate::driver! macro), then pass the captured result into these helpers for standard claims:

  • Whole-run audio shape: nonzero / silence / no-NaNs / peak below threshold.
  • Time-windowed audio shape: silence-after, nonzero-after, silence-between, nonzero-between (for tail-decay / gate-between-notes assertions).
  • Meter readings at end-of-run.
  • Output events emitted by the plugin.
use std::time::Duration;
use truce_test::{assertions, driver, InputSource};

#[test]
fn long_tail_goes_silent() {
    let result = driver!(MyReverb)
        .duration(Duration::from_secs(3))
        .input(InputSource::Constant(0.5))
        .run();
    assertions::assert_nonzero(&result);
    assertions::assert_silence_after(&result, Duration::from_millis(2_500));
}

Functions§

assert_meter_above
Assert the meter identified by id read above threshold at the end of the run.
assert_meter_below
Assert the meter identified by id read below threshold at the end of the run.
assert_no_nans
Assert no sample is NaN or infinite. If this fails, the DSP went divergent.
assert_nonzero
Assert that at least one sample anywhere in the output is above the audible threshold.
assert_nonzero_after
Assert at least one sample after t is above the audible threshold.
assert_nonzero_between
Assert non-zero audio somewhere in [start, end).
assert_output_event_count
Assert exactly n output events were emitted by the plugin across the run. Requires .capture_output_events(true) on the driver.
assert_peak_below
Assert no sample exceeds threshold in absolute value. Typical use: assert_peak_below(&result, 1.0) to catch clipping.
assert_silence
Assert every sample in the output is below the audible threshold.
assert_silence_after
Assert every sample after t is below the audible threshold. Use for reverb / delay tail decay tests.
assert_silence_between
Assert silence across [start, end). More precise than assert_silence_after when both endpoints matter.