Skip to main content

TestSession

Struct TestSession 

Source
pub struct TestSession { /* private fields */ }
Expand description

One checker for a whole run: every test file gets its own fresh program state (globals, package.loaded, module state), but modules are type-checked and generated once and served to every file from the checker’s store.

Implementations§

Source§

impl TestSession

Source

pub fn new( lint_spec: Option<&str>, lib: &str, filter: Option<&str>, opts: RunOptions, ) -> Result<Self>

Build the one checker a run shares. lint_spec is the same --lint string the CLI takes and is applied once here; lib is the module a test file requires for its assertions (DEFAULT_LIB unless the caller has its own); filter and opts are handed to that library’s run for every file.

Source

pub fn checker(&self) -> &Htl

The session’s checker (for Htl::executable_ranges on the sources a run touched).

Source

pub fn run_file(&self, path: &Path) -> Result<FileReport>

Run one file in a fresh program state borrowing the session’s checker. The checker’s search path is restored afterwards so files do not see each other’s directories.

Source

pub fn run_file_with( &self, path: &Path, generated: Option<(&str, &CheckInfo)>, preload: &[(String, String, PathBuf)], ) -> Result<(FileReport, Option<String>)>

Run one file, reusing Lua the caller generated earlier.

generated is (the Lua, what checking it reported). Everything before the codegen still happens — the searcher, the search path, the project and the config all have to be in place before the code can execute — and everything after it happens as usual. Only the check and the codegen are skipped.

The run itself is never reused, and this signature cannot express reusing it: a test has to run to say whether it passes.

Returns the report and, when this call generated the Lua rather than being handed it, that Lua — so a caller keeping a cache has something to keep. preload is (module name, its generated Lua, the file it came from) for modules this file will require. Each one goes in front of the searcher, so requiring it does not check and generate it during the run. A module not in the list still loads the usual way; the list is an optimisation, never a restriction on what can be required.

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T

Source§

impl<T> MaybeSync for T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.