From 0b00fcfff577c4d0d0a683fd9e061f0f43257252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 27 Aug 2025 02:33:58 +0200 Subject: [PATCH] Remove `test` feature and expose `Preset` unconditionally --- Cargo.lock | 1 - Cargo.toml | 5 +---- examples/todos/Cargo.toml | 3 +-- examples/todos/src/main.rs | 15 +++++---------- program/Cargo.toml | 1 - program/src/lib.rs | 3 --- src/application.rs | 16 +--------------- src/application/timed.rs | 2 -- src/daemon.rs | 31 ++++++++++++++++++++++++++++++- src/lib.rs | 3 ++- test/Cargo.toml | 4 +--- 11 files changed, 41 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6fd97456..40e459e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2488,7 +2488,6 @@ dependencies = [ "iced_devtools", "iced_futures", "iced_highlighter", - "iced_program", "iced_renderer", "iced_runtime", "iced_wgpu", diff --git a/Cargo.toml b/Cargo.toml index c8087550..0a8ac2a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,9 +48,7 @@ time-travel = ["debug", "iced_devtools/time-travel"] # Enables hot reloading (very experimental!) hot = ["debug", "iced_debug/hot"] # Enables the tester developer tool for recording and playing tests (press F12) -tester = ["debug", "test", "iced_devtools/tester"] -# Enables testing features (e.g. application presets) -test = ["iced_program/test"] +tester = ["debug", "iced_devtools/tester"] # Enables the `thread-pool` futures executor as the `executor::Default` on native platforms thread-pool = ["iced_futures/thread-pool"] # Enables `tokio` as the `executor::Default` on native platforms @@ -86,7 +84,6 @@ sipper = ["iced_runtime/sipper"] iced_debug.workspace = true iced_core.workspace = true iced_futures.workspace = true -iced_program.workspace = true iced_renderer.workspace = true iced_runtime.workspace = true iced_widget.workspace = true diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml index 9869a2c5..f47cd861 100644 --- a/examples/todos/Cargo.toml +++ b/examples/todos/Cargo.toml @@ -6,8 +6,7 @@ edition = "2024" publish = false [features] -test = ["iced/test"] -tester = ["test", "iced/tester"] +tester = ["iced/tester"] [dependencies] iced.workspace = true diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 3e15e492..ecaa99d4 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -5,7 +5,8 @@ use iced::widget::{ }; use iced::window; 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}; @@ -19,10 +20,8 @@ pub fn main() -> iced::Result { .subscription(Todos::subscription) .title(Todos::title) .font(Todos::ICON_FONT) - .window_size((500.0, 800.0)); - - #[cfg(feature = "test")] - let todos = todos.presets(presets()); + .window_size((500.0, 800.0)) + .presets(presets()); todos.run() } @@ -579,11 +578,7 @@ impl SavedState { } } -#[cfg(feature = "test")] -fn presets() -> impl Iterator> -{ - use iced::application::Preset; - +fn presets() -> impl Iterator> { [ Preset::new("Empty", || { (Todos::Loaded(State::default()), Command::none()) diff --git a/program/Cargo.toml b/program/Cargo.toml index 4b49f464..7aa6414d 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -15,7 +15,6 @@ workspace = true [features] time-travel = [] -test = [] [dependencies] iced_graphics.workspace = true diff --git a/program/src/lib.rs b/program/src/lib.rs index 04583bd3..c20afdfd 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -4,10 +4,8 @@ pub use iced_runtime as runtime; pub use iced_runtime::core; pub use iced_runtime::futures; -#[cfg(feature = "test")] mod preset; -#[cfg(feature = "test")] pub use preset::Preset; use crate::core::renderer; @@ -107,7 +105,6 @@ pub trait Program: Sized { 1.0 } - #[cfg(feature = "test")] fn presets(&self) -> &[Preset] { &[] } diff --git a/src/application.rs b/src/application.rs index e832834c..6b965502 100644 --- a/src/application.rs +++ b/src/application.rs @@ -35,7 +35,7 @@ use crate::shell; use crate::theme; use crate::window; use crate::{ - Element, Executor, Font, Result, Settings, Size, Subscription, Task, + Element, Executor, Font, Preset, Result, Settings, Size, Subscription, Task, }; use iced_debug as debug; @@ -44,8 +44,6 @@ use std::borrow::Cow; pub mod timed; -#[cfg(feature = "test")] -pub use program::Preset; pub use timed::timed; /// Creates an iced [`Application`] given its boot, update, and view logic. @@ -158,8 +156,6 @@ where }, settings: Settings::default(), window: window::Settings::default(), - - #[cfg(feature = "test")] presets: Vec::new(), } } @@ -176,8 +172,6 @@ pub struct Application { raw: P, settings: Settings, window: window::Settings, - - #[cfg(feature = "test")] presets: Vec>, } @@ -348,7 +342,6 @@ impl Application

{ }), settings: self.settings, window: self.window, - #[cfg(feature = "test")] presets: self.presets, } } @@ -366,7 +359,6 @@ impl Application

{ }), settings: self.settings, window: self.window, - #[cfg(feature = "test")] presets: self.presets, } } @@ -384,7 +376,6 @@ impl Application

{ }), settings: self.settings, window: self.window, - #[cfg(feature = "test")] presets: self.presets, } } @@ -402,7 +393,6 @@ impl Application

{ }), settings: self.settings, window: self.window, - #[cfg(feature = "test")] presets: self.presets, } } @@ -420,7 +410,6 @@ impl Application

{ }), settings: self.settings, window: self.window, - #[cfg(feature = "test")] presets: self.presets, } } @@ -438,7 +427,6 @@ impl Application

{ raw: program::with_executor::(self.raw), settings: self.settings, window: self.window, - #[cfg(feature = "test")] presets: self.presets, } } @@ -448,7 +436,6 @@ impl Application

{ /// Presets can be used to override the default booting strategy /// of your application during testing to create reproducible /// environments. - #[cfg(feature = "test")] pub fn presets( self, presets: impl IntoIterator>, @@ -519,7 +506,6 @@ impl Program for Application

{ self.raw.scale_factor(state, window) } - #[cfg(feature = "test")] fn presets(&self) -> &[Preset] { &self.presets } diff --git a/src/application/timed.rs b/src/application/timed.rs index 7deb3faa..02574b3a 100644 --- a/src/application/timed.rs +++ b/src/application/timed.rs @@ -147,8 +147,6 @@ where }, settings: Settings::default(), window: window::Settings::default(), - - #[cfg(feature = "test")] presets: Vec::new(), } } diff --git a/src/daemon.rs b/src/daemon.rs index d64b7712..fceb1486 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -4,7 +4,9 @@ use crate::program::{self, Program}; use crate::shell; use crate::theme; 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; @@ -101,6 +103,7 @@ where _renderer: PhantomData, }, settings: Settings::default(), + presets: Vec::new(), } } @@ -115,6 +118,7 @@ where pub struct Daemon { raw: P, settings: Settings, + presets: Vec>, } impl Daemon

{ @@ -187,6 +191,7 @@ impl Daemon

{ debug::hot(|| title.title(state, window)) }), settings: self.settings, + presets: self.presets, } } @@ -202,6 +207,7 @@ impl Daemon

{ debug::hot(|| f(state)) }), settings: self.settings, + presets: self.presets, } } @@ -217,6 +223,7 @@ impl Daemon

{ debug::hot(|| f(state, window)) }), settings: self.settings, + presets: self.presets, } } @@ -232,6 +239,7 @@ impl Daemon

{ debug::hot(|| f(state, theme)) }), settings: self.settings, + presets: self.presets, } } @@ -247,6 +255,7 @@ impl Daemon

{ debug::hot(|| f(state, window)) }), settings: self.settings, + presets: self.presets, } } @@ -262,6 +271,22 @@ impl Daemon

{ Daemon { raw: program::with_executor::(self.raw), 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>, + ) -> Self { + Self { + presets: presets.into_iter().collect(), + ..self } } } @@ -324,6 +349,10 @@ impl Program for Daemon

{ fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 { self.raw.scale_factor(state, window) } + + fn presets(&self) -> &[Preset] { + &self.presets + } } /// The title logic of some [`Daemon`]. diff --git a/src/lib.rs b/src/lib.rs index 79867909..29dffb1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -475,11 +475,11 @@ )] #![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))] -use iced_program as program; use iced_widget::graphics; use iced_widget::renderer; use iced_winit as shell; use iced_winit::core; +use iced_winit::program; use iced_winit::runtime; pub use iced_futures::futures; @@ -525,6 +525,7 @@ pub use crate::core::{ Function, Gradient, Length, Padding, Pixels, Point, Radians, Rectangle, Rotation, Settings, Shadow, Size, Theme, Transformation, Vector, never, }; +pub use crate::program::Preset; pub use crate::runtime::exit; pub use iced_futures::Subscription; diff --git a/test/Cargo.toml b/test/Cargo.toml index af15020e..7c30cefd 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -15,10 +15,8 @@ workspace = true [dependencies] iced_runtime.workspace = true -iced_selector.workspace = true - iced_program.workspace = true -iced_program.features = ["test"] +iced_selector.workspace = true iced_renderer.workspace = true iced_renderer.features = ["fira-sans"]