use bevy_ecs::prelude::*;
use bevy_math::{Quat, Vec3};
use serde::Deserialize;
#[derive(Deserialize, Resource, PartialEq, Debug, Default, Clone)]
pub struct CiTestingConfig {
#[serde(default)]
pub setup: CiTestingSetup,
#[serde(default)]
pub events: Vec<CiTestingEventOnFrame>,
}
#[derive(Deserialize, Default, PartialEq, Debug, Clone)]
pub struct CiTestingSetup {
pub fixed_frame_time: Option<f32>,
}
#[derive(Deserialize, PartialEq, Debug, Clone)]
pub struct CiTestingEventOnFrame(pub u32, pub CiTestingEvent);
#[derive(Deserialize, PartialEq, Debug, Clone)]
pub enum CiTestingEvent {
Screenshot,
ScreenshotAndExit,
NamedScreenshot(String),
AppExit,
StartScreenRecording,
StopScreenRecording,
MoveCamera {
translation: Vec3,
rotation: Quat,
},
Custom(String),
}
#[derive(Message)]
pub struct CiTestingCustomEvent(pub String);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn deserialize() {
const INPUT: &str = r#"
(
setup: (
fixed_frame_time: Some(0.03),
),
events: [
(100, Custom("Hello, world!")),
(200, Screenshot),
(300, AppExit),
],
)"#;
let expected = CiTestingConfig {
setup: CiTestingSetup {
fixed_frame_time: Some(0.03),
},
events: vec![
CiTestingEventOnFrame(100, CiTestingEvent::Custom("Hello, world!".into())),
CiTestingEventOnFrame(200, CiTestingEvent::Screenshot),
CiTestingEventOnFrame(300, CiTestingEvent::AppExit),
],
};
let config: CiTestingConfig = ron::from_str(INPUT).unwrap();
assert_eq!(config, expected);
}
}