You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and add this line to the end of main(), in src/main.rs:
print!("{}", quine::LIB_SOURCE);
✔️ cargo run works as expected, but...
❌ cargo test chokes when trying to run doc tests:
Doc-tests quine
error: couldn't read /data/projects/quine/src/..//data/projects/quine/src/lib.rs: No such file or directory (os error 2)
cargo test -v confirms that Cargo is passing absolute source paths to rustdoc. If I run the same rustdoc command, except with a relative path to the source file, everything compiles as expected.
Possible Solution(s)
For now, my workaround is to disable doc tests in Cargo.toml, and then invoke rustdoc manually from build automation.
[lib]
doctest = false
But intuitively, I'd not expect the value of path!() to change between my normal build and my doc tests.
To ensure that, it seems that Cargo must pass a relative source path to rustdoc, not an absolute path.
Thanks for the thorough report! This is a known issue, and there is a fix on the nightly channel using the -Z doctest-in-workspace flag. If you could give it a try on your projects and report if there are any problems, that would be appreciated. Closing in favor of tracking issue #9427.
Problem
cargo test
invokesrustdoc
with absolute paths, causing compile errors if the code depends on source paths being relative, e.g. through usingto auto-include matching
build.rs
-generated code.Steps
To demonstrate, let's make a quine!
Create a new Cargo binary project with
cargo new quine
, and put this insrc/main.rs
:✔️
cargo run
shows that the code is working, and✔️
cargo test
confirms that our non-existing test suite is green.This code works, but is horribly unorganized. The next obvious step is to create a separate library crate, so put this in
src/lib.rs
:and add this line to the end of
main()
, insrc/main.rs
:✔️
cargo run
works as expected, but...❌
cargo test
chokes when trying to run doc tests:cargo test -v
confirms that Cargo is passing absolute source paths torustdoc
. If I run the samerustdoc
command, except with a relative path to the source file, everything compiles as expected.Possible Solution(s)
For now, my workaround is to disable doc tests in
Cargo.toml
, and then invokerustdoc
manually from build automation.But intuitively, I'd not expect the value of
path!()
to change between my normal build and my doc tests.To ensure that, it seems that Cargo must pass a relative source path to
rustdoc
, not an absolute path.Notes
Output of
cargo version
:Confirmed with both above versions, on Linux and Windows.
The text was updated successfully, but these errors were encountered: