pub struct Setup<'paths> { /* private fields */ }
Expand description
A builder to configure desired test data paths.
This is created through setup!
instead of a usual method as it must gather some information
from the callers environment first.
This is a builder and after configuration, its Setup::build()
method should be called. Note
the lifetime on this struct. This is either the lifetime of paths borrowed from the caller,
which it will rewrite, or it can be 'static
when it owns all of the paths. The latter case
requires them to be registered with Setup::add()
.
On a VCS copy of the surrounding package this will simply collect and validate the information, canonicalizing paths to be interpreted from the Manifest in the process.
However, when executed in the source tree from .crate
then it will rewrite them all to refer
to a local copy of the data instead. That is, if it is allowed to, since by default we merely
provide a detailed report of data paths, repository location, and commit information that would
need to be fetched before aborting. When the environment has opted into our access of network
(and might have overridden the repository path) then we will perform the actual access,
checkout, and rewrite.
Implementations§
Source§impl<'lt> Setup<'lt>
impl<'lt> Setup<'lt>
Sourcepub fn rewrite(self, iter: impl IntoIterator<Item = &'lt mut PathBuf>) -> Self
pub fn rewrite(self, iter: impl IntoIterator<Item = &'lt mut PathBuf>) -> Self
Register some paths to rewrite their location.
The paths should be relative to the crate’s manifest. For example, to refer to data in your
tests
directory you would use PathBuf::from("tests/data.zip")
.
The paths will be registered internally. If the repository is local they will be rewritten to be relative to the manifest location. If the repository is a crate distribution then the paths will be sparsely checked out (meaning: only that path will be downloaded from the VCS working dir and you can’t expect any other files to be present).
Those actions will happen when you call Setup::build()
.
§Example
use std::path::PathBuf;
use xtest_data::setup;
let mut path = PathBuf::from("tests/data.zip");
setup!().rewrite([&mut path]).build();
assert!(path.exists(), "{}", path.display());
Sourcepub fn add(&mut self, path: impl AsRef<Path>) -> Files
pub fn add(&mut self, path: impl AsRef<Path>) -> Files
Register the path of a file or a tree of files.
The return value is a key that can later be used in FsData
. All the files under this
location will be checked out when Setup::build()
is called in a crate-build.
§Example
let mut vcs = xtest_data::setup!();
let datazip = vcs.add("tests/data.zip");
let testdata = vcs.build();
let path = testdata.path(&datazip);
assert!(path.exists(), "{}", path.display());
Sourcepub fn build(self) -> FsData
pub fn build(self) -> FsData
Run the final validation and perform rewrites.
Returns the frozen dictionary of file mappings that had been registered with
Setup::add()
. This allows retrieving the final data paths for those items.
§Panics
This will panic if:
- Any registered file or tree is not tracked in the VCS.
- You have not allowed retrieving data from the VCS.
- It was not possible to retrieve the data from the VCS.