Closed
Description
Problem
cargo 1.50.0-nightly
changes the current working directory for doctests when executed from a workspace. Instead of the crate's root, the workspace's root is assumed. The regression originates in #8954. I think, the cwd should still point to the crate root in all cases.
Steps
- Crate a workspace with a member crate in a subdirectory.
- Write a doctest that reads a file relative to the crate root, e.g.
src/lib.rs
. - Test with
cargo +stable test --workspace
and observe the test pass. - Test with
cargo +nightly test --workspace
and observe the test fail.
Possible Solution(s)
- Revert Run rustdoc doctests relative to the workspace #8954. I have not checked if there are any follow-ups.
- Explicitly set the CWD while also somehow preserving workspace-relative file path information. It seems like this may be required to solve Rustdoc doctests should have their file/lines remapped when using
-Zinstrument-coverage
rust#79417.
Notes
Output of cargo version
: cargo 1.50.0-nightly (d274fcf86 2020-12-07)
Example src/lib.rs
for a workspace member that will pass on stable but fail on nightly:
//! ```
//! assert_eq!(std::fs::read_to_string("src/lib.rs").unwrap(), include_str!("lib.rs"));
//! ```