Skip to content

Commit

Permalink
fix include_dir invocations
Browse files Browse the repository at this point in the history
Must pass in `$CARGO_MANIFEST_DIR`.
  • Loading branch information
sunshowers committed Dec 26, 2024
1 parent 192e0d9 commit 6b6229a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.3.1] - 2024-12-25

### Fixed

Fixed documentation for `include_dir` invocations. They must typically be called
via `include_dir!("$CARGO_MANIFEST_DIR/path/to/data")`.

## [0.3.0] - 2024-12-24

### Added
Expand Down Expand Up @@ -62,6 +69,7 @@ Previously, the test functions supported were `fn(&Path) -> Result<()>` and `fn(
- Switched to the `fancy-regex` crate, which allows for matching against regexes with
lookahead/behind and backreferences. Thanks [@webbdays](https://github.com/webbdays) for your
first contribution!

- MSRV updated to Rust 1.66.

## [0.2.6] - 2024-04-09
Expand Down Expand Up @@ -143,6 +151,7 @@ There are no functional changes in this release.

(Version 0.1.0 was yanked because of a metadata issue.)

[0.3.1]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.3.1
[0.3.0]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.3.0
[0.2.10]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.2.10
[0.2.9]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.2.9
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ You can also use directories published as `static` items in upstream crates:
use datatest_stable::{include_dir, Utf8Path};

// In the upstream crate:
pub static FIXTURES: include_dir::Dir<'static> = include_dir!("tests/files");
pub static FIXTURES: include_dir::Dir<'static> =
include_dir!("$CARGO_MANIFEST_DIR/tests/files");

// In your test:
fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
Expand Down Expand Up @@ -190,7 +191,8 @@ use datatest_stable::Utf8Path;

static FIXTURES: &str = "tests/files";

static FIXTURES: include_dir::Dir<'static> = datatest_stable::include_dir!("tests/files");
static FIXTURES: include_dir::Dir<'static> =
datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files");

fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
// ... write test here
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
//! use datatest_stable::{include_dir, Utf8Path};
//!
//! // In the upstream crate:
//! pub static FIXTURES: include_dir::Dir<'static> = include_dir!("tests/files");
//! pub static FIXTURES: include_dir::Dir<'static> =
//! include_dir!("$CARGO_MANIFEST_DIR/tests/files");
//!
//! // In your test:
//! fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
Expand Down Expand Up @@ -189,7 +190,8 @@
//! static FIXTURES: &str = "tests/files";
//!
//! #[cfg(not(feature = "testing"))]
//! static FIXTURES: include_dir::Dir<'static> = datatest_stable::include_dir!("tests/files");
//! static FIXTURES: include_dir::Dir<'static> =
//! datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files");
//!
//! fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
//! // ... write test here
Expand Down
4 changes: 2 additions & 2 deletions tests/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ mod with_contents {
/// Returns an `include_dir::Dir` instance.
macro_rules! maybe_include_dir {
() => {
include_dir::include_dir!("tests/files")
include_dir::include_dir!("$CARGO_MANIFEST_DIR/tests/files")
};
}

/// A `&'static include_dir::Dir` instance.
pub(crate) static MAYBE_INCLUDE_STATIC: include_dir::Dir =
include_dir::include_dir!("tests/files");
include_dir::include_dir!("$CARGO_MANIFEST_DIR/tests/files");

pub(crate) fn test_artifact_string(path: &Path, contents: String) -> Result<()> {
compare_contents(path, contents.as_bytes())
Expand Down

0 comments on commit 6b6229a

Please sign in to comment.