Skip to content

Automatically check if README.md examples are working when running "cargo test" - #657

Merged
bors[bot] merged 3 commits into
rayon-rs:masterfrom
GuillaumeGomez:doc-tests
May 1, 2019
Merged

bors[bot] merged 3 commits into
rayon-rs:masterfrom
GuillaumeGomez:doc-tests

Conversation

@GuillaumeGomez

Copy link
Copy Markdown
Contributor

Since rustdoc nightly now provides "cfg(test)" when running on test mode, we can now use this macro on test mode only to check if README.md examples are working as expected.

@cuviper

cuviper commented May 1, 2019

Copy link
Copy Markdown
Member

How do I know if this worked? I don't see README tests in the log:
https://travis-ci.org/rayon-rs/rayon/jobs/525713032

@GuillaumeGomez

GuillaumeGomez commented May 1, 2019

Copy link
Copy Markdown
Contributor Author

It only work on nightly for the moment. The PR got merged recently: rust-lang/rust#59940, so in 6 weeks it'll be in beta and then on stable (but you already know how it works I assume ;) ).

I can add tests for nightly on your CI if you want alongside the others?

@cuviper

cuviper commented May 1, 2019

Copy link
Copy Markdown
Member

Ah, we do have CI for nightly, but only on the full bors check. Let's just go for it:

bors r+

bors Bot added a commit that referenced this pull request May 1, 2019
657: Automatically check if README.md examples are working when running "cargo test" r=cuviper a=GuillaumeGomez

Since rustdoc nightly now provides "cfg(test)" when running on test mode, we can now use this macro on test mode only to check if README.md examples are working as expected.

Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
@bors

bors Bot commented May 1, 2019

Copy link
Copy Markdown
Contributor

Build failed

@GuillaumeGomez

Copy link
Copy Markdown
Contributor Author

Can you tell me what failed please? :)

@cuviper

cuviper commented May 1, 2019

Copy link
Copy Markdown
Member

Looks like a UI issue in rayon-core, unrelated to your change:

---- src/compile_fail/scope_join_bad.rs - compile_fail::scope_join_bad (line 1) stdout ----
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
 --> src/compile_fail/scope_join_bad.rs:8:17
  |
7 |     rayon_core::scope(|s| {
  |                        - has type `&rayon_core::Scope<'1>`
8 |         let x = 22;
9 |         s.spawn(|_| f(&x)); //~ ERROR `x` does not live long enough
  |                 ^^^    - `x` is borrowed here
  |                 |
  |                 may outlive borrowed value `x`
  |
note: function requires argument type to outlive `'1`
 --> src/compile_fail/scope_join_bad.rs:8:9
  |
9 |         s.spawn(|_| f(&x)); //~ ERROR `x` does not live long enough
  |         ^^^^^^^^^^^^^^^^^^
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
  |
9 |         s.spawn(move |_| f(&x)); //~ ERROR `x` does not live long enough
  |                 ^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0373`.
thread 'src/compile_fail/scope_join_bad.rs - compile_fail::scope_join_bad (line 1)' panicked at 'Some expected error codes were not found: ["E0597"]', src/librustdoc/test.rs:315:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

@GuillaumeGomez

Copy link
Copy Markdown
Contributor Author

Oh? That's surprising. Well, I'll let you handle this part then. Thanks for showing me the error! :)

@cuviper

cuviper commented May 1, 2019

Copy link
Copy Markdown
Member

I believe the error change is from NLL being enabled for 2015 edition. Fortunately, compile_fail doc tests still only check the error string on nightly, so we don't have to worry about matching older errors.

bors r+

bors Bot added a commit that referenced this pull request May 1, 2019
657: Automatically check if README.md examples are working when running "cargo test" r=cuviper a=GuillaumeGomez

Since rustdoc nightly now provides "cfg(test)" when running on test mode, we can now use this macro on test mode only to check if README.md examples are working as expected.

Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
@bors

bors Bot commented May 1, 2019

Copy link
Copy Markdown
Contributor

Build failed

@cuviper

cuviper commented May 1, 2019

Copy link
Copy Markdown
Member

Bah, more error changes in rayon-futures...

@cuviper

cuviper commented May 1, 2019

Copy link
Copy Markdown
Member

bors r+

bors Bot added a commit that referenced this pull request May 1, 2019
657: Automatically check if README.md examples are working when running "cargo test" r=cuviper a=GuillaumeGomez

Since rustdoc nightly now provides "cfg(test)" when running on test mode, we can now use this macro on test mode only to check if README.md examples are working as expected.

Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
@bors

bors Bot commented May 1, 2019

Copy link
Copy Markdown
Contributor

@bors
bors Bot merged commit 4547a27 into rayon-rs:master May 1, 2019
@GuillaumeGomez
GuillaumeGomez deleted the doc-tests branch May 2, 2019 07:52
@GuillaumeGomez

Copy link
Copy Markdown
Contributor Author

Congrats and thanks for fixing!

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.

2 participants