pub struct TestEnv { /* private fields */ }
Expand description

A test environment, which is essentially a wrapper around some directory, with some utility functions operating relative to that directory.

Implementations§

source§

impl TestEnv

source

pub fn new(current_dir: &str) -> Option<Self>

source

pub fn push(&self, child: &str) -> Option<Self>

source

pub fn current_dir(&self) -> &str

source

pub fn clear_log(&self) -> Option<()>

source

pub fn logln(&self, msg: &str) -> Option<()>

source

pub fn logln_to(&self, msg: &str, rel_path: impl AsRef<Path>) -> Option<()>

source

pub fn read_file(&self, rel_path: impl AsRef<Path>) -> Option<String>

Read a file from a path relative to the environment current dir into a string

source

pub fn write_file( &self, rel_path: impl AsRef<Path>, contents: &str ) -> Option<()>

Write a file to a path relative to the environment current dir

source

pub fn parse_file<T: DeserializeOwned>( &self, rel_path: impl AsRef<Path> ) -> Option<T>

Parse a file from a path relative to the environment current dir as the given type

source

pub fn copy_file_from(&self, path: impl AsRef<Path>) -> Option<()>

Copy a file from the path outside environment into the environment current dir Returns None if copying was not successful

source

pub fn copy_file_from_as( &self, path: impl AsRef<Path>, new_name: &str ) -> Option<()>

Copy a file from the path outside environment into the environment current dir Assigns the file a new_name in the current environment Returns None if copying was not successful

source

pub fn copy_file_from_env( &self, other: &TestEnv, path: impl AsRef<Path> ) -> Option<()>

Copy a file from the path relative to the other environment into the environment current dir Returns None if copying was not successful

source

pub fn copy_file_from_env_as( &self, other: &TestEnv, path: impl AsRef<Path>, new_name: &str ) -> Option<()>

Copy a file from the path relative to the other environment into the environment current dir Assigns the file a new_name in the current environment Returns None if copying was not successful

source

pub fn remove_file(&self, rel_path: impl AsRef<Path>) -> Option<()>

Remove a file from a path relative to the environment current dir

source

pub fn full_path(&self, rel_path: impl AsRef<Path>) -> PathBuf

Convert a relative path to the full path from the test root Return None if the full path can’t be formed

source

pub fn rel_path(&self, full_path: impl AsRef<Path>) -> Option<String>

Convert a full path to the path relative to the test root Returns None if the full path doesn’t contain test root as prefix

source

pub fn full_canonical_path(&self, rel_path: impl AsRef<Path>) -> Option<String>

Convert a relative path to the full path from the test root, canonicalized Returns None the full path can’t be formed

Trait Implementations§

source§

impl Clone for TestEnv

source§

fn clone(&self) -> TestEnv

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TestEnv

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.