pub struct Assert<'a> { /* private fields */ }
Expand description
Environment in which to run assertion tests.
Implementations§
source§impl<'a> Assert<'a>
impl<'a> Assert<'a>
Construction and state management.
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new assert object, which will by default use
Dialect::Extended
and all library extensions,
plus some additional global functions like assert_eq
.
The usual pattern is to create a mut
Assert
, modify some properties
and then execute some tests.
sourcepub fn disable_gc(&mut self)
pub fn disable_gc(&mut self)
Disable garbage collection on the tests.
sourcepub fn setup_eval(&mut self, setup: impl Fn(&mut Evaluator<'_, '_>) + 'static)
pub fn setup_eval(&mut self, setup: impl Fn(&mut Evaluator<'_, '_>) + 'static)
Configure a callback which is used to setup evaluator before each evaluation.
sourcepub fn set_print_handler(&mut self, handler: &'a (dyn PrintHandler + 'a))
pub fn set_print_handler(&mut self, handler: &'a (dyn PrintHandler + 'a))
Configure the handler for print
function.
sourcepub fn disable_static_typechecking(&mut self)
pub fn disable_static_typechecking(&mut self)
Disable static typechecking for test. It is off by default in Evaluator
,
but on by default in Assert
.
sourcepub fn dialect_set(&mut self, f: impl FnOnce(&mut Dialect))
pub fn dialect_set(&mut self, f: impl FnOnce(&mut Dialect))
Set specific fields in the Dialect
that future tests will use.
sourcepub fn module_add(&mut self, name: &str, module: FrozenModule)
pub fn module_add(&mut self, name: &str, module: FrozenModule)
Add a FrozenModule
to the environment that future tests can access via
load
. To construct the FrozenModule
automatically use module
.
sourcepub fn module(&mut self, name: &str, program: &str) -> FrozenModule
pub fn module(&mut self, name: &str, program: &str) -> FrozenModule
Add a module to the environment that future tests can access.
let mut a = Assert::new();
a.module("hello.star", "hello = 'world'");
a.is_true("load('hello.star', 'hello'); hello == 'world'");
sourcepub fn globals_add(&mut self, f: impl FnOnce(&mut GlobalsBuilder))
pub fn globals_add(&mut self, f: impl FnOnce(&mut GlobalsBuilder))
Modify the Globals
that future tests have access to.
Note that this method will start from the default environment for Assert
,
ignoring any previous globals
or globals_add
calls.
source§impl<'a> Assert<'a>
impl<'a> Assert<'a>
Execution tests.
sourcepub fn fail(&self, program: &str, msg: &str) -> Error
pub fn fail(&self, program: &str, msg: &str) -> Error
A program that must fail with an error message that contains a specific
string. Remember that the purpose of fail
is to ensure you get
the right error, not to fully specify the error - usually only one or
two words will be sufficient to ensure that.
Assert::new().fail("fail('hello')", "ello");
sourcepub fn fails(&self, program: &str, msgs: &[&str]) -> Error
pub fn fails(&self, program: &str, msgs: &[&str]) -> Error
A program that must fail with an error message that contains a specific
set of strings. Remember that the purpose of fail
is to ensure you get
the right error, not to fully specify the error - usually only one or
two words will be sufficient to ensure that. The words do not have to be
in order.
Assert::new().fails("fail('hello')", &["fail", "ello"]);
sourcepub fn pass(&self, program: &str) -> OwnedFrozenValue
pub fn pass(&self, program: &str) -> OwnedFrozenValue
A program that must execute successfully without an exception. Often uses assert_eq. Returns the resulting value.
Assert::new().pass("assert_eq(1, 1)");
sourcepub fn pass_module(&self, program: &str) -> FrozenModule
pub fn pass_module(&self, program: &str) -> FrozenModule
A program that must execute successfully without an exception. Returns the frozen module
that program
was evaluated in.
sourcepub fn is_true(&self, program: &str)
pub fn is_true(&self, program: &str)
A program that must evaluate to True
.
Assert::new().is_true(
r#"
x = 1 + 1
x == 2
"#,
);
source§impl<'a> Assert<'a>
impl<'a> Assert<'a>
sourcepub fn conformance(&self, code: &str)
pub fn conformance(&self, code: &str)
Run a conformance test, e.g. the Go Starlark tests
sourcepub fn conformance_except(&self, code: &str, except: &[&str])
pub fn conformance_except(&self, code: &str, except: &[&str])
Run a conformance test, but where some test cases are allowed to fail.
The except
argument represents a list of these permissible failures,
in the order they occur in the conformance test set,
identified by a substring that occurs in the test.