Skip to main content

assert_unreachable

Macro assert_unreachable 

Source
macro_rules! assert_unreachable {
    ($message:expr$(, $details:expr)?) => { ... };
    ($($rest:tt)*) => { ... };
}
Expand description

Assert that a line of code is never reached. The corresponding test property will fail if this macro is ever called. (If it is never called the test property will therefore pass.) This test property will be viewable in the Antithesis SDK: Reachablity assertions group.

ยงExample

use serde::Serialize;
use antithesis_sdk::{assert_unreachable, random};

// Only serialized when the assertion emits; see assert_always.
#[derive(Serialize)]
struct Details { max_allowed: u64, actual: u64 }

const MAX_ALLOWED: u64 = 100;
let actual = random::get_random() % 120u64;
let details = Details { max_allowed: MAX_ALLOWED, actual };
if (actual > 120u64) {
    antithesis_sdk::assert_unreachable!("Value is above range", &details);
}