Use doc-comment crate to run readme doctests#48
Conversation
|
I think this is broken as written. The doctests in the readme don't appear to be running, I think because they have #[test] annotations, and the doctest wrapper itself has a #[test] annotation, so they're being nested. Taking a look now. |
|
Fixed, I think. I removed |
|
@thequux Ping! |
|
Hey @casey I tested a few things based on your commit and realized we might miss some changes in here:
Applying those changes could look like: diff --git a/Cargo.toml b/Cargo.toml
index 185cd7c..0b87f18 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,9 +35,10 @@ codegen-units = 1
failure = { version = "^0.1.3", default_features = false, features = ["derive"] }
serde_ = { version = "^1.0" , optional = true, package = "serde" }
serde_bytes = { version = "^0.11.3", optional = true }
+rustversion = "^1.0"
[dev-dependencies]
-doc-comment = "0.3.3"
+doc-comment = "^0.3.3"
regex = "^1.0"
serde_derive = "^1.0"
diff --git a/README.md b/README.md
index 8b81491..b2a0381 100644
--- a/README.md
+++ b/README.md
@@ -558,6 +558,9 @@ respectively:
```rust
+# #[cfg(feature = "serde")]
+# mod feature_capsule {
+#
use serde_derive::{Deserialize, Serialize};
#[serde(crate = "serde_")]
@@ -566,17 +569,20 @@ struct Foo {
bar: String,
}
-let value = Foo {
- bar: "hello".into(),
-};
+fn main() -> Result<(), bendy::serde::Error> {
+ let value = Foo {
+ bar: "hello".into(),
+ };
-let bencode = bendy::serde::to_bytes(&value)?;
-assert_eq!(bencode, b"d3:bar5:helloe");
+ let bencode = bendy::serde::to_bytes(&value)?;
+ assert_eq!(bencode, b"d3:bar5:helloe");
-let deserialized = bendy::serde::from_bytes::<Foo>(&bencode)?;
-assert_eq!(deserialized, value);
+ let deserialized = bendy::serde::from_bytes::<Foo>(&bencode)?;
+ assert_eq!(deserialized, value);
-Ok::<(), bendy::serde::Error>(())
+ Ok(())
+}
+# }
```
Information on how Rust types are represented in bencode is available in the
diff --git a/src/lib.rs b/src/lib.rs
index 22a9c7b..0c68802 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -22,5 +22,10 @@ pub mod serde;
pub mod value;
-#[cfg(doctest)]
-doc_comment::doctest!("../README.md");
+// -----------------------------------------------------------------------------
+
+#[rustversion::since(1.40)]
+const _ : () = {
+ #[cfg(doctest)]
+ doc_comment::doctest!("../README.md");
+};Next to this there are also two potentially intersting future features of rustc:
|
|
@0ndorio Sounds good, and thanks for writing the diff out. I used a module instead of |
|
There's a formatting error on CI that I don't understand: But the version required in rustfmt.toml is 1.4.11. |
Thats fine. Based on my initial tests I thought its not going to work with a module but it seems like this was a mistake. The module based version is way better 👍
It seems like the CI for a merge request is not only based on the incoming branch but on the expected merge, as |
1c42847 to
fdd61fb
Compare
|
I just checked the logs and it seems like there is still an issue with the Based on some quick tests with different compiler versions it looks like:
Further:
|
Delete `tests/readme.rs` in favor of using the `doc-comment` crate to run the doctests in README.md directly.
fdd61fb to
d576851
Compare
|
There are a few separate issues that I encountered:
|
|
I think failure of the |
|
Yeah the failure in |
|
Well, CI blew up completely on this one, but that's entirely clippy issues unrelated to this PR. I'll merge this, then fix them up in a separate PR. |
Delete
tests/readme.rsin favor of using thedoc-commentcrate torun the doctests in README.md directly.
I noticed #24, and it seems that
cfg(doctest)is now stable, so Ithought I'd go ahead and implement it.