Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_dev_tools/src/ci_testing/config.rs
6601 views
1
use bevy_ecs::prelude::*;
2
use serde::Deserialize;
3
4
/// A configuration struct for automated CI testing.
5
///
6
/// It gets used when the `bevy_ci_testing` feature is enabled to automatically
7
/// exit a Bevy app when run through the CI. This is needed because otherwise
8
/// Bevy apps would be stuck in the game loop and wouldn't allow the CI to progress.
9
#[derive(Deserialize, Resource, PartialEq, Debug, Default)]
10
pub struct CiTestingConfig {
11
/// The setup for this test.
12
#[serde(default)]
13
pub setup: CiTestingSetup,
14
/// Events to send, with their associated frame.
15
#[serde(default)]
16
pub events: Vec<CiTestingEventOnFrame>,
17
}
18
19
/// Setup for a test.
20
#[derive(Deserialize, Default, PartialEq, Debug)]
21
pub struct CiTestingSetup {
22
/// The amount of time in seconds between frame updates.
23
///
24
/// This is set through the [`TimeUpdateStrategy::ManualDuration`] resource.
25
///
26
/// [`TimeUpdateStrategy::ManualDuration`]: bevy_time::TimeUpdateStrategy::ManualDuration
27
pub fixed_frame_time: Option<f32>,
28
}
29
30
/// An event to send at a given frame, used for CI testing.
31
#[derive(Deserialize, PartialEq, Debug)]
32
pub struct CiTestingEventOnFrame(pub u32, pub CiTestingEvent);
33
34
/// An event to send, used for CI testing.
35
#[derive(Deserialize, PartialEq, Debug)]
36
pub enum CiTestingEvent {
37
/// Takes a screenshot of the entire screen, and saves the results to
38
/// `screenshot-{current_frame}.png`.
39
Screenshot,
40
/// Takes a screenshot of the entire screen, saves the results to
41
/// `screenshot-{current_frame}.png`, and exits once the screenshot is taken.
42
ScreenshotAndExit,
43
/// Takes a screenshot of the entire screen, and saves the results to
44
/// `screenshot-{name}.png`.
45
NamedScreenshot(String),
46
/// Stops the program by sending [`AppExit::Success`].
47
///
48
/// [`AppExit::Success`]: bevy_app::AppExit::Success
49
AppExit,
50
/// Sends a [`CiTestingCustomEvent`] using the given [`String`].
51
Custom(String),
52
}
53
54
/// A custom event that can be configured from a configuration file for CI testing.
55
#[derive(BufferedEvent)]
56
pub struct CiTestingCustomEvent(pub String);
57
58
#[cfg(test)]
59
mod tests {
60
use super::*;
61
62
#[test]
63
fn deserialize() {
64
const INPUT: &str = r#"
65
(
66
setup: (
67
fixed_frame_time: Some(0.03),
68
),
69
events: [
70
(100, Custom("Hello, world!")),
71
(200, Screenshot),
72
(300, AppExit),
73
],
74
)"#;
75
76
let expected = CiTestingConfig {
77
setup: CiTestingSetup {
78
fixed_frame_time: Some(0.03),
79
},
80
events: vec![
81
CiTestingEventOnFrame(100, CiTestingEvent::Custom("Hello, world!".into())),
82
CiTestingEventOnFrame(200, CiTestingEvent::Screenshot),
83
CiTestingEventOnFrame(300, CiTestingEvent::AppExit),
84
],
85
};
86
87
let config: CiTestingConfig = ron::from_str(INPUT).unwrap();
88
89
assert_eq!(config, expected);
90
}
91
}
92
93