Move tester to a new iced_tester subcrate

This commit is contained in:
Héctor Ramón Jiménez 2025-08-29 08:39:44 +02:00
parent 9e81c2b9e8
commit 4f7444bddf
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
28 changed files with 392 additions and 355 deletions

View file

@ -30,12 +30,14 @@
//! ]
//! }
//! ```
use crate::message;
use crate::program::{self, Program};
use crate::shell;
use crate::theme;
use crate::window;
use crate::{
Element, Executor, Font, Preset, Result, Settings, Size, Subscription, Task,
Element, Executor, Font, MaybeSend, Preset, Result, Settings, Size,
Subscription, Task,
};
use iced_debug as debug;
@ -81,7 +83,7 @@ pub fn application<State, Message, Theme, Renderer>(
) -> Application<impl Program<State = State, Message = Message, Theme = Theme>>
where
State: 'static,
Message: program::Message + 'static,
Message: MaybeSend + 'static,
Theme: Default + theme::Base,
Renderer: program::Renderer,
{
@ -100,7 +102,7 @@ where
impl<State, Message, Theme, Renderer, Boot, Update, View> Program
for Instance<State, Message, Theme, Renderer, Boot, Update, View>
where
Message: program::Message + 'static,
Message: MaybeSend + 'static,
Theme: Default + theme::Base,
Renderer: program::Renderer,
Boot: self::Boot<State, Message>,
@ -142,6 +144,10 @@ where
fn settings(&self) -> Settings {
Settings::default()
}
fn window(&self) -> Option<iced_core::window::Settings> {
Some(window::Settings::default())
}
}
Application {
@ -180,25 +186,25 @@ impl<P: Program> Application<P> {
pub fn run(self) -> Result
where
Self: 'static,
P::Message: message::MaybeDebug + message::MaybeClone,
{
let settings = self.settings.clone();
let window = self.window.clone();
#[cfg(feature = "debug")]
iced_debug::init(iced_debug::Metadata {
name: P::name(),
theme: None,
can_time_travel: cfg!(feature = "time-travel"),
});
#[cfg(all(feature = "debug", not(target_arch = "wasm32")))]
let program = {
iced_debug::init(iced_debug::Metadata {
name: P::name(),
theme: None,
can_time_travel: cfg!(feature = "time-travel"),
});
#[cfg(feature = "tester")]
let program = iced_tester::attach(self);
iced_devtools::attach(self)
};
#[cfg(all(feature = "debug", not(feature = "tester")))]
let program = iced_devtools::attach(self);
#[cfg(any(not(feature = "debug"), target_arch = "wasm32"))]
let program = self;
Ok(shell::run(program, settings, Some(window))?)
Ok(shell::run(program)?)
}
/// Sets the [`Settings`] that will be used to run the [`Application`].
@ -456,6 +462,10 @@ impl<P: Program> Program for Application<P> {
self.settings.clone()
}
fn window(&self) -> Option<window::Settings> {
Some(self.window.clone())
}
fn boot(&self) -> (Self::State, Task<Self::Message>) {
self.raw.boot()
}