envtestkit/
lib.rs

1//! Test kit for logics which involves environment variables.
2//!
3//! # Usage
4//!
5//! To test environment-related logics:
6//! ```
7//! use envtestkit::lock::lock_test;
8//! use envtestkit::set_env;
9//! use std::ffi::OsString;
10//!
11//! let _lock = lock_test();
12//! let _test = set_env(OsString::from("ENV_KEY"), "value");
13//! // Put your test logic here ...
14//! ```
15//!
16//! Complete examples can be found in `examples/` directory of this crate.
17//!
18//! # Race Condition
19//!
20//! Environment variables are global states. These things need to be ensured for building robust tests:
21//! - Run environment-modifying tests in serial.
22//! - Run environment-sensitive tests while no environment-modifying tests are running at the moment.
23//!
24//! For that, please use appropriate locks in your tests. See the [lock](lock/index.html) module.
25
26#![warn(missing_docs)]
27#![warn(missing_doc_code_examples)]
28
29#[cfg(feature = "lock")]
30#[macro_use]
31extern crate lazy_static;
32
33/// Tools for serializing environment-modifying tests.
34#[cfg(feature = "lock")]
35pub mod lock;
36
37mod testkit;
38pub use testkit::*;