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