diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 710eb1c..4fafac3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,11 @@ jobs: - name: Clippy run: cargo clippy --all -- -D warnings - name: Run tests + if: matrix.rust == 'stable' run: cargo test --all --verbose --features fancy + - name: Run tests + if: matrix.rust == '1.56.0' + run: cargo test --all --verbose --features fancy no-format-args-capture miri: name: Miri diff --git a/Cargo.toml b/Cargo.toml index 7615d6b..61d357a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,16 @@ lazy_static = "1.4" [features] default = [] -fancy-no-backtrace = ["owo-colors", "is-terminal", "textwrap", "terminal_size", "supports-hyperlinks", "supports-color", "supports-unicode"] +no-format-args-capture = [] +fancy-no-backtrace = [ + "owo-colors", + "is-terminal", + "textwrap", + "terminal_size", + "supports-hyperlinks", + "supports-color", + "supports-unicode", +] fancy = ["fancy-no-backtrace", "backtrace", "backtrace-ext"] [workspace] diff --git a/src/eyreish/macros.rs b/src/eyreish/macros.rs index d3abcf2..50605e7 100644 --- a/src/eyreish/macros.rs +++ b/src/eyreish/macros.rs @@ -16,7 +16,14 @@ /// # let resource = 0; /// # /// if !has_permission(user, resource) { -/// bail!("permission denied for accessing {resource}"); +#[cfg_attr( + not(feature = "no-format-args-capture"), + doc = r#" bail!("permission denied for accessing {resource}");"# +)] +#[cfg_attr( + feature = "no-format-args-capture", + doc = r#" bail!("permission denied for accessing {}", resource);"# +)] /// } /// # Ok(()) /// # } @@ -56,7 +63,14 @@ /// if y.abs() < 1e-3 { /// bail!( /// severity = Severity::Warning, -/// "dividing by value ({y}) close to 0" +#[cfg_attr( + not(feature = "no-format-args-capture"), + doc = r#" "dividing by value ({y}) close to 0""# +)] +#[cfg_attr( + feature = "no-format-args-capture", + doc = r#" "dividing by value ({}) close to 0", y"# +)] /// ); /// } /// Ok(x / y) @@ -126,7 +140,14 @@ macro_rules! bail { /// ensure!( /// y.abs() >= 1e-3, /// severity = Severity::Warning, -/// "dividing by value ({y}) close to 0" +#[cfg_attr( + not(feature = "no-format-args-capture"), + doc = r#" "dividing by value ({y}) close to 0""# +)] +#[cfg_attr( + feature = "no-format-args-capture", + doc = r#" "dividing by value ({}) close to 0", y"# +)] /// ); /// Ok(x / y) /// } @@ -156,11 +177,26 @@ macro_rules! ensure { /// # use miette::miette; /// let x = 1; /// let y = 2; -/// let report = miette!("{x} + {} = {z}", y, z = x + y); +#[cfg_attr( + not(feature = "no-format-args-capture"), + doc = r#"let report = miette!("{x} + {} = {z}", y, z = x + y);"# +)] +#[cfg_attr( + feature = "no-format-args-capture", + doc = r#"let report = miette!("{} + {} = {z}", x, y, z = x + y);"# +)] +/// /// assert_eq!(report.to_string().as_str(), "1 + 2 = 3"); /// /// let z = x + y; -/// let report = miette!("{x} + {y} = {z}"); +#[cfg_attr( + not(feature = "no-format-args-capture"), + doc = r#"let report = miette!("{x} + {y} = {z}");"# +)] +#[cfg_attr( + feature = "no-format-args-capture", + doc = r#"let report = miette!("{} + {} = {}", x, y, z);"# +)] /// assert_eq!(report.to_string().as_str(), "1 + 2 = 3"); /// ``` /// @@ -225,11 +261,25 @@ macro_rules! miette { /// let x = 1; /// let y = 2; /// -/// let diag = diagnostic!("{x} + {} = {z}", y, z = x + y); +#[cfg_attr( + not(feature = "no-format-args-capture"), + doc = r#" let diag = diagnostic!("{x} + {} = {z}", y, z = x + y);"# +)] +#[cfg_attr( + feature = "no-format-args-capture", + doc = r#" let diag = diagnostic!("{} + {} = {z}", x, y, z = x + y);"# +)] /// assert_eq!(diag.message, "1 + 2 = 3"); /// /// let z = x + y; -/// let diag = diagnostic!("{x} + {y} = {z}"); +#[cfg_attr( + not(feature = "no-format-args-capture"), + doc = r#"let diag = diagnostic!("{x} + {y} = {z}");"# +)] +#[cfg_attr( + feature = "no-format-args-capture", + doc = r#"let diag = diagnostic!("{} + {} = {}", x, y, z);"# +)] /// assert_eq!(diag.message, "1 + 2 = 3"); /// ``` #[macro_export] diff --git a/src/lib.rs b/src/lib.rs index d1fb3ea..cc113ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -599,7 +599,7 @@ //! then you may want to use [`miette!`], [`diagnostic!`] macros or //! [`MietteDiagnostic`] directly to create diagnostic on the fly. //! -//! ```rs +//! ```rust,ignore //! # use miette::{miette, LabeledSpan, Report}; //! //! let source = "2 + 2 * 2 = 8".to_string();