Crate droptest[−][src]
Expand description
A helper crate for testing drop-semantics (i.e. whether or not a value was or as not dropped as expected).
Examples
Ensure std::mem::drop
does in fact drop:
use droptest::prelude::*;
let registry = DropRegistry::default();
let guard = registry.new_guard();
let guard_id = guard.id();
std::mem::drop(guard);
assert_drop!(registry, guard_id);
Ensure std::mem::forget
does not drop:
use droptest::prelude::*;
let registry = DropRegistry::default();
let guard = registry.new_guard();
let guard_id = guard.id();
std::mem::forget(guard);
assert_no_drop!(registry, guard_id);
Ensure std::rc::Rc
only drops the when reference count reaches 0
:
use droptest::prelude::*;
let registry = DropRegistry::default();
let guard = registry.new_guard();
let guard_id = guard.id();
let rc = std::rc::Rc::new(guard);
let rc_clone = rc.clone();
std::mem::drop(rc);
assert_no_drop!(registry, guard_id);
std::mem::drop(rc_clone);
assert_drop!(registry, guard_id);
Modules
The doptest prelude.
Macros
Asserts that the registry has registered a drop for the given id.
Asserts that the registry’s current stats match the provided pattern.
Asserts that the registry has not registered a drop for the given id.
Structs
A guard object that reports to its registry when it gets dropped.
An identifier associated with a registry’s individual registered guards.
A registry for tracking a guard’s liveness state (i.e. alive vs. dropped).
A snapshot for a registry’s statistics at a given time.