Struct fuchsia_fuzzctl_test::Test
source · 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.