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

[beta] properly run doctests in standalone markdown files with pulldown #48410

Merged
merged 1 commit into from
Mar 3, 2018

Conversation

QuietMisdreavus
Copy link
Member

This is a beta-specific fix for #48327, since a different fix landed in nightly (#48274) that is infeasible to backport.

The nature of the issue was that when running doctests on standalone Markdown files, rustdoc names the tests based on the headings in the files. Therefore, with the following a.md:

# My Cool Library

This is my cool library!

## Examples

Here's some cool code samples!

```rust
assert_eq!(2+2, 4);
```

Running this file with rustdoc --test a.md would show a test named a.md - my_cool_library::examples (line 9). So far, this works just fine between Hoedown and Pulldown. But it gets murkier when you introduce markup into your headings. Consider the following b.md:

# My Cool Library

This is my cool library!

## `libcool`

```rust
assert_eq!(2+2, 4);
```

The code surrounding the different renderers handles this differently. Pulldown handles just the first Text event after seeing the header, so it names the test b.md - my_cool_library::libcool (line 9). Hoedown, on the other hand, takes all the test within the heading, which Hoedown renders before handing to library code. Therefore, it will name the test b.md - my_cool_library::_code_libcool__code_ (line 9). (Somewhere between rustdoc and libtest, the </> characters are replaced with underscores.)

This causes a problem with another piece of code: The one that checks for whether Pulldown detected a code block that Hoedown didn't. The test collector groups the "old tests" listing by the full test name, but it inserts with the Hoedown name, and searches for the Pulldown name! This creates a situation where when b.md from above is run, it can't find a matching test from the ones Hoedown extracted, so it discards it and emits a warning.

On nightly, this has been fixed by... ditching Hoedown entirely. This also removed the code that tracked the different test listings, and made it run the test anyway. Since backporting the Hoedown removal is infeasible (i'm personally relying on the change to ride the trains to give the stabilization enough time to complete), this instead chooses to group the test by the filename, instead of the full test name as before. This means that the test extractor finds the test properly, and properly runs the test.

@rust-highfive
Copy link
Collaborator

r? @steveklabnik

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive
Copy link
Collaborator

warning Warning warning

  • Pull requests are usually filed against the master branch for this repo, but this one is against beta. Please double check that you specified the right target!

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 21, 2018
@pietroalbini
Copy link
Member

@rust-lang/dev-tools, can we get a review on this PR?

@shepmaster shepmaster added the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Mar 2, 2018
@shepmaster
Copy link
Member

@rust-lang/dev-tools, can we get a review on this PR?

@alexcrichton
Copy link
Member

@bors: r+ p=3

Thanks @QuietMisdreavus!

@bors
Copy link
Contributor

bors commented Mar 3, 2018

📌 Commit 798feb2 has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 3, 2018
@bors
Copy link
Contributor

bors commented Mar 3, 2018

⌛ Testing commit 798feb2 with merge da64ca9...

bors added a commit that referenced this pull request Mar 3, 2018
[beta] properly run doctests in standalone markdown files with pulldown

This is a beta-specific fix for #48327, since a different fix landed in nightly (#48274) that is infeasible to backport.

The nature of the issue was that when running doctests on standalone Markdown files, rustdoc names the tests based on the headings in the files. Therefore, with the following `a.md`:

``````markdown
# My Cool Library

This is my cool library!

## Examples

Here's some cool code samples!

```rust
assert_eq!(2+2, 4);
```
``````

Running this file with `rustdoc --test a.md` would show a test named `a.md - my_cool_library::examples (line 9)`. So far, this works just fine between Hoedown and Pulldown. But it gets murkier when you introduce markup into your headings. Consider the following `b.md`:

``````markdown
# My Cool Library

This is my cool library!

## `libcool`

```rust
assert_eq!(2+2, 4);
```
``````

The code surrounding the different renderers handles this differently. Pulldown handles just the first `Text` event after seeing the header, so it names the test `b.md - my_cool_library::libcool (line 9)`. Hoedown, on the other hand, takes all the test within the heading, which Hoedown renders before handing to library code. Therefore, it will name the test `b.md - my_cool_library::_code_libcool__code_ (line 9)`. (Somewhere between rustdoc and libtest, the `</>` characters are replaced with underscores.)

This causes a problem with another piece of code: The one that checks for whether Pulldown detected a code block that Hoedown didn't. The test collector groups the "old tests" listing by the full test name, but it *inserts* with the Hoedown name, and *searches* for the Pulldown name! This creates a situation where when `b.md` from above is run, it can't find a matching test from the ones Hoedown extracted, so it discards it and emits a warning.

On nightly, this has been fixed by... ditching Hoedown entirely. This also removed the code that tracked the different test listings, and made it run the test anyway. Since backporting the Hoedown removal is infeasible (i'm personally relying on the change to ride the trains to give the stabilization enough time to complete), this instead chooses to group the test by the filename, instead of the full test name as before. This means that the test extractor finds the test properly, and properly runs the test.
@bors
Copy link
Contributor

bors commented Mar 3, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing da64ca9 to beta...

@bors bors merged commit 798feb2 into rust-lang:beta Mar 3, 2018
@QuietMisdreavus QuietMisdreavus deleted the beta-48327 branch May 9, 2018 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants