From afe5eb3af66eedbc84032a07a1bd00c05ed266d7 Mon Sep 17 00:00:00 2001 From: Rain Date: Thu, 26 Dec 2024 04:37:23 +0000 Subject: [PATCH] fix README.md cargo sync-rdme seems to eat lines that begin with `#` even if they're `cfg()`, which seems incorrect. This is a good workaround for now. --- README.md | 16 +++++++++++----- src/lib.rs | 18 +++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 59ee6f6c1..37685fd0a 100644 --- a/README.md +++ b/README.md @@ -189,18 +189,24 @@ case, you can use: ````rust use datatest_stable::Utf8Path; -static FIXTURES: &str = "tests/files"; - -static FIXTURES: include_dir::Dir<'static> = - datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files"); +// In the library itself: +pub mod fixtures { + #[cfg(feature = "testing")] + pub static FIXTURES: &str = "tests/files"; + + #[cfg(not(feature = "testing"))] + pub static FIXTURES: include_dir::Dir<'static> = + datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files"); +} +// In the test: fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> { // ... write test here Ok(()) } datatest_stable::harness! { - { test = my_test, root = &FIXTURES, pattern = r"^.*/*" }, + { test = my_test, root = &fixtures::FIXTURES, pattern = r"^.*/*" }, } ```` diff --git a/src/lib.rs b/src/lib.rs index be444a6ba..cd2f67140 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -186,20 +186,24 @@ #![cfg_attr(not(feature = "include-dir"), doc = "```rust,ignore")] //! use datatest_stable::Utf8Path; //! -//! #[cfg(feature = "testing")] -//! static FIXTURES: &str = "tests/files"; -//! -//! #[cfg(not(feature = "testing"))] -//! static FIXTURES: include_dir::Dir<'static> = -//! datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files"); +//! // In the library itself: +//! pub mod fixtures { +//! #[cfg(feature = "testing")] +//! pub static FIXTURES: &str = "tests/files"; +//! +//! #[cfg(not(feature = "testing"))] +//! pub static FIXTURES: include_dir::Dir<'static> = +//! datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files"); +//! } //! +//! // In the test: //! fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> { //! // ... write test here //! Ok(()) //! } //! //! datatest_stable::harness! { -//! { test = my_test, root = &FIXTURES, pattern = r"^.*/*" }, +//! { test = my_test, root = &fixtures::FIXTURES, pattern = r"^.*/*" }, //! } //! ``` //!