Skip to main content

saluki_antithesis/
lib.rs

1//! Thin facade over the Antithesis SDK.
2//!
3//! This crate owns the single `antithesis` feature for the project. It is no-op
4//! unless specifically enabled. Each macro forwards to the SDK macro. These
5//! macros convert a trailing map into JSON for consumption by the underlying
6//! SDK.
7//!
8//! # Use Guidance
9//!
10//! A more precise assertion gives Antithesis better exploration. Prefer the
11//! numeric macros like `always_gt!(x, y, ...)` over `always!(x > y, ...)`.
12
13#![deny(missing_docs)]
14
15/// Hidden SDK handle. The macros forward through this path so call sites never
16/// name `antithesis_sdk`.
17#[cfg(feature = "antithesis")]
18#[doc(hidden)]
19pub use antithesis_sdk as __sdk;
20/// Hidden `serde_json::json` handle. The macros wrap detail maps through this path so call sites need no `serde_json`
21/// dependency of their own.
22#[cfg(feature = "antithesis")]
23#[doc(hidden)]
24pub use serde_json::json as __json;
25
26/// Initializes the Antithesis SDK and its assertion catalog. No-op without the
27/// `antithesis` feature.
28#[cfg(feature = "antithesis")]
29pub fn init() {
30    antithesis_sdk::antithesis_init();
31}
32
33/// Initializes the Antithesis SDK and its assertion catalog. No-op without the
34/// `antithesis` feature.
35#[cfg(not(feature = "antithesis"))]
36pub fn init() {}
37
38// Feature on. Every macro forwards to the live SDK macro at the call site.
39#[cfg(feature = "antithesis")]
40mod enabled {
41    /// Asserts `condition` holds every time this line runs, and that the line runs at least once.
42    #[macro_export]
43    macro_rules! always {
44        ($condition:expr, $message:literal, { $($details:tt)* }) => {
45            $crate::__sdk::assert_always!($condition, $message, &$crate::__json!({ $($details)* }))
46        };
47        ($condition:expr, $message:literal) => {
48            $crate::__sdk::assert_always!($condition, $message)
49        };
50    }
51
52    /// Asserts `condition` holds every time this line runs. Passes even if the line never runs.
53    #[macro_export]
54    macro_rules! always_or_unreachable {
55        ($condition:expr, $message:literal, { $($details:tt)* }) => {
56            $crate::__sdk::assert_always_or_unreachable!($condition, $message, &$crate::__json!({ $($details)* }))
57        };
58        ($condition:expr, $message:literal) => {
59            $crate::__sdk::assert_always_or_unreachable!($condition, $message)
60        };
61    }
62
63    /// Asserts `condition` holds at least once across all runs of this line.
64    #[macro_export]
65    macro_rules! sometimes {
66        ($condition:expr, $message:literal, { $($details:tt)* }) => {
67            $crate::__sdk::assert_sometimes!($condition, $message, &$crate::__json!({ $($details)* }))
68        };
69        ($condition:expr, $message:literal) => {
70            $crate::__sdk::assert_sometimes!($condition, $message)
71        };
72    }
73
74    /// Asserts this line is reached at least once.
75    #[macro_export]
76    macro_rules! reachable {
77        ($message:literal, { $($details:tt)* }) => {
78            $crate::__sdk::assert_reachable!($message, &$crate::__json!({ $($details)* }))
79        };
80        ($message:literal) => {
81            $crate::__sdk::assert_reachable!($message)
82        };
83    }
84
85    /// Asserts this line is never reached.
86    #[macro_export]
87    macro_rules! unreachable {
88        ($message:literal, { $($details:tt)* }) => {
89            $crate::__sdk::assert_unreachable!($message, &$crate::__json!({ $($details)* }))
90        };
91        ($message:literal) => {
92            $crate::__sdk::assert_unreachable!($message)
93        };
94    }
95
96    /// Asserts `left > right` always, with numeric guidance on the two operands.
97    #[macro_export]
98    macro_rules! always_gt {
99        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {
100            $crate::__sdk::assert_always_greater_than!($left, $right, $message, &$crate::__json!({ $($details)* }))
101        };
102        ($left:expr, $right:expr, $message:literal) => {
103            $crate::__sdk::assert_always_greater_than!($left, $right, $message)
104        };
105    }
106
107    /// Asserts `left >= right` always, with numeric guidance on the two operands.
108    #[macro_export]
109    macro_rules! always_ge {
110        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {
111            $crate::__sdk::assert_always_greater_than_or_equal_to!(
112                $left, $right, $message, &$crate::__json!({ $($details)* })
113            )
114        };
115        ($left:expr, $right:expr, $message:literal) => {
116            $crate::__sdk::assert_always_greater_than_or_equal_to!($left, $right, $message)
117        };
118    }
119
120    /// Asserts `left < right` always, with numeric guidance on the two operands.
121    #[macro_export]
122    macro_rules! always_lt {
123        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {
124            $crate::__sdk::assert_always_less_than!($left, $right, $message, &$crate::__json!({ $($details)* }))
125        };
126        ($left:expr, $right:expr, $message:literal) => {
127            $crate::__sdk::assert_always_less_than!($left, $right, $message)
128        };
129    }
130
131    /// Asserts `left <= right` always, with numeric guidance on the two operands.
132    #[macro_export]
133    macro_rules! always_le {
134        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {
135            $crate::__sdk::assert_always_less_than_or_equal_to!(
136                $left, $right, $message, &$crate::__json!({ $($details)* })
137            )
138        };
139        ($left:expr, $right:expr, $message:literal) => {
140            $crate::__sdk::assert_always_less_than_or_equal_to!($left, $right, $message)
141        };
142    }
143
144    /// Asserts `left > right` at least once, with numeric guidance on the two operands.
145    #[macro_export]
146    macro_rules! sometimes_gt {
147        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {
148            $crate::__sdk::assert_sometimes_greater_than!($left, $right, $message, &$crate::__json!({ $($details)* }))
149        };
150        ($left:expr, $right:expr, $message:literal) => {
151            $crate::__sdk::assert_sometimes_greater_than!($left, $right, $message)
152        };
153    }
154
155    /// Asserts `left >= right` at least once, with numeric guidance on the two operands.
156    #[macro_export]
157    macro_rules! sometimes_ge {
158        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {
159            $crate::__sdk::assert_sometimes_greater_than_or_equal_to!(
160                $left, $right, $message, &$crate::__json!({ $($details)* })
161            )
162        };
163        ($left:expr, $right:expr, $message:literal) => {
164            $crate::__sdk::assert_sometimes_greater_than_or_equal_to!($left, $right, $message)
165        };
166    }
167
168    /// Asserts `left < right` at least once, with numeric guidance on the two operands.
169    #[macro_export]
170    macro_rules! sometimes_lt {
171        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {
172            $crate::__sdk::assert_sometimes_less_than!($left, $right, $message, &$crate::__json!({ $($details)* }))
173        };
174        ($left:expr, $right:expr, $message:literal) => {
175            $crate::__sdk::assert_sometimes_less_than!($left, $right, $message)
176        };
177    }
178
179    /// Asserts `left <= right` at least once, with numeric guidance on the two operands.
180    #[macro_export]
181    macro_rules! sometimes_le {
182        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {
183            $crate::__sdk::assert_sometimes_less_than_or_equal_to!(
184                $left, $right, $message, &$crate::__json!({ $($details)* })
185            )
186        };
187        ($left:expr, $right:expr, $message:literal) => {
188            $crate::__sdk::assert_sometimes_less_than_or_equal_to!($left, $right, $message)
189        };
190    }
191
192    /// Asserts at least one of the named conditions always holds, with per-name guidance.
193    #[macro_export]
194    macro_rules! always_some {
195        ({ $($conditions:tt)* }, $message:literal, { $($details:tt)* }) => {
196            $crate::__sdk::assert_always_some!({ $($conditions)* }, $message, &$crate::__json!({ $($details)* }))
197        };
198        ({ $($conditions:tt)* }, $message:literal) => {
199            $crate::__sdk::assert_always_some!({ $($conditions)* }, $message)
200        };
201    }
202
203    /// Asserts every named condition holds at least once, with per-name guidance.
204    #[macro_export]
205    macro_rules! sometimes_all {
206        ({ $($conditions:tt)* }, $message:literal, { $($details:tt)* }) => {
207            $crate::__sdk::assert_sometimes_all!({ $($conditions)* }, $message, &$crate::__json!({ $($details)* }))
208        };
209        ({ $($conditions:tt)* }, $message:literal) => {
210            $crate::__sdk::assert_sometimes_all!({ $($conditions)* }, $message)
211        };
212    }
213}
214
215// Feature off. Every macro is a no-op that elides its arguments unevaluated.
216#[cfg(not(feature = "antithesis"))]
217mod disabled {
218    /// Asserts `condition` holds every time this line runs, and that the line runs at least once.
219    #[macro_export]
220    macro_rules! always {
221        ($condition:expr, $message:literal, { $($details:tt)* }) => {{}};
222        ($condition:expr, $message:literal) => {{}};
223    }
224
225    /// Asserts `condition` holds every time this line runs. Passes even if the line never runs.
226    #[macro_export]
227    macro_rules! always_or_unreachable {
228        ($condition:expr, $message:literal, { $($details:tt)* }) => {{}};
229        ($condition:expr, $message:literal) => {{}};
230    }
231
232    /// Asserts `condition` holds at least once across all runs of this line.
233    #[macro_export]
234    macro_rules! sometimes {
235        ($condition:expr, $message:literal, { $($details:tt)* }) => {{}};
236        ($condition:expr, $message:literal) => {{}};
237    }
238
239    /// Asserts this line is reached at least once.
240    #[macro_export]
241    macro_rules! reachable {
242        ($message:literal, { $($details:tt)* }) => {{}};
243        ($message:literal) => {{}};
244    }
245
246    /// Asserts this line is never reached.
247    #[macro_export]
248    macro_rules! unreachable {
249        ($message:literal, { $($details:tt)* }) => {{}};
250        ($message:literal) => {{}};
251    }
252
253    /// Asserts `left > right` always, with numeric guidance on the two operands.
254    #[macro_export]
255    macro_rules! always_gt {
256        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {{}};
257        ($left:expr, $right:expr, $message:literal) => {{}};
258    }
259
260    /// Asserts `left >= right` always, with numeric guidance on the two operands.
261    #[macro_export]
262    macro_rules! always_ge {
263        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {{}};
264        ($left:expr, $right:expr, $message:literal) => {{}};
265    }
266
267    /// Asserts `left < right` always, with numeric guidance on the two operands.
268    #[macro_export]
269    macro_rules! always_lt {
270        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {{}};
271        ($left:expr, $right:expr, $message:literal) => {{}};
272    }
273
274    /// Asserts `left <= right` always, with numeric guidance on the two operands.
275    #[macro_export]
276    macro_rules! always_le {
277        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {{}};
278        ($left:expr, $right:expr, $message:literal) => {{}};
279    }
280
281    /// Asserts `left > right` at least once, with numeric guidance on the two operands.
282    #[macro_export]
283    macro_rules! sometimes_gt {
284        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {{}};
285        ($left:expr, $right:expr, $message:literal) => {{}};
286    }
287
288    /// Asserts `left >= right` at least once, with numeric guidance on the two operands.
289    #[macro_export]
290    macro_rules! sometimes_ge {
291        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {{}};
292        ($left:expr, $right:expr, $message:literal) => {{}};
293    }
294
295    /// Asserts `left < right` at least once, with numeric guidance on the two operands.
296    #[macro_export]
297    macro_rules! sometimes_lt {
298        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {{}};
299        ($left:expr, $right:expr, $message:literal) => {{}};
300    }
301
302    /// Asserts `left <= right` at least once, with numeric guidance on the two operands.
303    #[macro_export]
304    macro_rules! sometimes_le {
305        ($left:expr, $right:expr, $message:literal, { $($details:tt)* }) => {{}};
306        ($left:expr, $right:expr, $message:literal) => {{}};
307    }
308
309    /// Asserts at least one of the named conditions always holds, with per-name guidance.
310    #[macro_export]
311    macro_rules! always_some {
312        ({ $($conditions:tt)* }, $message:literal, { $($details:tt)* }) => {{}};
313        ({ $($conditions:tt)* }, $message:literal) => {{}};
314    }
315
316    /// Asserts every named condition holds at least once, with per-name guidance.
317    #[macro_export]
318    macro_rules! sometimes_all {
319        ({ $($conditions:tt)* }, $message:literal, { $($details:tt)* }) => {{}};
320        ({ $($conditions:tt)* }, $message:literal) => {{}};
321    }
322}