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

rustdoc: doctests with a manual crate_name attribute cannot run #57317

Closed
QuietMisdreavus opened this issue Jan 3, 2019 · 0 comments
Closed
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

@QuietMisdreavus
Copy link
Member

//! ```
//! #![crate_name = "asdf"]
//!
//! println!("yo");
//! ```
$ rustdoc +nightly u.rs --test

running 1 test
test u.rs -  (line 1) ... FAILED

failures:

---- u.rs -  (line 1) stdout ----
thread 'u.rs -  (line 1)' panicked at 'couldn't run the test: No such file or directory (os error 2)', src/librustdoc/test.rs:343:19
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.


failures:
    u.rs -  (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Based on investigation in rust-lang/rust-by-example#1137 (comment), rustdoc hardcodes the name of the doctest executable to run, but manually setting a #![crate_name] attribute changes the name of this executable. This causes the above error, because rustdoc is trying to run the wrong executable.

@QuietMisdreavus QuietMisdreavus 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 C-bug Category: This is a bug. labels Jan 3, 2019
kennytm added a commit to kennytm/rust that referenced this issue Jan 5, 2019
…r=GuillaumeGomez

rustdoc: force binary filename for compiled doctests

Fixes rust-lang#57317, needed for rust-lang/rust-by-example#1137

Right now, when building a doctest, rustdoc provides the compiler an output directory (a temp dir) but lets the compiler name the executable. If the doctest needs to be executed, it then tries to run a binary named `rust_out` from that directory. For the most part, this works fine. However, if the doctest sets its own crate name, the compiler uses that name for the output binary instead. This causes rustdoc to try to execute a nonexistent binary, causing the test to fail.

This PR changes the paths rustdoc gives to the compiler when building doctests to force the output *filename* instead of just the *directory*.
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
None yet
Development

No branches or pull requests

1 participant