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

Cargo test quicker by not building untested examples #6677

Conversation

dwijnand
Copy link
Member

(TIL cargo test --tests runs test-enabled examples.)

Pushes forward from #5464
Fixes #6675
r? @ehuss

@dwijnand
Copy link
Member Author

Test-wise, I tried to adapt tests to the new expectations however, some tests I felt had to be dropped entirely. With the test changes made I felt no further tests were required. But let me know what you think.

(TIL `cargo test --tests` runs test-enabled examples.)
@dwijnand dwijnand force-pushed the cargo-test-quicker-by-not-building-untested-examples branch from 809f4a4 to 137e23c Compare February 18, 2019 07:38
@ehuss
Copy link
Contributor

ehuss commented Feb 19, 2019

I'm not sure I understand the motivation for this. Examples are intentionally built by default in cargo test to ensure they are not broken. That seems like a good compromise, in that examples almost never have unit tests (and thus building them as a test would be a waste). Not building them at all would risk them becoming stale.

I think it would be reasonable to skip non-tested examples if cargo test includes an argument (cargo test foo). But this is related to the general problem that Cargo does not know which target contains a specific test, and would only be a minor improvement of that problem.

@dwijnand
Copy link
Member Author

I'm not sure I understand the motivation for this. Examples are intentionally built by default in cargo test to ensure they are not broken.

I guess our opinions differ here. I think examples are a great feature built into cargo, but I would've assumed you'd need to run something like cargo check --examples or cargo check --all-targets in CI to ensure they still compile. So I agree with the premise of #6675 that adding a space to a unit test shouldn't force all 12 examples to rebuild when running cargo test.

Two more questions:

  1. if adding a space to a cfg test unit test, why doesn't the incremental compiler kick in and realise the examples don't need to recompile?
  2. I had a variant of this based on the non-emptiness of test_args, i.e. exclude building non-testable examples if any arguments (e.g TESTNAME) was specified. Would you be happier to land a change along those lines?

@ehuss
Copy link
Contributor

ehuss commented Feb 19, 2019

1. if adding a space to a cfg test unit test, why doesn't the incremental compiler kick in and realise the examples don't need to recompile?

I don't know much about how incremental works.

2. I had a variant of this based on the non-emptiness of `test_args`, i.e. exclude building non-testable examples if any arguments (e.g TESTNAME) was specified.  Would you be happier to land a change along those lines?

I think that would be the safer route if it is not too complex.

@dwijnand
Copy link
Member Author

OK, I'll propose that instead.

@dwijnand dwijnand closed this Feb 19, 2019
@dwijnand dwijnand deleted the cargo-test-quicker-by-not-building-untested-examples branch February 19, 2019 17:33
bors added a commit that referenced this pull request Feb 25, 2019
…ested-examples-when-filtered, r=ehuss

Cargo test quicker by not building untested examples when filtered

Alternative to #6677
Fixes #6675
r? @ehuss
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