crates/nornir-saga/tests/noop_when_off.rs
//! **No-op-on-release guarantee** — with the `saga` feature OFF (the default,
//! i.e. a normal release build), the global capture tap must be an inert no-op:
//! `tap` captures nothing and `drain_saga` always yields an empty saga. The
//! process-global capture buffer (`ui::capture::cap`) is `#[cfg(feature =
//! "saga")]`, so it is *not compiled* into this build at all — this test simply
//! confirms the public surface still links and behaves as a no-op.
//!
//! The whole file is gated to the feature-off build; under `--features saga`
//! there is nothing here (the capture path is tested inline in `capture.rs`).
#![cfg(not(feature = "saga"))]
use nornir_saga::ui::{drain_saga, tap, SagaMsg, UiMsg};
#[derive(Clone)]
enum AppMsg {
Nav(&'static str),
Tick,
}
impl SagaMsg for AppMsg {
fn to_ui_msg(&self) -> Option<UiMsg> {
match self {
AppMsg::Nav(r) => Some(UiMsg::nav(r)),
AppMsg::Tick => None,
}
}
}
#[test]
fn tap_is_a_noop_and_drain_is_always_empty() {
// Tapping many movements must capture nothing when `saga` is off.
for _ in 0..1000 {
tap(&AppMsg::Nav("/home"));
tap(&AppMsg::Tick);
// capturing a raw UiMsg directly is a no-op too.
nornir_saga::ui::capture(UiMsg::click(1.0, 2.0, "#x"));
}
let saga = drain_saga("release build");
assert!(saga.is_empty(), "no `saga` feature ⇒ capture tap is a no-op");
assert_eq!(saga.title, "release build", "drain still returns a titled empty saga");
assert_eq!(saga.version, nornir_saga::ui::Saga::VERSION);
}