Remove test feature and expose Preset unconditionally

This commit is contained in:
Héctor Ramón Jiménez 2025-08-27 02:33:58 +02:00
parent 1923d1db1e
commit 0b00fcfff5
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
11 changed files with 41 additions and 43 deletions

1
Cargo.lock generated
View file

@ -2488,7 +2488,6 @@ dependencies = [
"iced_devtools", "iced_devtools",
"iced_futures", "iced_futures",
"iced_highlighter", "iced_highlighter",
"iced_program",
"iced_renderer", "iced_renderer",
"iced_runtime", "iced_runtime",
"iced_wgpu", "iced_wgpu",

View file

@ -48,9 +48,7 @@ time-travel = ["debug", "iced_devtools/time-travel"]
# Enables hot reloading (very experimental!) # Enables hot reloading (very experimental!)
hot = ["debug", "iced_debug/hot"] hot = ["debug", "iced_debug/hot"]
# Enables the tester developer tool for recording and playing tests (press F12) # Enables the tester developer tool for recording and playing tests (press F12)
tester = ["debug", "test", "iced_devtools/tester"] tester = ["debug", "iced_devtools/tester"]
# Enables testing features (e.g. application presets)
test = ["iced_program/test"]
# Enables the `thread-pool` futures executor as the `executor::Default` on native platforms # Enables the `thread-pool` futures executor as the `executor::Default` on native platforms
thread-pool = ["iced_futures/thread-pool"] thread-pool = ["iced_futures/thread-pool"]
# Enables `tokio` as the `executor::Default` on native platforms # Enables `tokio` as the `executor::Default` on native platforms
@ -86,7 +84,6 @@ sipper = ["iced_runtime/sipper"]
iced_debug.workspace = true iced_debug.workspace = true
iced_core.workspace = true iced_core.workspace = true
iced_futures.workspace = true iced_futures.workspace = true
iced_program.workspace = true
iced_renderer.workspace = true iced_renderer.workspace = true
iced_runtime.workspace = true iced_runtime.workspace = true
iced_widget.workspace = true iced_widget.workspace = true

View file

@ -6,8 +6,7 @@ edition = "2024"
publish = false publish = false
[features] [features]
test = ["iced/test"] tester = ["iced/tester"]
tester = ["test", "iced/tester"]
[dependencies] [dependencies]
iced.workspace = true iced.workspace = true

View file

@ -5,7 +5,8 @@ use iced::widget::{
}; };
use iced::window; use iced::window;
use iced::{ use iced::{
Center, Element, Fill, Font, Function, Subscription, Task as Command, Center, Element, Fill, Font, Function, Preset, Subscription,
Task as Command,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -19,10 +20,8 @@ pub fn main() -> iced::Result {
.subscription(Todos::subscription) .subscription(Todos::subscription)
.title(Todos::title) .title(Todos::title)
.font(Todos::ICON_FONT) .font(Todos::ICON_FONT)
.window_size((500.0, 800.0)); .window_size((500.0, 800.0))
.presets(presets());
#[cfg(feature = "test")]
let todos = todos.presets(presets());
todos.run() todos.run()
} }
@ -579,11 +578,7 @@ impl SavedState {
} }
} }
#[cfg(feature = "test")] fn presets() -> impl Iterator<Item = Preset<Todos, Message>> {
fn presets() -> impl Iterator<Item = iced::application::Preset<Todos, Message>>
{
use iced::application::Preset;
[ [
Preset::new("Empty", || { Preset::new("Empty", || {
(Todos::Loaded(State::default()), Command::none()) (Todos::Loaded(State::default()), Command::none())

View file

@ -15,7 +15,6 @@ workspace = true
[features] [features]
time-travel = [] time-travel = []
test = []
[dependencies] [dependencies]
iced_graphics.workspace = true iced_graphics.workspace = true

View file

@ -4,10 +4,8 @@ pub use iced_runtime as runtime;
pub use iced_runtime::core; pub use iced_runtime::core;
pub use iced_runtime::futures; pub use iced_runtime::futures;
#[cfg(feature = "test")]
mod preset; mod preset;
#[cfg(feature = "test")]
pub use preset::Preset; pub use preset::Preset;
use crate::core::renderer; use crate::core::renderer;
@ -107,7 +105,6 @@ pub trait Program: Sized {
1.0 1.0
} }
#[cfg(feature = "test")]
fn presets(&self) -> &[Preset<Self::State, Self::Message>] { fn presets(&self) -> &[Preset<Self::State, Self::Message>] {
&[] &[]
} }

View file

@ -35,7 +35,7 @@ use crate::shell;
use crate::theme; use crate::theme;
use crate::window; use crate::window;
use crate::{ use crate::{
Element, Executor, Font, Result, Settings, Size, Subscription, Task, Element, Executor, Font, Preset, Result, Settings, Size, Subscription, Task,
}; };
use iced_debug as debug; use iced_debug as debug;
@ -44,8 +44,6 @@ use std::borrow::Cow;
pub mod timed; pub mod timed;
#[cfg(feature = "test")]
pub use program::Preset;
pub use timed::timed; pub use timed::timed;
/// Creates an iced [`Application`] given its boot, update, and view logic. /// Creates an iced [`Application`] given its boot, update, and view logic.
@ -158,8 +156,6 @@ where
}, },
settings: Settings::default(), settings: Settings::default(),
window: window::Settings::default(), window: window::Settings::default(),
#[cfg(feature = "test")]
presets: Vec::new(), presets: Vec::new(),
} }
} }
@ -176,8 +172,6 @@ pub struct Application<P: Program> {
raw: P, raw: P,
settings: Settings, settings: Settings,
window: window::Settings, window: window::Settings,
#[cfg(feature = "test")]
presets: Vec<Preset<P::State, P::Message>>, presets: Vec<Preset<P::State, P::Message>>,
} }
@ -348,7 +342,6 @@ impl<P: Program> Application<P> {
}), }),
settings: self.settings, settings: self.settings,
window: self.window, window: self.window,
#[cfg(feature = "test")]
presets: self.presets, presets: self.presets,
} }
} }
@ -366,7 +359,6 @@ impl<P: Program> Application<P> {
}), }),
settings: self.settings, settings: self.settings,
window: self.window, window: self.window,
#[cfg(feature = "test")]
presets: self.presets, presets: self.presets,
} }
} }
@ -384,7 +376,6 @@ impl<P: Program> Application<P> {
}), }),
settings: self.settings, settings: self.settings,
window: self.window, window: self.window,
#[cfg(feature = "test")]
presets: self.presets, presets: self.presets,
} }
} }
@ -402,7 +393,6 @@ impl<P: Program> Application<P> {
}), }),
settings: self.settings, settings: self.settings,
window: self.window, window: self.window,
#[cfg(feature = "test")]
presets: self.presets, presets: self.presets,
} }
} }
@ -420,7 +410,6 @@ impl<P: Program> Application<P> {
}), }),
settings: self.settings, settings: self.settings,
window: self.window, window: self.window,
#[cfg(feature = "test")]
presets: self.presets, presets: self.presets,
} }
} }
@ -438,7 +427,6 @@ impl<P: Program> Application<P> {
raw: program::with_executor::<P, E>(self.raw), raw: program::with_executor::<P, E>(self.raw),
settings: self.settings, settings: self.settings,
window: self.window, window: self.window,
#[cfg(feature = "test")]
presets: self.presets, presets: self.presets,
} }
} }
@ -448,7 +436,6 @@ impl<P: Program> Application<P> {
/// Presets can be used to override the default booting strategy /// Presets can be used to override the default booting strategy
/// of your application during testing to create reproducible /// of your application during testing to create reproducible
/// environments. /// environments.
#[cfg(feature = "test")]
pub fn presets( pub fn presets(
self, self,
presets: impl IntoIterator<Item = Preset<P::State, P::Message>>, presets: impl IntoIterator<Item = Preset<P::State, P::Message>>,
@ -519,7 +506,6 @@ impl<P: Program> Program for Application<P> {
self.raw.scale_factor(state, window) self.raw.scale_factor(state, window)
} }
#[cfg(feature = "test")]
fn presets(&self) -> &[Preset<Self::State, Self::Message>] { fn presets(&self) -> &[Preset<Self::State, Self::Message>] {
&self.presets &self.presets
} }

View file

@ -147,8 +147,6 @@ where
}, },
settings: Settings::default(), settings: Settings::default(),
window: window::Settings::default(), window: window::Settings::default(),
#[cfg(feature = "test")]
presets: Vec::new(), presets: Vec::new(),
} }
} }

View file

@ -4,7 +4,9 @@ use crate::program::{self, Program};
use crate::shell; use crate::shell;
use crate::theme; use crate::theme;
use crate::window; use crate::window;
use crate::{Element, Executor, Font, Result, Settings, Subscription, Task}; use crate::{
Element, Executor, Font, Preset, Result, Settings, Subscription, Task,
};
use iced_debug as debug; use iced_debug as debug;
@ -101,6 +103,7 @@ where
_renderer: PhantomData, _renderer: PhantomData,
}, },
settings: Settings::default(), settings: Settings::default(),
presets: Vec::new(),
} }
} }
@ -115,6 +118,7 @@ where
pub struct Daemon<P: Program> { pub struct Daemon<P: Program> {
raw: P, raw: P,
settings: Settings, settings: Settings,
presets: Vec<Preset<P::State, P::Message>>,
} }
impl<P: Program> Daemon<P> { impl<P: Program> Daemon<P> {
@ -187,6 +191,7 @@ impl<P: Program> Daemon<P> {
debug::hot(|| title.title(state, window)) debug::hot(|| title.title(state, window))
}), }),
settings: self.settings, settings: self.settings,
presets: self.presets,
} }
} }
@ -202,6 +207,7 @@ impl<P: Program> Daemon<P> {
debug::hot(|| f(state)) debug::hot(|| f(state))
}), }),
settings: self.settings, settings: self.settings,
presets: self.presets,
} }
} }
@ -217,6 +223,7 @@ impl<P: Program> Daemon<P> {
debug::hot(|| f(state, window)) debug::hot(|| f(state, window))
}), }),
settings: self.settings, settings: self.settings,
presets: self.presets,
} }
} }
@ -232,6 +239,7 @@ impl<P: Program> Daemon<P> {
debug::hot(|| f(state, theme)) debug::hot(|| f(state, theme))
}), }),
settings: self.settings, settings: self.settings,
presets: self.presets,
} }
} }
@ -247,6 +255,7 @@ impl<P: Program> Daemon<P> {
debug::hot(|| f(state, window)) debug::hot(|| f(state, window))
}), }),
settings: self.settings, settings: self.settings,
presets: self.presets,
} }
} }
@ -262,6 +271,22 @@ impl<P: Program> Daemon<P> {
Daemon { Daemon {
raw: program::with_executor::<P, E>(self.raw), raw: program::with_executor::<P, E>(self.raw),
settings: self.settings, settings: self.settings,
presets: self.presets,
}
}
/// Sets the boot presets of the [`Daemon`].
///
/// Presets can be used to override the default booting strategy
/// of your application during testing to create reproducible
/// environments.
pub fn presets(
self,
presets: impl IntoIterator<Item = Preset<P::State, P::Message>>,
) -> Self {
Self {
presets: presets.into_iter().collect(),
..self
} }
} }
} }
@ -324,6 +349,10 @@ impl<P: Program> Program for Daemon<P> {
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 { fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
self.raw.scale_factor(state, window) self.raw.scale_factor(state, window)
} }
fn presets(&self) -> &[Preset<Self::State, Self::Message>] {
&self.presets
}
} }
/// The title logic of some [`Daemon`]. /// The title logic of some [`Daemon`].

View file

@ -475,11 +475,11 @@
)] )]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
use iced_program as program;
use iced_widget::graphics; use iced_widget::graphics;
use iced_widget::renderer; use iced_widget::renderer;
use iced_winit as shell; use iced_winit as shell;
use iced_winit::core; use iced_winit::core;
use iced_winit::program;
use iced_winit::runtime; use iced_winit::runtime;
pub use iced_futures::futures; pub use iced_futures::futures;
@ -525,6 +525,7 @@ pub use crate::core::{
Function, Gradient, Length, Padding, Pixels, Point, Radians, Rectangle, Function, Gradient, Length, Padding, Pixels, Point, Radians, Rectangle,
Rotation, Settings, Shadow, Size, Theme, Transformation, Vector, never, Rotation, Settings, Shadow, Size, Theme, Transformation, Vector, never,
}; };
pub use crate::program::Preset;
pub use crate::runtime::exit; pub use crate::runtime::exit;
pub use iced_futures::Subscription; pub use iced_futures::Subscription;

View file

@ -15,10 +15,8 @@ workspace = true
[dependencies] [dependencies]
iced_runtime.workspace = true iced_runtime.workspace = true
iced_selector.workspace = true
iced_program.workspace = true iced_program.workspace = true
iced_program.features = ["test"] iced_selector.workspace = true
iced_renderer.workspace = true iced_renderer.workspace = true
iced_renderer.features = ["fira-sans"] iced_renderer.features = ["fira-sans"]