-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 should have their file/lines remapped when using -Zinstrument-coverage
#79417
Comments
Here is some example code: |
Hi @Swatinem ! Thanks for your patience. It would be great if you could work on this! (I will probably not be able to work on it any time soon.) I was able to reproduce this issue as well. Your instructions above are great. Another way to see these results, using cargo commands similar to what's in the updated "Rust Unstable Book" documentation (just for comparison and context) is: $ rm -rf target/debug/doctestbins/*
$ RUSTFLAGS="-Zinstrument-coverage" RUSTDOCFLAGS="-Zinstrument-coverage -Z unstable-options \
--persist-doctests target/debug/doctestbins" LLVM_PROFILE_FILE="json5format-%m.profraw" \
cargo test --doc
# or full coverage status after running both doc and non-doc tests:
# $ RUSTFLAGS="-Zinstrument-coverage" RUSTDOCFLAGS="-Zinstrument-coverage -Z unstable-options \
# --persist-doctests target/debug/doctestbins" LLVM_PROFILE_FILE="json5format-%m.profraw" \
# cargo test # (default: both --tests and --doc)
$ cargo profdata -- merge -sparse json5format-*.profraw -o json5format.profdata
$ cargo cov -- show --color -Xdemangler=rustfilt --instr-profile=json5format.profdata \
$(for file in target/debug/build/* target/debug/doctestbins/*/*; \
do [[ ! -d $file && -x $file ]] && echo $file; done) \
--show-line-counts-or-regions --show-instantiations | less -R When I ran this, I saw (for example) the large test block in If you do work on this, I'm happy to try to help and answer questions if you have them, either via this issue (for more strategic issues in particular) or via a Zulip topic. I don't know how rustdoc does its remapping specifically, but that sounds like a good place to start looking. The tcx.sess.source_map(); to get the file name, line, and column. One nice thing about that is, I know there are ways to remap the source directly in the I know this works for file names, at least. If I add the following to
the coverage map embedded in the binary will use the Maybe there's already support for remapping line numbers. If not, that may still be the place to implement a line mapping feature. Obviously a command line flag is not the right approach for line number mapping. You would need to derive the line number offset from the line position of each test, and you would only apply that offset to the test code, without changing the line numbers of other "real" functions in the source file. So, a bit different, but it should be possible. |
Thanks for pointing me to rust/compiler/rustc_span/src/source_map.rs Lines 417 to 429 in a68864b
Just for reference, this was added here: #47274 and later passed via unstable env vars here: #63827 I’m playing around with this a bit and it seems like I have found a way to re-map the lines, however there is still other problems related to rustdoc that I would have to fix separately. I will test a bit more locally and then open a PR :-) |
rust-lang/cargo#8954 is a change to cargo that should make rustdoc use the correct filenames for workspace crates. I think that will solve the filename problem, although I haven’t tested that directly yet. |
This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done. Part of issue rust-lang#79417.
…Swatinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? `@richkadel` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
…Swatinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? ``@richkadel`` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
…Swatinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? ```@richkadel``` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
…Swatinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? `@richkadel` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
…Swatinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? `@richkadel` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
…Swatinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? ``@richkadel`` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
…Swatinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? ```@richkadel``` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
…Swatinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? ````@richkadel```` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
…atinem Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of rust-lang#79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? `@richkadel` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
This Issue is partially resolved by #79762. (Thanks @Swatinem!) There are some known issues still to resolve:
|
There are some issues with documentation tests, see taiki-e/cargo-llvm-cov#2 and rust-lang/rust#79417
There are some issues with documentation tests, see taiki-e/cargo-llvm-cov#2 and rust-lang/rust#79417
There are some issues with documentation tests, see taiki-e/cargo-llvm-cov#2 and rust-lang/rust#79417
I have a workspace with
crate_a
(andcrate_b
, but its not used for this example), and use the following env vars set to have my rustdoc tests run through code coverage:RUSTDOCFLAGS="-Z instrument-coverage -Z unstable-options --persist-doctests=C:\Users\swatinem\AppData\Local\Temp\_rustdoc
Running the result later through
llvm-cov
gives me errors for my rustdocs, and unexpected results:When using
export -format=lcov
, I get the following:This is not really a problem per-se, but note that the filename is not relative to my workspace, but to the crate inside the workspace, which creates problems down the road, because uploading that report to
codecov
actually finds the correct file for some reason, but then highlights lines 3 and 4.So ideally, the coverage support should similarly re-map line numbers such as compile errors in doctests do, and the filename should be relative to the workspace (but that seems to be a separate issue with rustdoc I guess).
@richkadel I guess you know the code the best: Is such a re-mapping that I propose possible at all? If so, I would be happy to work on this if you point me in the right direction and would be willing to mentor me ;-)
The text was updated successfully, but these errors were encountered: