Expand description
Support for the #[gpui::test] macro, and streams for observing entities in tests.
#[gpui::test] runs a test function once per seed. Each &TestAppContext
parameter gets its own app, and all the apps share one deterministic scheduler,
so a failing seed replays the same interleaving. The functions in this module
are used by the macro; you rarely need to call them directly. See the
testing guide.
§Example
use gpui::{AppContext, Global, TestAppContext};
struct Name(&'static str);
impl Global for Name {}
#[gpui::test]
fn test_counts_are_positive(cx: &mut TestAppContext) {
let count = cx.new(|_| 1usize);
cx.run_until_parked();
cx.read(|cx| assert!(*count.read(cx) > 0));
}
#[gpui::test]
fn test_each_app_has_its_own_globals(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
cx_a.update(|cx| cx.set_global(Name("alice")));
cx_b.update(|cx| cx.set_global(Name("bob")));
cx_a.read_global::<Name, _>(|name, _| assert_eq!(name.0, "alice"));
cx_b.read_global::<Name, _>(|name, _| assert_eq!(name.0, "bob"));
}Structs§
- Observation
- A stream of unit values from an entity observation, created by
observe.
Functions§
- apply_
seed_ to_ proptest_ config - Sets the RNG seed of a proptest config from
SEED, or from0when it’s unset. - observe
- Returns a stream that yields
()each timeentitynotifies. - run_
test - Runs
test_fnfor each seed, retrying a failing seed up tomax_retriestimes. - run_
test_ once - Runs
test_fnonce on a dispatcher forseed, and returns its result. - seed_
strategy - Returns a proptest strategy for scheduler seeds.