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

General purpose test context for the ffx fuzz plugin unit tests.

This object groups several commonly used routines used to capture data produced as a part of unit tests, such as:

  • It can create temporary files and directories, and ensure they persist for duration of the test.
  • It maintains a list of expected outputs.
  • It shares a list of actual outputs with a BufferSink and can verify that they match its expectations.
  • It can produce Writers backed by its associated BufferSink.

Implementations§

source§

impl Test

source

pub fn try_new() -> Result<Self>

Creates a new Test.

When running tests, users may optionally set the FFX_FUZZ_ECHO_TEST_OUTPUT environment variable, which will cause this object to use an existing directory rather than create a temporary one.

source

pub fn root_dir(&self) -> &Path

Returns the writable temporary directory for this test.

source

pub fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>

Creates a directory under this object’s root_dir.

The given path may be relative or absolute, but if it is the latter it must be prefixed with this object’s root_dir.

Returns a PathBuf on success and an error if the path is outside the root_dir or the filesystem returns an error.

source

pub fn artifact_dir(&self) -> PathBuf

Returns the path where the fuzzer will store artifacts.

source

pub fn corpus_dir(&self, corpus_type: Corpus) -> PathBuf

Returns the path where the fuzzer will store its corpus of the given type.

source

pub fn write_fx_build_dir<P: AsRef<Path>>(&self, build_dir: P) -> Result<()>

Creates a fake “.fx-build-dir” file for testing.

The “.fx-build-dir” file will be created under this object’s root_dir, and will contain the relative_path to the build directory. Except for some util::tests, unit tests should prefer create_tests_json.

Returns an error if any filesystem operations fail.

source

pub fn write_tests_json<P: AsRef<Path>, S: AsRef<str>>( &self, build_dir: P, contents: S ) -> Result<PathBuf>

Creates a fake “tests.json” file for testing.

The “tests.json” will be created under the relative_path from this object’s root_dir and will contain the given contents. Except for some util::tests, unit tests should prefer create_tests_json.

Returns an error if any filesystem operations fail.

source

pub fn create_tests_json<D: Display>( &self, urls: impl Iterator<Item = D> ) -> Result<PathBuf>

Creates a fake “tests.json” file for testing.

The “tests.json” will include an array of valid JSON objects for the given urls.

Returns an error if any filesystem operations fail.

source

pub fn create_test_files<P: AsRef<Path>, D: Display>( &self, test_dir: P, files: impl Iterator<Item = D> ) -> Result<()>

Creates several temporary files from the given iterator for testing.

Each file’s contents will simpl be its name, which is taken from the given files.

Returns an error if writing to the filesystem fails.

source

pub fn url(&self) -> Rc<RefCell<Option<String>>>

Clones the RefCell holding the URL provided to the fake manager.

source

pub fn controller(&self) -> FakeController

Clones the fake fuzzer controller “connected” by the fake manager.

source

pub fn record<S: AsRef<str>>(&mut self, request: S)

Records a FIDL request made to a test fake.

source

pub fn requests(&mut self) -> Vec<String>

Returns the recorded FIDL requests.

As a side-effect, this resets the recorded requests.

source

pub fn output_matches<T: AsRef<str> + Display>(&mut self, msg: T)

Adds an expectation that an output written to the BufferSink will exactly match msg.

source

pub fn output_includes<T: AsRef<str> + Display>(&mut self, msg: T)

Adds an expectation that an output written to the BufferSink will contain msg.

source

pub fn verify_output(&mut self) -> Result<()>

Iterates over the expected and actual output and verifies expectations are met.

source

pub fn writer(&self) -> &Writer<BufferSink>

Returns a Writer using the BufferSink associated with this object.

Trait Implementations§

source§

impl Clone for Test

source§

fn clone(&self) -> Test

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 Test

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Test

§

impl !RefUnwindSafe for Test

§

impl !Send for Test

§

impl !Sync for Test

§

impl Unpin for Test

§

impl !UnwindSafe for Test

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> Encode<Ambiguous1> for T

source§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
source§

impl<T> Encode<Ambiguous2> for T

source§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more