Struct InMemoryFileSystem

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

In-memory filesystem for use in unit tests.

This type mocks out the file system operations in the VM. It provides an in-memory system to which “files” can be added before the test runs. It is designed to help test primitives that interact with the filesystem.

Given a VM, the file system can be set as follows:

let mut vm = vm::VM::<State>::new(
    Default::default(),  // initial commands
);
let mock_file_system: InMemoryFileSystem = Default::default();
vm.file_system = Box::new(mock_file_system);

When using the test runners in this module or the test_suite macro, assign the file system ops using the TestOption::CustomVMInitializationDyn option:

let options = TestOption::CustomVMInitializationDyn(Box::new(|vm: &mut vm::VM<State>|{
    let mock_file_system: InMemoryFileSystem = Default::default();
    vm.file_system = Box::new(mock_file_system);
}));

Implementations§

Source§

impl InMemoryFileSystem

Source

pub fn add_file(&mut self, path: PathBuf, content: &str)

Add a file to the in-memory file system.

Trait Implementations§

Source§

impl Default for InMemoryFileSystem

Source§

fn default() -> InMemoryFileSystem

Returns the “default value” for a type. Read more
Source§

impl FileSystem for InMemoryFileSystem

Source§

fn read_to_string(&self, path: &Path) -> Result<String>

Read the entire contents of a file into a string. Read more
Source§

fn write_bytes(&self, _: &Path, _: &[u8]) -> Result<()>

Write a slice of bytes to a file. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

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.