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

file-level doctests have wrong file/line mapping when module has use-level doctest #79764

Open
Swatinem opened this issue Dec 6, 2020 · 0 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

@Swatinem
Copy link
Contributor

Swatinem commented Dec 6, 2020

I have a module in an external file.
When I add doctests to both the pub mod X; item, and the X.rs file, the file-level doctest has the wrong filename/line information.

Consider the following example:

--- lib.rs ---
//! crate-level doctest
//!
//! ```
//! // lib.rs line 3
//! assert_eq!(1, 1);
//! ```

pub mod mod_with_file_doctest;

/// mod reference-level doctest
///
/// ```
/// // lib.rs line 12
/// assert_eq!(1, 1);
/// ```
pub mod mod_with_ref_doctest;

/// mod reference-level doctest
///
/// ```
/// // lib.rs line 20
/// assert_eq!(1, 1);
/// ```
pub mod mod_with_both_doctests;

--- mod_with_file_doctest.rs ---

//! mod file-level doctest
//!
//! ```
//! // mod_with_file_doctest.rs line 3
//! assert_eq!(1, 1);
//! ```

--- mod_with_both_doctests.rs ---

//! mod file-level doctest
//!
//! ```
//! // mod_with_both_doctests.rs line 3
//! assert_eq!(1, 1);
//! ```

Running cargo test, I get the following output:

running 5 tests
test src\lib.rs - mod_with_both_doctests (line 20) ... ok
test src\lib.rs - mod_with_both_doctests (line 26) ... ok
test src\lib.rs - (line 3) ... ok
test src\mod_with_file_doctest.rs - mod_with_file_doctest (line 3) ... ok
test src\lib.rs - mod_with_ref_doctest (line 12) ... ok

The line test src\lib.rs - mod_with_both_doctests (line 26) should actually be test src\mod_with_file_doctest.rs - mod_with_file_doctest (line 3)

Looks like that the line 26 is somehow relative to the pub mod line.

I will look into this and try to get a PR together that fixes this.

@Swatinem Swatinem added the C-bug Category: This is a bug. label Dec 6, 2020
@Swatinem Swatinem changed the title Module-level doctests have wrong file/line mapping when module has use-level doctest file-level doctests have wrong file/line mapping when module has use-level doctest Dec 6, 2020
@camelid camelid added A-doctests Area: Documentation tests, run by rustdoc T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Dec 6, 2020
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

3 participants