Expand description
Fetch test data in packaged crate tests.
§For crate authors
Drop these lines into your integration tests (due to a limitation in cargo
this will only
work in integration tests right now¹). Note that this requires your repository—through the URL
contained in Cargo.toml
—to be readable by the environment where you wish to test the packaged
crate.
use std::path::PathBuf;
// or any other file you want to use.
let mut datazip = PathBuf::from("tests/data.zip");
xtest_data::setup!().rewrite([&mut datazip]).build();
// … and the crate works its magic to make this succeed.
assert!(datazip.exists(), "{}", datazip.display());
§For packagers
The .crate
file you have downloaded is a .tar.gz
in disguise. When you unpack it for your
local build steps etc., verify that this package contains Cargo.toml.orig
as well as a
.cargo_vcs_info.json
file; and that the latter file has git commit information.
Then you can then run the tests:
cargo test -- --nocapture
Don’t worry, this won’t access the network yet. In the first step it will only verify the basic installation. It will then panic while printing information on what it would have done and instructions on how to proceed. You can opt into allow network access by default with:
CARGO_XTEST_DATA_FETCH=yes cargo test -- --nocapture
¹We need a place to store a shallow clone of the crate’s source repository.
Macros§
- Create a builder to configure local test data.
Structs§
- A file or tree that was registered from
Setup
. - The product of
Setup
, ensuring local file system accessible test resources. - A builder to configure desired test data paths.