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)