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
Writer
s backed by its associatedBufferSink
.
Implementations§
Source§impl Test
impl Test
Sourcepub fn try_new() -> Result<Self>
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.
Sourcepub fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
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.
Sourcepub fn artifact_dir(&self) -> PathBuf
pub fn artifact_dir(&self) -> PathBuf
Returns the path where the fuzzer will store artifacts.
Sourcepub fn corpus_dir(&self, corpus_type: Corpus) -> PathBuf
pub fn corpus_dir(&self, corpus_type: Corpus) -> PathBuf
Returns the path where the fuzzer will store its corpus of the given type.
Sourcepub fn write_fx_build_dir<P: AsRef<Path>>(&self, build_dir: P) -> Result<()>
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.
Sourcepub fn write_tests_json<P: AsRef<Path>, S: AsRef<str>>(
&self,
build_dir: P,
contents: S,
) -> Result<PathBuf>
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.
Sourcepub fn create_tests_json<D: Display>(
&self,
urls: impl Iterator<Item = D>,
) -> Result<PathBuf>
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.
Sourcepub fn create_test_files<P: AsRef<Path>, D: Display>(
&self,
test_dir: P,
files: impl Iterator<Item = D>,
) -> Result<()>
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.
Sourcepub fn url(&self) -> Rc<RefCell<Option<String>>>
pub fn url(&self) -> Rc<RefCell<Option<String>>>
Clones the RefCell
holding the URL provided to the fake manager.
Sourcepub fn controller(&self) -> FakeController
pub fn controller(&self) -> FakeController
Clones the fake fuzzer controller “connected” by the fake manager.
Sourcepub fn record<S: AsRef<str>>(&mut self, request: S)
pub fn record<S: AsRef<str>>(&mut self, request: S)
Records a FIDL request made to a test fake.
Sourcepub fn requests(&mut self) -> Vec<String>
pub fn requests(&mut self) -> Vec<String>
Returns the recorded FIDL requests.
As a side-effect, this resets the recorded requests.
Sourcepub fn output_matches<T: AsRef<str> + Display>(&mut self, msg: T)
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
.
Sourcepub fn output_includes<T: AsRef<str> + Display>(&mut self, msg: T)
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
.
Sourcepub fn verify_output(&mut self) -> Result<()>
pub fn verify_output(&mut self) -> Result<()>
Iterates over the expected and actual output and verifies expectations are met.
Sourcepub fn writer(&self) -> &Writer<BufferSink>
pub fn writer(&self) -> &Writer<BufferSink>
Returns a Writer
using the BufferSink
associated with this object.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)