Struct starlark::assert::Assert

source ·
pub struct Assert<'a> { /* private fields */ }
Expand description

Environment in which to run assertion tests.

Implementations§

source§

impl<'a> Assert<'a>

Construction and state management.

source

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.

source

pub fn disable_gc(&mut self)

Disable garbage collection on the tests.

source

pub fn setup_eval(&mut self, setup: impl Fn(&mut Evaluator<'_, '_>) + 'static)

Configure a callback which is used to setup evaluator before each evaluation.

source

pub fn set_print_handler(&mut self, handler: &'a (dyn PrintHandler + 'a))

Configure the handler for print function.

source

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.

source

pub fn dialect(&mut self, x: &Dialect)

Set the Dialect that future tests will use.

source

pub fn dialect_set(&mut self, f: impl FnOnce(&mut Dialect))

Set specific fields in the Dialect that future tests will use.

source

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.

source

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'");
source

pub fn globals(&mut self, x: Globals)

Set the Globals that future tests have access to.

source

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>

Execution tests.

source

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");
source

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"]);
source

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)");
source

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.

source

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

pub fn is_false(&self, program: &str)

A program that must evaluate to False.

source

pub fn all_true(&self, program: &str)

Many lines, each of which must individually evaluate to True (or be blank lines).

Assert::new().all_true(
    r#"
1 == 1

2 == 1 + 1
"#,
);
source

pub fn eq(&self, lhs: &str, rhs: &str)

Two programs that must evaluate to the same (non-error) result.

Assert::new().eq("1 + 1", "2");
source§

impl<'a> Assert<'a>

source

pub fn conformance(&self, code: &str)

Run a conformance test, e.g. the Go Starlark tests

source

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.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Assert<'a>

§

impl<'a> !Send for Assert<'a>

§

impl<'a> !Sync for Assert<'a>

§

impl<'a> Unpin for Assert<'a>

§

impl<'a> !UnwindSafe for Assert<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToAst for T

source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.