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

Make cargo-miri run documentation tests #1671

Closed
wants to merge 11 commits into from
Closed

Conversation

teryror
Copy link
Contributor

@teryror teryror commented Jan 14, 2021

This would resolve #584.

It Works On My Machine. Specifically, it needs a version of rustdoc with this change, which was only merged yesterday, i.e. it needs the most recent nightly build. With that, I can run the entire coca test suite successfully, which is what I used for testing this feature. Verbose output and/or purposefully changing a doc-test to fail confirm this is working as intended, and not just reported incorrectly.

However, updating rustc-version breaks several tests from Miri's own test suite, so merging this will have to wait. Still, I'm sure this would benefit a lot from code review and testing on other projects, in other build environments.

@teryror
Copy link
Contributor Author

teryror commented Jan 16, 2021

I had completely forgotten about test-cargo-miri since I'd been testing on my own project the whole time. This fixes an oversight of mine in phase_cargo_runner, and updates the tests to expect working doc-tests.

Given this still requires a newer rustdoc, I don't expect this to pass CI though.

test-cargo-miri/run-test.py Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

Thanks a lot for this PR! I have this in my queue of things to do. Unfortunately, I am pretty busy currently and reviewing these PRs is but one of many things competing for my spare time, so it might take a week or more until I get around to taking a closer look at this. Sorry for that.

@teryror
Copy link
Contributor Author

teryror commented Jan 17, 2021

No worries, take all the time you need!

@RalfJung
Copy link
Member

Has the rustdoc change landed in the rustc repository in the mean time? Can you rebase this PR over Miri master? That should now work with latest rustc.

cargo-miri/bin.rs Outdated Show resolved Hide resolved
cargo-miri/bin.rs Outdated Show resolved Hide resolved
cargo-miri/bin.rs Outdated Show resolved Hide resolved
cargo-miri/bin.rs Outdated Show resolved Hide resolved
cargo-miri/bin.rs Outdated Show resolved Hide resolved
@teryror
Copy link
Contributor Author

teryror commented Jan 23, 2021

Has the rustdoc change landed in the rustc repository in the mean time? Can you rebase this PR over Miri master? That should now work with latest rustc.

This has been merged for about a week now, yes.

I rolled up all of your suggestions into a single commit, then rebased and force-pushed, we should be good to go. Let's see what CI has to say about it.

@RalfJung
Copy link
Member

I rolled up all of your suggestions into a single commit, then rebased and force-pushed, we should be good to go.

I'd prefer if you could avoid squashing while we are still doing review. That makes my job much easier as it means I do not have to re-read all your code. :)

Let's see what CI has to say about it.

Is the version in rust-version new enough to contain that fix?

@teryror
Copy link
Contributor Author

teryror commented Jan 23, 2021

Argh, sorry about that. Good thing this was mostly about adding more comments.

The rust_version is new enough, the CI check fails because doc-tests aren't run for all targets, so we'd need a different test.default.stdout.ref depending on the platform, it would seem. I find that a bit strange, wouldn't it be better to enable that somehow? I'm not quite sure how, though. What's your preference here?

cargo-miri/bin.rs Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

The rust_version is new enough, the CI check fails because doc-tests aren't run for all targets, so we'd need a different test.default.stdout.ref depending on the platform, it would seem. I find that a bit strange, wouldn't it be better to enable that somehow? I'm not quite sure how, though. What's your preference here?

Looks like cargo by default does not run doctests in cross-mode, but an experimental feature exists to fix that: rust-lang/cargo#7040. Maybe our test suite could use that?

@bors
Copy link
Collaborator

bors commented Jan 24, 2021

☔ The latest upstream changes (presumably #1675) made this pull request unmergeable. Please resolve the merge conflicts.

@teryror
Copy link
Contributor Author

teryror commented Jan 25, 2021

That should do it, I think. I'll get around to merging this with #1675 later today, maybe tomorrow.

Edit: Oops, forgot to save after adding a comment.

@teryror
Copy link
Contributor Author

teryror commented Jan 27, 2021

Getting this to work locally was actually pretty easy, but the CI setup really doesn't like the -Zdoctest-xcompile option. With no toolchain explicitly set, or with +master, it complains about unstable options requiring nightly, with +nightly it says the nightly toolchain is not installed. Once again, I don't know how to proceed here, and trial-and-error gets old fast with this turnaround time. Right now it seems easier to just switch out the test.*.ref files depending on the target.

Furthermore, I don't think phase_cargo_rustdoc even works right in cross-mode, which I hadn't really considered before. Since -Zdoctest-xcompile actually makes cargo pass its own --runtool to rustdoc, which I currently just overwrite, while forwarding any --runtool-args. Miri proper may not actually like those, but that also means the way I select the phase to enter from main when MIRI_CALLED_FROM_RUSTDOC is set is broken.

Soo, I'll have to revise this some more, I guess.

@RalfJung
Copy link
Member

Not supporting cross-running of doctests at first is also fine, if it turns out to be hard (and it seems like it does^^).

You can use the existing is_foreign variable to swap out the ref file. But it would be good if we didn't have to do this for each test. Maybe pass --no-doc for most of them or so?

@teryror
Copy link
Contributor Author

teryror commented Jan 27, 2021

Sounds good to me. I should be able to finish up by tomorrow in that case :)

If no one else picks this up, I should be able to set some time aside to investigate cross-running starting around mid-March (I have exams coming up until then).

@RalfJung
Copy link
Member

If no one else picks this up, I should be able to set some time aside to investigate cross-running starting around mid-March (I have exams coming up until then).

Awesome. :) Once this lands, it's probably best to create an issue and leave such notes there. And good call on not letting Miri distract you too much from your exams 👍

@RalfJung
Copy link
Member

RalfJung commented Feb 2, 2021

@teryror I'm sorry I lost track... is this PR waiting for me to review it, or do you have further changes planned?

@teryror
Copy link
Contributor Author

teryror commented Feb 4, 2021

This is ready for review, yes, probably should have pinged you about that, sorry. I didn't rebase in a week or so, no changes planned besides that.

env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
)
test("`cargo miri test` (raw-ptr tracking)",
cargo_miri("test"),
"test.default.stdout.ref", rustdoc_ref,
default_ref, "test.stderr-empty.ref",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change one of these tests to also pass --no-doc, just to make sure that that actually has the intended effect?

@RalfJung
Copy link
Member

RalfJung commented Feb 6, 2021

This looks great, I just have some minor nits. :)

@RalfJung

This comment has been minimized.

@ghost
Copy link

ghost commented Feb 14, 2021

This PR does not pass a test that will be introduced in #1709:

## Running `cargo miri` tests
A libstd for Miri is now available in `/home/user/.cache/miri/HOST`.
Testing `cargo miri run` (no isolation)...
Testing `cargo miri run` (with arguments and target)...
Testing `cargo miri run` (subcrate, no ioslation)...
Testing `cargo miri test`...
--- BEGIN stdout ---

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


running 7 tests
..i....
test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out

--- END stdout ---
--- BEGIN stderr ---
error[E0460]: found possibly newer version of crate `std` which `issue_1691` depends on
 --> /home/user/miri/test-cargo-miri/src/lib.rs:6:5
  |
6 |     issue_1691::use_me()
  |     ^^^^^^^^^^
  |
  = note: perhaps that crate needs to be recompiled?
  = note: the following crate versions were found:
          crate `std`: /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-6f5658153d127ddd.rlib
          crate `std`: /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-6f5658153d127ddd.so
          crate `issue_1691`: /home/user/miri/test-cargo-miri/target/x86_64-unknown-linux-gnu/debug/deps/libissue_1691-30200c4d8cd6fa63.rmeta

error: aborting due to previous error

error: test failed, to rerun pass '--doc'
--- END stderr ---

TEST FAIL: exit code was 1

This can fix it (feel free to cherry-pick it, but it duplicates some --sysroot code, so probably needs to be deduplicated before landing, also note that it contains some unrelated whitespace diff because my editor trimmed trailing whitespaces automatically).

@bors
Copy link
Collaborator

bors commented Feb 15, 2021

☔ The latest upstream changes (presumably #1710) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung
Copy link
Member

RalfJung commented Apr 5, 2021

@teryror I haven't heard from you in a while, so I assume you moved on to other things. Thanks a lot for this PR! I will take over and finish it so that it can hopefully land soon. :)

@RalfJung RalfJung mentioned this pull request Apr 5, 2021
@RalfJung
Copy link
Member

RalfJung commented Apr 5, 2021

Closing in favor of #1757.

@RalfJung RalfJung closed this Apr 5, 2021
bors added a commit that referenced this pull request Apr 6, 2021
add rustdoc support

`@teryror` did all the work in #1671; I just finished things up and fixed conflicts. Also thanks to `@hyd-dev` for preemptively fixing a sysroot issue that would have taken me some time to diagnose.

Fixes #584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo miri test does not run doc-tests
3 participants