Newer
Older

Louis
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use micro_games_macros::event_system;
use std::sync::Mutex;
#[test]
fn event_system_correctly_generates_and_dispatches_events() {
use bevy::prelude::*;
let mut app = App::new();
#[event_system]
enum MyEvents {
Wait { source: Entity },
Log { source: Entity, mesasge: String },
}
/// A hatch to allow us to assert that the system has actually run, so we don't miss an
/// assertion
#[derive(Resource)]
struct HasRun(bool);
app.insert_resource(HasRun(false));
app.add_plugins(MyEventsPlugin);
app.add_systems(
Update,
|mut has_run: ResMut<HasRun>, mut events: EventReader<WaitEvent>| {
has_run.0 = true;
let event_length = events.len();
assert_eq!(event_length, 1);
},
);
dispatch_my_events(
&mut app.world,
MyEvents::Wait(WaitEvent {
source: Entity::from_raw(0),
}),
);
app.update();
assert!(app.world.resource::<HasRun>().0);
}