rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.8k stars 2.43k forks source link

`cargo test` tries to run doc tests from markdown indented code blocks #14627

Closed maia-s closed 1 month ago

maia-s commented 1 month ago

Problem

I'm making a bindings generator that among other things translates comments from C headers to rust. The comments are partially in markdown format, and sometimes include indented code blocks (i.e. without ```). cargo test tries to compile and run these as if they were Rust code. There's no way for me to tell cargo that an indented block isn't Rust code without transforming it into a ``` block. The rustdoc docs makes no mention of indented code blocks, so this seems unintentional.

Steps

  1. Write a doc comment with an indented code block (four spaces +)
  2. cargo test will try to run it as if it was Rust code

Possible Solution(s)

cargo test shouldn't interpret indented code blocks as Rust code

Notes

No response

Version

cargo 1.81.0 (2dbb1af80 2024-08-20) release: 1.81.0 commit-hash: 2dbb1af80a2914475ba76827a312e29cedfa6b2f commit-date: 2024-08-20 host: aarch64-apple-darwin libgit2: 1.8.1 (sys:0.19.0 vendored) libcurl: 8.7.1 (sys:0.4.73+curl-8.8.0 system ssl:(SecureTransport) LibreSSL/3.3.6) ssl: OpenSSL 1.1.1w 11 Sep 2023 os: Mac OS 15.0.0 [64-bit]

cargo 1.83.0-nightly (c1fa840a8 2024-08-29) release: 1.83.0-nightly commit-hash: c1fa840a85eca53818895901a53fae34247448b2 commit-date: 2024-08-29 host: aarch64-apple-darwin libgit2: 1.8.1 (sys:0.19.0 vendored) libcurl: 8.7.1 (sys:0.4.74+curl-8.9.0 system ssl:(SecureTransport) LibreSSL/3.3.6) ssl: OpenSSL 1.1.1w 11 Sep 2023 os: Mac OS 15.0.0 [64-bit]

weihanglo commented 1 month ago

It is mentioned in https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#syntax-reference. Please see other previous closed issues. Thank you.

weihanglo commented 1 month ago

Going to link to more relevant issues and close this one. Thanks for the report.