From fe5cea1de355dd8bef59486860e4fd68ee2c7672 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Thu, 18 Feb 2021 11:14:00 +0100 Subject: [PATCH] Add doc-comment tests --- Cargo.lock | 1 + Cargo.toml | 1 + README.md | 12 ++++++------ src/lib.rs | 8 ++++++++ tests/{readme.rs => usage.rs} | 4 ++-- 5 files changed, 18 insertions(+), 8 deletions(-) rename tests/{readme.rs => usage.rs} (95%) diff --git a/Cargo.lock b/Cargo.lock index 39b84ea..2ab6e02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1399,6 +1399,7 @@ dependencies = [ "check-if-email-exists", "deadpool", "derive_builder", + "doc-comment", "futures", "glob", "headers", diff --git a/Cargo.toml b/Cargo.toml index aeab718..3bb241c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,6 +66,7 @@ assert_cmd = "1.0.3" predicates = "1.0.7" uuid = { version = "0.8.2", features = ["v4"] } tempfile = "3.2.0" +doc-comment = "0.3.3" [features] vendored-openssl = ["openssl-sys/vendored"] diff --git a/README.md b/README.md index 3814f04..f6c53d6 100644 --- a/README.md +++ b/README.md @@ -89,13 +89,13 @@ You can run lychee directly from the commandline. #### Using cargo -``` +```sh cargo install lychee ``` #### Using the official Docker image -``` +```sh docker pull lycheeverse/lychee ``` @@ -108,13 +108,13 @@ You can download them from the [releases page](https://github.com/lycheeverse/ly Run it inside a repository with a `README.md`: -``` +```sh lychee ``` You can also specify various types of inputs: -``` +```sh # check links on a website: lychee https://endler.dev/ @@ -149,7 +149,7 @@ token with no extra permissions is enough to be able to check public repos links There is an extensive list of commandline parameters to customize the behavior, see below for a full list. -``` +```sh USAGE: lychee [FLAGS] [OPTIONS] [--] [inputs]... @@ -235,7 +235,7 @@ async fn main() -> Result<(), Box> { The client builder is very customizable: -```rust +```rust,ignore let client = lychee::ClientBuilder::default() .includes(includes) .excludes(excludes) diff --git a/src/lib.rs b/src/lib.rs index 8345d59..6cd698e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,14 @@ * } * ``` */ + +#[cfg(doctest)] +#[macro_use] +extern crate doc_comment; + +#[cfg(doctest)] +doctest!("../README.md"); + mod client; mod client_pool; mod excludes; diff --git a/tests/readme.rs b/tests/usage.rs similarity index 95% rename from tests/readme.rs rename to tests/usage.rs index 7861dc4..9455dd9 100644 --- a/tests/readme.rs +++ b/tests/usage.rs @@ -41,13 +41,13 @@ mod readme { .expect("Invalid utf8 output for `--help`"); let readme = load_readme_text(); - const BACKTICKS_OFFSET: usize = 3; + const BACKTICKS_OFFSET: usize = 5; // marker: ```sh const NEWLINE_OFFSET: usize = 1; let usage_start = BACKTICKS_OFFSET + NEWLINE_OFFSET + readme - .find("```\nUSAGE:\n") + .find("```sh\nUSAGE:\n") .expect("Couldn't find USAGE section in README.md"); let usage_end = readme[usage_start..]