1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/// The assert module enables defining
/// [test properties](https://antithesis.com/docs/properties_assertions/properties/)
/// about your program or
/// [workload](https://antithesis.com/docs/test_templates/first_test/).
///
/// The constant [const@LOCAL_OUTPUT] is associated with local logging, which is
/// one of the
/// [local execution](https://antithesis.com/docs/using_antithesis/sdk/rust/#sdk-runtime-behavior)
/// modes.
///
/// Each macro/function in this module takes a parameter called ``message``,
/// which is a string literal identifier used to aggregate assertions.
/// Antithesis generates one test property per unique ``message`` This test
/// property will be named ``message`` in the
/// [triage report](https://antithesis.com/reports/example-triage-report).
///
/// Each macro/function also takes a parameter called ``details``, which is a
/// key-value map of optional additional information provided by the user to add
/// context for assertion failures. The information that is logged will appear
/// in the ``logs`` section of a
/// [triage report](https://antithesis.com/reports/example-triage-report).
/// Normally the values in ``details`` are evaluated at runtime. Details may be
/// borrowed structs or maps implementing [`serde::Serialize`]; serialization
/// happens only when an assertion evaluation is emitted. Constructing the
/// details argument still happens on every call, so `json!` at the call site is
/// not deferred. Omitted details and values that serialize to null are omitted
/// from the event; explicit empty objects are preserved. Other JSON values are
/// wrapped in an object under `"value"`, for example `3` becomes
/// `{"value": 3}`. Serialization errors emit an `antithesis_error` message and
/// omit details without suppressing the assertion.
// External crates used in assertion macros
pub use linkme;
pub use once_cell;
pub use serde_json;
/// The catalog module gives read access to the assertion catalog compiled
/// into this binary: every assertion macro call site linked into the
/// program, whether or not that code ever runs.
///
/// It exists for tooling rather than for workloads: comparing the assertions
/// a binary declares against the ones a local test suite encounters, failing
/// CI when a change silently drops an assertion, or checking an inventory of
/// test properties into the repository. Workloads use [`assert`](mod@crate::assert)
/// and [`random`] instead and never need this module.
///
/// [`catalog::assertions()`] lists the assertions as values.
/// [`catalog::write()`] writes them as the same JSON lines, in the same
/// order, that [`antithesis_init()`] emits for them, without init having
/// run. A binary can expose its own catalog with a few lines:
///
/// ```no_run
/// use std::io::stdout;
///
/// fn main() -> std::io::Result<()> {
/// if std::env::args().any(|a| a == "--antithesis-catalog") {
/// return antithesis_sdk::catalog::write(stdout());
/// }
/// // ... the actual program ...
/// Ok(())
/// }
/// ```
/// The lifecycle module contains functions which inform the Antithesis
/// environment that particular test phases or milestones have been reached.
///
/// The constant [const@LOCAL_OUTPUT] is associated with local logging, which is
/// one of the
/// [local execution](https://antithesis.com/docs/using_antithesis/sdk/rust/#sdk-runtime-behavior)
/// modes.
/// The random module provides functions that request both structured and
/// unstructured randomness from the Antithesis environment.
///
/// These functions should not be used to seed a conventional PRNG, and should
/// not have their return values stored and used to make a decision at a later
/// time. Doing either of these things makes it much harder for the Antithesis
/// platform to control the history of your program's execution, and also makes
/// it harder for Antithesis to learn which inputs provided at which times are
/// most fruitful. Instead, you should call a function from the random package
/// every time your program or
/// [workload](https://antithesis.com/docs/test_templates/first_test/) needs to
/// make a decision, at the moment that you need to make the decision.
///
/// These functions are also safe to call outside the Antithesis environment,
/// where they will fall back on the rust std library implementation.
///
/// # `rand` Integration
///
/// [`AntithesisRng`](crate::random::AntithesisRng) plugs the same
/// Antithesis-controlled randomness into the `rand` ecosystem. Enable the
/// feature flag that matches the version of `rand` your project already uses:
///
/// | Your `rand` version | Feature flag | Trait implemented |
/// |----------------------|----------------------------|------------------------------|
/// | 0.8 | `rand_v0_8` **(default)** | [`rand_core::RngCore`](https://docs.rs/rand_core/0.6/rand_core/trait.RngCore.html) |
/// | 0.9 | `rand_v0_9` | [`rand_core::RngCore`](https://docs.rs/rand_core/0.9/rand_core/trait.RngCore.html) |
/// | 0.10 | `rand_v0_10` | [`rand_core::TryRng`](https://docs.rs/rand_core/0.10/rand_core/trait.TryRng.html) |
///
/// ## Setup
///
/// Pick the flag matching your `rand` version. For example, with `rand 0.9`:
///
/// ```toml
/// [dependencies]
/// antithesis_sdk = { version = "0.3", features = ["rand_v0_9"] }
/// rand = "0.9"
/// ```
///
/// Multiple flags can coexist if your dependency tree includes more than one
/// `rand` version.
/// Convenience to import all macros and functions
/// Global initialization logic. Performs registration of the Antithesis
/// assertion catalog. This should be invoked as early as possible during
/// program execution. It is recommended to call it immediately in ``main``.
///
/// If called more than once, only the first call will result in the assertion
/// catalog being registered. If never called, the assertion catalog will be
/// registered when it encounters the first assertion at runtime.
///
/// Example:
///
/// ```
/// use std::env;
/// use serde_json::{json};
/// use antithesis_sdk::{antithesis_init, assert_unreachable};
///
/// fn main() {
/// if (env::args_os().len() == 1888999778899) {
/// assert_unreachable!("Unable to provide trillions of arguments", &json!({}));
/// }
///
/// // if antithesis_init() is omitted, the above unreachable will
/// // not be reported
/// antithesis_init();
/// }
/// ```
use Lazy;
/// A constant provided by the SDK to report the location of logged output when
/// run locally. This constant is the name of an environment variable
/// ``ANTITHESIS_SDK_LOCAL_OUTPUT``. ``ANTITHESIS_SDK_LOCAL_OUTPUT`` is a path
/// to a file that can be created and written to when running locally. If this
/// environment variable is not present at runtime, then no assertion and
/// lifecycle output will be attempted.
///
/// This allows you to make use of the Antithesis assertions module in your
/// regular testing, or even in production. In particular, very few assertions
/// frameworks offer a convenient way to define
/// [Sometimes assertions](https://antithesis.com/docs/best_practices/sometimes_assertions/),
/// but they can be quite useful even outside Antithesis.
///
/// See also the documentation for
/// [local execution](https://antithesis.com/docs/using_antithesis/sdk/rust/#sdk-runtime-behavior).
pub use crateLOCAL_OUTPUT;