Expand description
§leviso-cheat-guard
Runtime macros for cheat-aware error handling in non-test contexts.
This crate provides macro_rules! macros that work like anyhow::bail! and
anyhow::ensure! but include cheat documentation in error messages.
§Why This Exists
The leviso-cheat-test crate provides proc-macro attributes for #[test] functions.
But install-tests uses a custom Step trait, not standard tests. This crate
provides macros that can be used inside any function to document cheat vectors
and fail with informative messages.
§Macros
cheat_bail!- Likebail!()but with cheat documentationcheat_ensure!- Likeensure!()but with cheat documentationcheat_check!- Check a condition and add to StepResult with cheat metadata
§Example
ⓘ
use leviso_cheat_guard::cheat_bail;
fn partition_disk(console: &mut Console) -> Result<()> {
let output = console.exec("sfdisk /dev/vda", timeout)?;
if !output.contains("vda1") {
cheat_bail!(
protects = "Disk is partitioned correctly",
severity = "CRITICAL",
cheats = ["Accept exit code without verification", "Skip partition check"],
consequence = "No partitions, installation fails silently",
"Partition vda1 not found after sfdisk"
);
}
Ok(())
}Macros§
- cheat_
bail - Bail with cheat-aware error message.
- cheat_
check - Check a condition and record result with cheat metadata.
- cheat_
ensure - Ensure a condition with cheat-aware error message.
Enums§
- Check
Result - CheckResult for use with cheat_check! macro. Mirrors the install-tests CheckResult enum.
Attribute Macros§
- cheat_
aware - Mark a test as cheat-aware, documenting how it could be cheated.
- cheat_
canary - Mark a test as a canary - an intentionally verbose/tedious test that should trigger extra scrutiny if modified.
- cheat_
reviewed - A simpler version of
cheat_awarefor tests where full metadata isn’t needed.