From b840cfd0ea4c8c96517c31e990a89990d2768cd4 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sat, 12 Feb 2022 17:00:04 +0000 Subject: [PATCH 1/4] Document feature flags better --- Cargo.lock | 7 +++++++ serial_test/Cargo.toml | 8 +++++++- serial_test/src/lib.rs | 3 +++ serial_test_derive/src/lib.rs | 3 +++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4a40d90..f3b22ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,6 +111,12 @@ dependencies = [ "syn", ] +[[package]] +name = "document-features" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b01c09fd63b5136fba41aa625c7b3254f0aa0a435ff6ec4b2c9a28d496c83c88" + [[package]] name = "env_logger" version = "0.7.1" @@ -509,6 +515,7 @@ dependencies = [ name = "serial_test" version = "0.5.1" dependencies = [ + "document-features", "fslock", "lazy_static", "parking_lot", diff --git a/serial_test/Cargo.toml b/serial_test/Cargo.toml index e217772..2ccf435 100644 --- a/serial_test/Cargo.toml +++ b/serial_test/Cargo.toml @@ -15,10 +15,16 @@ lazy_static = "1.2" parking_lot = ">= 0.10, < 0.12" serial_test_derive = { version = "~0.5.1", path = "../serial_test_derive" } fslock = {version = "0.2", optional = true} +document-features = "0.2" [features] default = [] + +## The file_locks feature unlocks the `file_serial` macro file_locks = ["fslock"] +# docs.rs-specific configuration [package.metadata.docs.rs] -all-features = true \ No newline at end of file +all-features = true +# defines the configuration attribute `docsrs` +rustdoc-args = ["--cfg", "docsrs"] \ No newline at end of file diff --git a/serial_test/src/lib.rs b/serial_test/src/lib.rs index b3b6f7c..943408f 100644 --- a/serial_test/src/lib.rs +++ b/serial_test/src/lib.rs @@ -30,6 +30,9 @@ //! // Do things //! } //! ```` +//! +//! ## Feature flags +#![doc = document_features::document_features!()] mod code_lock; #[cfg(feature = "file_locks")] diff --git a/serial_test_derive/src/lib.rs b/serial_test_derive/src/lib.rs index f3a2076..3e827cb 100644 --- a/serial_test_derive/src/lib.rs +++ b/serial_test_derive/src/lib.rs @@ -1,6 +1,8 @@ //! # serial_test_derive //! Helper crate for [serial_test](../serial_test/index.html) +#![cfg_attr(docsrs, feature(doc_cfg))] + extern crate proc_macro; use proc_macro::TokenStream; @@ -99,6 +101,7 @@ pub fn serial(attr: TokenStream, input: TokenStream) -> TokenStream { /// Note that in this case you need to specify the `name` arg as well (as per [serial](macro@serial)). The path defaults to a reasonable temp directory for the OS if not specified. #[proc_macro_attribute] #[proc_macro_error] +#[cfg_attr(docsrs, doc(cfg(feature = "file_locks")))] pub fn file_serial(attr: TokenStream, input: TokenStream) -> TokenStream { fs_serial_core(attr.into(), input.into()).into() } From b981a9a6922fb4b054ae213f382f5db9f1344e07 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sat, 12 Feb 2022 18:26:17 +0000 Subject: [PATCH 2/4] Run the document-features only on docsrs --- serial_test/Cargo.toml | 4 +++- serial_test/src/lib.rs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/serial_test/Cargo.toml b/serial_test/Cargo.toml index 2ccf435..11e43b3 100644 --- a/serial_test/Cargo.toml +++ b/serial_test/Cargo.toml @@ -15,7 +15,7 @@ lazy_static = "1.2" parking_lot = ">= 0.10, < 0.12" serial_test_derive = { version = "~0.5.1", path = "../serial_test_derive" } fslock = {version = "0.2", optional = true} -document-features = "0.2" +document-features = {version = "0.2", optional=true} [features] default = [] @@ -23,6 +23,8 @@ default = [] ## The file_locks feature unlocks the `file_serial` macro file_locks = ["fslock"] +docsrs = ["document-features"] + # docs.rs-specific configuration [package.metadata.docs.rs] all-features = true diff --git a/serial_test/src/lib.rs b/serial_test/src/lib.rs index 943408f..e83eec0 100644 --- a/serial_test/src/lib.rs +++ b/serial_test/src/lib.rs @@ -32,7 +32,10 @@ //! ```` //! //! ## Feature flags -#![doc = document_features::document_features!()] +#![cfg_attr( + feature = "docsrs", + cfg_attr(doc, doc = ::document_features::document_features!()) +)] mod code_lock; #[cfg(feature = "file_locks")] From 85222c62d70d16c05d40a2a9d08b5a5a3df91b30 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sat, 12 Feb 2022 18:30:10 +0000 Subject: [PATCH 3/4] Add all feature testing --- .github/workflows/ci.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f64d785..0de2a78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,7 @@ jobs: features: - default - file_locks + - all steps: - uses: actions/checkout@v2.3.4 - uses: actions-rs/toolchain@v1.0.7 @@ -45,11 +46,18 @@ jobs: command: clippy if: ${{ matrix.features == 'default' }} continue-on-error: ${{ matrix.rust == 'nightly' || matrix.rust == 'beta' }} - - name: Build and test + - name: Build and test feature ${{ matrix.features }} uses: actions-rs/cargo@v1.0.3 with: command: test args: --features ${{ matrix.features }} + if: ${{ matrix.features != 'all' }} + - name: Build and test all features + uses: actions-rs/cargo@v1.0.3 + with: + command: test + args: --all-features + if: ${{ matrix.features == 'all' }} multi-os-testing: name: Test suite From 491026a1becde0bde41cb0a2928b46f48095794d Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sat, 12 Feb 2022 18:35:39 +0000 Subject: [PATCH 4/4] Only test "all features" on nightly --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0de2a78..f08178b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,9 @@ jobs: features: - default - file_locks - - all + include: + - rust: nightly + features: all steps: - uses: actions/checkout@v2.3.4 - uses: actions-rs/toolchain@v1.0.7 @@ -57,7 +59,7 @@ jobs: with: command: test args: --all-features - if: ${{ matrix.features == 'all' }} + if: ${{ matrix.features == 'all' }} multi-os-testing: name: Test suite