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

doctest line number is incorrect if used with #![doc = include_str!()] #127893

Open
ProfFan opened this issue Jul 18, 2024 · 6 comments
Open

doctest line number is incorrect if used with #![doc = include_str!()] #127893

ProfFan opened this issue Jul 18, 2024 · 6 comments
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@ProfFan
Copy link

ProfFan commented Jul 18, 2024

I tried this code:

#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]

/// ```no_run << line 23
///  panic!("nooo");
///  ```
pub struct XXXXYYYY<A, B> {
...
}

I expected to see this happen: the included doctests show the line number of the include statement.

Instead, this happened:

running 2 tests
test src/lib.rs - XXXXYYYY (line 23) - compile ... ok
test src/lib.rs - (line 23) ... FAILED

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (032be6f7b 2024-07-16)
binary: rustc
commit-hash: 032be6f7bbe091c7dfa29f115e94b9cc9bae1758
commit-date: 2024-07-16
host: aarch64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7
Backtrace

N/A

@ProfFan ProfFan added the C-bug Category: This is a bug. label Jul 18, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 18, 2024
@ProfFan ProfFan changed the title doctest repeats ignored test on macOS doctest repeats ignored/removed test on macOS Jul 18, 2024
@ProfFan
Copy link
Author

ProfFan commented Jul 18, 2024

Strange, this runs even after I removed the doctest itself, target folder, as well as doing a cargo clean. Does cargo keep a cache of this test somewhere outside of the project?

@workingjubilee
Copy link
Member

...weird.

can you provide a version that compiles and repros?

@ProfFan
Copy link
Author

ProfFan commented Jul 18, 2024

...weird.

can you provide a version that compiles and repros?

https://github.com/ProfFan/icm426xx on main

I don't know if this is my macOS being funky, this is the only system I have.

Just run cargo test and this should trigger?

@ProfFan
Copy link
Author

ProfFan commented Jul 18, 2024

nvm, it's this trick from stackoverflow that got me:

#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]

This results in doctest trying to run the code snippet from README.

However this problem is still valid: the displayed line number is clearly incorrect. It shows the line number of my disabled test in the source code.

@ProfFan ProfFan changed the title doctest repeats ignored/removed test on macOS doctest line number is incorrect if used with #![doc = include_str!()] Jul 18, 2024
@ProfFan
Copy link
Author

ProfFan commented Jul 18, 2024

@tgross35
Copy link
Contributor

Similar but not exact issue #81070

@tgross35 tgross35 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-doctests Area: Documentation tests, run by rustdoc and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

No branches or pull requests

4 participants