pub struct MockPtyBackend { /* private fields */ }Expand description
Cloneable mock backend with one shared recording state.
Every clone and every session spawned from the same backend shares spawn
configs, writes, resizes, and one global event queue. Session shutdown flags
are per spawn, but PtyHandle clones share their session.
No automatic output or exit event is generated.
§Panics
Public mock operations panic with "mock pty state" if shared state’s mutex
has been poisoned by another thread.
§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let backend = MockPtyBackend::default();
backend.spawn(PtySpawnConfig::default()).unwrap().write(b"x").unwrap();
assert_eq!(backend.writes(), vec![b"x".to_vec()]);Implementations§
Source§impl MockPtyBackend
impl MockPtyBackend
Sourcepub fn with_spawn_error(self, error: PtyError) -> Self
pub fn with_spawn_error(self, error: PtyError) -> Self
Configures a cloned error to be returned by every later spawn.
The method consumes and returns this backend value, but mutates state
shared with any pre-existing clones. There is no setter to clear the error;
create a fresh default backend for successful spawning. Failed configs are
not added to Self::spawned_configs.
§Panics
Panics if the shared mock mutex is poisoned.
§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtyError, PtySpawnConfig};
let backend = MockPtyBackend::default().with_spawn_error(PtyError::Spawn("fixture".into()));
assert_eq!(backend.spawn(PtySpawnConfig::default()).unwrap_err(), PtyError::Spawn("fixture".into()));
assert!(backend.spawned_configs().is_empty());Sourcepub fn push_event(&self, event: PtyEvent)
pub fn push_event(&self, event: PtyEvent)
Appends an event to the global queue without requiring a spawned session.
Events are stored verbatim and drained FIFO by the first session handle
that calls drain_events.
§Panics
Panics if the shared mock mutex is poisoned.
§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtyEvent, PtySpawnConfig};
let backend = MockPtyBackend::default(); backend.push_event(PtyEvent::Output(vec![1, 2]));
let handle = backend.spawn(PtySpawnConfig::default()).unwrap();
assert_eq!(handle.drain_events(), vec![PtyEvent::Output(vec![1, 2])]);Sourcepub fn spawned_configs(&self) -> Vec<PtySpawnConfig>
pub fn spawned_configs(&self) -> Vec<PtySpawnConfig>
Clones successful spawn configurations in call order.
§Panics
Panics if the shared mock mutex is poisoned.
§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let backend = MockPtyBackend::default(); let config = PtySpawnConfig::default();
backend.spawn(config.clone()).unwrap();
assert_eq!(backend.spawned_configs(), vec![config]);Sourcepub fn writes(&self) -> Vec<Vec<u8>>
pub fn writes(&self) -> Vec<Vec<u8>>
Clones all successful writes from every shared session.
Empty writes are recorded. Mutating the returned vectors does not change the backend.
§Panics
Panics if the shared mock mutex is poisoned.
§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let backend = MockPtyBackend::default();
backend.spawn(PtySpawnConfig::default()).unwrap().write(&[]).unwrap();
assert_eq!(backend.writes(), vec![Vec::<u8>::new()]);Sourcepub fn resizes(&self) -> Vec<PtySize>
pub fn resizes(&self) -> Vec<PtySize>
Clones all successful resize requests from every shared session.
Values are recorded exactly; constructor invariants are not rechecked.
§Panics
Panics if the shared mock mutex is poisoned.
§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySize, PtySpawnConfig};
let backend = MockPtyBackend::default(); let size = PtySize::new(30, 90, 0, 0);
backend.spawn(PtySpawnConfig::default()).unwrap().resize(size).unwrap();
assert_eq!(backend.resizes(), vec![size]);Trait Implementations§
Source§impl Clone for MockPtyBackend
impl Clone for MockPtyBackend
Source§fn clone(&self) -> MockPtyBackend
fn clone(&self) -> MockPtyBackend
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for MockPtyBackend
impl Default for MockPtyBackend
Source§fn default() -> MockPtyBackend
fn default() -> MockPtyBackend
Source§impl PtyBackend for MockPtyBackend
impl PtyBackend for MockPtyBackend
Source§fn spawn(&self, config: PtySpawnConfig) -> Result<PtyHandle, PtyError>
fn spawn(&self, config: PtySpawnConfig) -> Result<PtyHandle, PtyError>
Returns the configured error or records config and creates a fresh session.
§Errors
Returns the error installed through Self::with_spawn_error, when one
is configured. No session or spawn record is created in that case.
§Panics
Panics if the shared mock-state mutex is poisoned.
Auto Trait Implementations§
impl Freeze for MockPtyBackend
impl RefUnwindSafe for MockPtyBackend
impl Send for MockPtyBackend
impl Sync for MockPtyBackend
impl Unpin for MockPtyBackend
impl UnwindSafe for MockPtyBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.