Crate droptest

Source
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§

prelude
The doptest prelude.

Macros§

assert_drop
Asserts that the registry has registered a drop for the given id.
assert_drop_stats
Asserts that the registry’s current stats match the provided pattern.
assert_no_drop
Asserts that the registry has not registered a drop for the given id.

Structs§

DropGuard
A guard object that reports to its registry when it gets dropped.
DropGuardId
An identifier associated with a registry’s individual registered guards.
DropRegistry
A registry for tracking a guard’s liveness state (i.e. alive vs. dropped).
DropStatistics
A snapshot for a registry’s statistics at a given time.