pub struct Test {
pub source_manager: Arc<DefaultSourceManager>,
pub source: Arc<SourceFile>,
pub kernel_source: Option<Arc<SourceFile>>,
pub stack_inputs: StackInputs,
pub advice_inputs: AdviceInputs,
pub in_debug_mode: bool,
pub libraries: Vec<Library>,
pub handlers: Vec<(EventName, Arc<dyn EventHandler>)>,
pub add_modules: Vec<(Arc<Path>, String)>,
}Expand description
This is a container for the data required to run tests, which allows for running several different types of tests.
Types of valid result tests:
- Execution test: check that running a program compiled from the given source has the specified results for the given (optional) inputs.
- Proptest: run an execution test inside a proptest.
Types of failure tests:
- Assembly error test: check that attempting to compile the given source causes an AssemblyError which contains the specified substring.
- Execution error test: check that running a program compiled from the given source causes an ExecutionError which contains the specified substring.
Fields§
§source_manager: Arc<DefaultSourceManager>§source: Arc<SourceFile>§kernel_source: Option<Arc<SourceFile>>§stack_inputs: StackInputs§advice_inputs: AdviceInputs§in_debug_mode: bool§libraries: Vec<Library>§handlers: Vec<(EventName, Arc<dyn EventHandler>)>§add_modules: Vec<(Arc<Path>, String)>Implementations§
Source§impl Test
impl Test
Sourcepub fn new(name: &str, source: &str, in_debug_mode: bool) -> Self
pub fn new(name: &str, source: &str, in_debug_mode: bool) -> Self
Creates the simplest possible new test, with only a source string and no inputs.
Sourcepub fn with_kernel(self, kernel_source: impl ToString) -> Self
pub fn with_kernel(self, kernel_source: impl ToString) -> Self
Adds kernel source to this test so it is assembled and linked during compilation.
Sourcepub fn with_kernel_source(
self,
kernel_name: impl Into<String>,
kernel_source: impl ToString,
) -> Self
pub fn with_kernel_source( self, kernel_name: impl Into<String>, kernel_source: impl ToString, ) -> Self
Adds kernel source to this test so it is assembled and linked during compilation.
Sourcepub fn add_module(&mut self, path: impl AsRef<Path>, source: impl ToString)
pub fn add_module(&mut self, path: impl AsRef<Path>, source: impl ToString)
Add an extra module to link in during assembly
Sourcepub fn add_event_handler(
&mut self,
event: EventName,
handler: impl EventHandler,
)
pub fn add_event_handler( &mut self, event: EventName, handler: impl EventHandler, )
Add a handler for a specific event when running the Host.
Sourcepub fn add_event_handlers(
&mut self,
handlers: Vec<(EventName, Arc<dyn EventHandler>)>,
)
pub fn add_event_handlers( &mut self, handlers: Vec<(EventName, Arc<dyn EventHandler>)>, )
Add a handler for a specific event when running the Host.
Sourcepub fn expect_stack(&self, final_stack: &[u64])
pub fn expect_stack(&self, final_stack: &[u64])
Builds a final stack from the provided stack-ordered array and asserts that executing the test will result in the expected final stack state.
Sourcepub fn expect_stack_and_memory(
&self,
final_stack: &[u64],
mem_start_addr: u32,
expected_mem: &[u64],
)
pub fn expect_stack_and_memory( &self, final_stack: &[u64], mem_start_addr: u32, expected_mem: &[u64], )
Executes the test and validates that the process memory has the elements of expected_mem
at address mem_start_addr and that the end of the stack execution trace matches the
final_stack.
Sourcepub fn prop_expect_stack(
&self,
final_stack: &[u64],
) -> Result<(), TestCaseError>
pub fn prop_expect_stack( &self, final_stack: &[u64], ) -> Result<(), TestCaseError>
Asserts that executing the test inside a proptest results in the expected final stack state. The proptest will return a test failure instead of panicking if the assertion condition fails.
Sourcepub fn compile(&self) -> Result<(Program, Option<KernelLibrary>), Report>
pub fn compile(&self) -> Result<(Program, Option<KernelLibrary>), Report>
Compiles a test’s source and returns the resulting Program together with the associated kernel library (when specified).
§Errors
Returns an error if compilation of the program source or the kernel fails.
Sourcepub fn execute(&self) -> Result<ExecutionTrace, ExecutionError>
pub fn execute(&self) -> Result<ExecutionTrace, ExecutionError>
Compiles the test’s source to a Program and executes it with the tests inputs. Returns a resulting execution trace or error.
Internally, this also checks that the slow and fast processors agree on the stack outputs.
Sourcepub fn execute_for_output(
&self,
) -> Result<(ExecutionOutput, DefaultHost), ExecutionError>
pub fn execute_for_output( &self, ) -> Result<(ExecutionOutput, DefaultHost), ExecutionError>
Compiles the test’s source to a Program and executes it with the tests inputs.
Returns the [ExecutionOutput] once execution is finished.
Sourcepub fn execute_with_debug_buffer(
&self,
) -> Result<(StackOutputs, String), ExecutionError>
pub fn execute_with_debug_buffer( &self, ) -> Result<(StackOutputs, String), ExecutionError>
Compiles the test’s source to a Program and executes it with the tests inputs. Returns
the StackOutputs and a String containing all debug output.
If the execution fails, the output is printed stderr.
Sourcepub fn prove_and_verify(&self, pub_inputs: Vec<u64>, test_fail: bool)
pub fn prove_and_verify(&self, pub_inputs: Vec<u64>, test_fail: bool)
Compiles the test’s code into a program, then generates and verifies a STARK proof of
execution. When test_fail is true, forces a failure by modifying the first output.
Prefer check_constraints for constraint validation — it is
much faster and provides better error diagnostics. Use this method only when you need to
exercise the full STARK prove/verify pipeline (e.g., testing proof serialization,
verifier logic, or precompile request handling).
Sourcepub fn check_constraints(&self)
pub fn check_constraints(&self)
Executes the test program and checks all AIR constraints without generating a STARK proof.
This is the recommended way to validate constraints in tests. It delegates to
ExecutionTrace::check_constraints, which is much faster than the
full prove/verify pipeline and provides better error diagnostics. Use
prove_and_verify only when you need to exercise the
complete STARK proof generation and verification flow.
§Panics
Panics if execution fails or if any AIR constraint evaluates to nonzero on any row.
Sourcepub fn get_last_stack_state(&self) -> StackOutputs
pub fn get_last_stack_state(&self) -> StackOutputs
Returns the last state of the stack after executing a test.
Auto Trait Implementations§
impl Freeze for Test
impl !RefUnwindSafe for Test
impl Send for Test
impl Sync for Test
impl Unpin for Test
impl UnsafeUnpin for Test
impl !UnwindSafe for Test
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more§fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);