Skip to content

Commit afe5eb3

Browse files
committed
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.
1 parent 6b6229a commit afe5eb3

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,24 @@ case, you can use:
189189
````rust
190190
use datatest_stable::Utf8Path;
191191

192-
static FIXTURES: &str = "tests/files";
193-
194-
static FIXTURES: include_dir::Dir<'static> =
195-
datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files");
192+
// In the library itself:
193+
pub mod fixtures {
194+
#[cfg(feature = "testing")]
195+
pub static FIXTURES: &str = "tests/files";
196+
197+
#[cfg(not(feature = "testing"))]
198+
pub static FIXTURES: include_dir::Dir<'static> =
199+
datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files");
200+
}
196201

202+
// In the test:
197203
fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
198204
// ... write test here
199205
Ok(())
200206
}
201207

202208
datatest_stable::harness! {
203-
{ test = my_test, root = &FIXTURES, pattern = r"^.*/*" },
209+
{ test = my_test, root = &fixtures::FIXTURES, pattern = r"^.*/*" },
204210
}
205211
````
206212

src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,24 @@
186186
#![cfg_attr(not(feature = "include-dir"), doc = "```rust,ignore")]
187187
//! use datatest_stable::Utf8Path;
188188
//!
189-
//! #[cfg(feature = "testing")]
190-
//! static FIXTURES: &str = "tests/files";
191-
//!
192-
//! #[cfg(not(feature = "testing"))]
193-
//! static FIXTURES: include_dir::Dir<'static> =
194-
//! datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files");
189+
//! // In the library itself:
190+
//! pub mod fixtures {
191+
//! #[cfg(feature = "testing")]
192+
//! pub static FIXTURES: &str = "tests/files";
193+
//!
194+
//! #[cfg(not(feature = "testing"))]
195+
//! pub static FIXTURES: include_dir::Dir<'static> =
196+
//! datatest_stable::include_dir!("$CARGO_MANIFEST_DIR/tests/files");
197+
//! }
195198
//!
199+
//! // In the test:
196200
//! fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
197201
//! // ... write test here
198202
//! Ok(())
199203
//! }
200204
//!
201205
//! datatest_stable::harness! {
202-
//! { test = my_test, root = &FIXTURES, pattern = r"^.*/*" },
206+
//! { test = my_test, root = &fixtures::FIXTURES, pattern = r"^.*/*" },
203207
//! }
204208
//! ```
205209
//!

0 commit comments

Comments
 (0)