pub struct TestConsole { /* private fields */ }Expand description
A Console that captures output for testing
This wraps a FastMcpConsole with a buffer writer to capture all output.
Use console() to get the inner console for rendering, then use
output(), contains(), and assertion methods to verify the output.
Implementations§
Source§impl TestConsole
impl TestConsole
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new test console that captures output
Note: Internally uses rich mode to ensure output goes through the writer.
ANSI codes are stripped when reading via output() and output_string().
Sourcepub fn console(&self) -> &FastMcpConsole
pub fn console(&self) -> &FastMcpConsole
Get the underlying console for passing to renderers
Sourcepub fn raw_output(&self) -> Vec<String>
pub fn raw_output(&self) -> Vec<String>
Get all captured output (with ANSI codes)
Sourcepub fn output_string(&self) -> String
pub fn output_string(&self) -> String
Get output as a single string
Sourcepub fn contains(&self, needle: &str) -> bool
pub fn contains(&self, needle: &str) -> bool
Check if output contains a string (case-insensitive)
Sourcepub fn contains_all(&self, needles: &[&str]) -> bool
pub fn contains_all(&self, needles: &[&str]) -> bool
Check if output contains all of the given strings
Sourcepub fn assert_contains(&self, needle: &str)
pub fn assert_contains(&self, needle: &str)
Assert that output contains a string
§Panics
Panics if the output does not contain the needle string.
Sourcepub fn assert_not_contains(&self, needle: &str)
pub fn assert_not_contains(&self, needle: &str)
Assert that output does NOT contain a string
§Panics
Panics if the output contains the needle string.
Sourcepub fn assert_line_count(&self, expected: usize)
pub fn assert_line_count(&self, expected: usize)
Sourcepub fn debug_print(&self)
pub fn debug_print(&self)
Print output for debugging (in tests)
Trait Implementations§
Source§impl Clone for TestConsole
impl Clone for TestConsole
Source§impl Debug for TestConsole
impl Debug for TestConsole
Auto Trait Implementations§
impl Freeze for TestConsole
impl RefUnwindSafe for TestConsole
impl Send for TestConsole
impl Sync for TestConsole
impl Unpin for TestConsole
impl UnsafeUnpin for TestConsole
impl UnwindSafe for TestConsole
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,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more