macro_rules! assert_always {
($condition:expr, $message:expr$(, $details:expr)?) => { ... };
($($rest:tt)*) => { ... };
}Expand description
Assert that condition is true every time this function is called, and that it is
called at least once. The corresponding test property will be viewable in the Antithesis SDK: Always group of your triage report.
ยงExample
use serde::Serialize;
use antithesis_sdk::{assert_always, random};
// Details can be any Serialize type, and are only serialized when the
// assertion actually emits โ on a sparse sample of passing and failing
// evaluations. A plain struct of values and references like this
// therefore costs nothing on the hot path.
#[derive(Serialize)]
struct Details<'a> {
max_allowed: u64,
actual: u64,
source: &'a str,
}
const MAX_ALLOWED: u64 = 100;
let actual = random::get_random() % 100u64;
let details = Details { max_allowed: MAX_ALLOWED, actual, source: "demo" };
antithesis_sdk::assert_always!(actual < MAX_ALLOWED, "Value in range", &details);Ensure that non-const-evaluable messages are rejected.
use serde_json::json;
const MESSAGE: &str = concat!("Value", " in range");
antithesis_sdk::assert_always!(true, MESSAGE, &json!({}));A message computed at runtime is rejected at compile time:
โ
use serde_json::json;
let message = String::from("Value in range");
antithesis_sdk::assert_always!(true, message, &json!({}));โ
use serde_json::json;
antithesis_sdk::assert_always!(true, format!("{}", "Value in range"), &json!({}));