Skip to content

Commit

Permalink
Add regression test for doc_include_without_cfg lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Oct 29, 2024
1 parent ffbed4d commit 43466bb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/ui/doc/doc_include_without_cfg.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![warn(clippy::doc_include_without_cfg)]
// Should not lint.
#![doc(html_playground_url = "https://playground.example.com/")]
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg
// Should not lint.
#![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
#![doc = "some doc"]
//! more doc

#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg
// Should not lint.
#[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
#[doc = "some doc"]
/// more doc
fn main() {
// test code goes here
}
19 changes: 19 additions & 0 deletions tests/ui/doc/doc_include_without_cfg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![warn(clippy::doc_include_without_cfg)]
// Should not lint.
#![doc(html_playground_url = "https://playground.example.com/")]
#![doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg
// Should not lint.
#![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
#![doc = "some doc"]
//! more doc

#[doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg
// Should not lint.
#[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))]
#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]
#[doc = "some doc"]
/// more doc
fn main() {
// test code goes here
}
17 changes: 17 additions & 0 deletions tests/ui/doc/doc_include_without_cfg.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: included a file in documentation unconditionally
--> tests/ui/doc/doc_include_without_cfg.rs:4:1
|
LL | #![doc = include_str!("../approx_const.rs")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))]`
|
= note: `-D clippy::doc-include-without-cfg` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::doc_include_without_cfg)]`

error: included a file in documentation unconditionally
--> tests/ui/doc/doc_include_without_cfg.rs:11:1
|
LL | #[doc = include_str!("../approx_const.rs")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]`

error: aborting due to 2 previous errors

1 change: 1 addition & 0 deletions tests/ui/missing_doc_crate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![warn(clippy::missing_docs_in_private_items)]
#![allow(clippy::doc_include_without_cfg)]
#![doc = include_str!("../../README.md")]

fn main() {}

0 comments on commit 43466bb

Please sign in to comment.