Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe incorrect parsing of doc tests #99041

Closed
frank-king opened this issue Jul 8, 2022 · 5 comments
Closed

Maybe incorrect parsing of doc tests #99041

frank-king opened this issue Jul 8, 2022 · 5 comments
Labels
C-bug Category: This is a bug.

Comments

@frank-king
Copy link
Contributor

frank-king commented Jul 8, 2022

Here is a fragment from some bindgen-generated code:

#[doc = "**"]
#[doc = "* <hr>"]
#[doc = "* ------------------ | -------------"]
#[doc = "*                    | Yes, "]
#[doc = "*/"]
pub struct Foo;

Playground.

I expected to see this happen: when running cargo test, there is no tests to execute.

Instead, this happened:

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 1 test
test src/lib.rs - Foo (line 4) ... FAILED

failures:

---- src/lib.rs - Foo (line 4) stdout ----
error: expected parameter name, found `}`
 --> src/lib.rs:6:1
  |
4 | } _doctest_main_src_lib_rs_4_0() }
  | ^ expected parameter name

error: aborting due to previous error

Couldn't compile the test.

failures:
    src/lib.rs - Foo (line 4)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s

Acutally, it is caused by this line,

#[doc = "*                    | Yes, "]

If removing it, then there is no doc tests.

It happens on both stable version and nightly version.

@frank-king frank-king added the C-bug Category: This is a bug. label Jul 8, 2022
@frank-king frank-king changed the title Maybe incorrenct parsing of doc tests Maybe incorrect parsing of doc tests Jul 8, 2022
@ehuss
Copy link
Contributor

ehuss commented Jul 8, 2022

I think this is expected behavior.

The line * | Yes, is rendered in markdown as a bullet list with an indented code block. All code blocks default to the "rust" language in rustdoc, and all rust codeblocks are tested by default.

There are several issues about this, such as #63193 for adding a control over that, #64162 for distinguishing indented code blocks differently, and #88590 for providing better error messages. (and #59867)

@frank-king
Copy link
Contributor Author

Are there any ways to ignore all the doc tests in a mod? Like #[cfg_attr(doctest, ignore)] (I have tried, but it didn't work).

@ehuss
Copy link
Contributor

ehuss commented Jul 8, 2022

Sorry, I don't know of any workarounds other than disabling comments in bindgen or blocklisting the offending items.

@frank-king
Copy link
Contributor Author

Sigh. I think I'd better manully edit the generated code to pass the tests.

@GuillaumeGomez
Copy link
Member

You can wrap it into a code block like this:

```text
you comment.
```

Since it's not a bug, closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants