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

fix(test): Distinguish 'testname' from escaped arguments #11190

Merged
merged 2 commits into from
Oct 7, 2022

Conversation

epage
Copy link
Contributor

@epage epage commented Oct 7, 2022

When working on clap v4, it appeared that last and trailing_var_arg
are mutually exclusive, so I called that out in the debug asserts in
#4187. Unfortunately, I didn't document my research on this
as my focus was elsewhere.

When updating cargo to use clap v4 in #11159, I found last and
trailing_var_arg were used together. I figured this was what I was
trying to catch with above and I went off of my intuitive sense of these
commands and assumed trailing_var_arg was intended, not knowing about
the testname positional that is mostly just a forward to libtest,
there for documentation purposes, except for a small optimization.

So it looks like we just need the last call and not the
trailing_var_arg call.

This restores us to behavior from 531ce13 which is what I originally
wrote the tests against.

It looks like #11159 was merged after the last beta branch was made, so we shouldn't
need to cherry-pick this into any other release.

For reviewing this, I made the test updates in the first commit, showing the wrong behavior. The following commit fixes the behavior and updates the tests to expected behavior.

Fixes #11191

When working on clap v4, it appeared that `last` and `trailing_var_arg`
are mutually exclusive, so I called that out in the debug asserts in
clap-rs/clap#4187.  Unfortunately, I didn't document my research on this
as my focus was elsewhere.

When updating cargo to use clap v4 in rust-lang#11159, I found `last` and
`trailing_var_arg` were used together.  I figured this was what I was
trying to catch with above and I went off of my intuitive sense of these
commands and assumed `trailing_var_arg` was intended, not knowing about
the `testname` positional that is mostly just a forward to `libtest`,
there for documentation purposes, except for a small optimization.

So it looks like we just need the `last` call and not the
`trailing_var_arg` call.

This restores us to behavior from 531ce13 which is what I originally
wrote the tests against.
@rust-highfive
Copy link

r? @ehuss

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 7, 2022
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Sorry for my oversight on this behaviour change.

Could you help double confirm that cargo run, cargo rustc, and cargo rustdoc are not affected? From my understanding they should behave as before and just tested by hands them seem fine.

@weihanglo
Copy link
Member

Feel free to r=weihanglo once you've done the confirmation. I may update Cargo in rust-lang/rust after this get merged.

@epage
Copy link
Contributor Author

epage commented Oct 7, 2022

Could you help double confirm that cargo run, cargo rustc, and cargo rustdoc are not affected? From my understanding they should behave as before and just tested by hands them seem fine.

Those commands are unrelated to the problem. This is a problem specifically with how I handled the change from .last(true).trailing_var_arg(true) which only affected cargo bench and cargo test (I searched #11159 multiple times to confirm). Even then, the only way to observe a problem is if people are relying on the specialization of logic that exists only in cargo test.. This precludes observing a change in behavior in cargo bench as it just takes BENCHNAME and prefixes it to args without any logic conditioned on the existence of BENCHNAME; no matter whether -- is used or not, the same behavior will occur. It took me several tries to even create a good test case for cargo test that clearly showed the problem due to how specific the relevant problem is.

Sorry for my oversight on this behaviour change.

Responsibility first lies with the author, reviewers can't be expected to catch everything. Unless you knew to check this exact case, I bet we would have missed it anyways.

r=weihanglo

@epage
Copy link
Contributor Author

epage commented Oct 7, 2022

@bors r=weihanglo

(of course I forgot to tag bors)

@bors
Copy link
Contributor

bors commented Oct 7, 2022

📌 Commit 3dd8413 has been approved by weihanglo

It is now in the queue for this repository.

@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 Oct 7, 2022
@bors
Copy link
Contributor

bors commented Oct 7, 2022

⌛ Testing commit 3dd8413 with merge 3cdf1ab...

@weihanglo
Copy link
Member

I should have thought of that, since I did some fixes around it…

Anyway, thanks for your quick patch!

@CAD97
Copy link
Contributor

CAD97 commented Oct 7, 2022

(hi I'm the one that found the behavior change)

It's definitely good to restore previous behavior here, but it's also I think worth discussing whether cargo test TESTARG and cargo test -- TESTARG should be behaving differently.

To me, it seems quite odd that being explicit about which arguments are passed to the test runner should change how the test runner is run.

Plus, in general, due to how rustdoc (ab)uses the test runner, flags can have distinctly different behavior. (The notable one I'm dealing with is --ignored.)

@epage
Copy link
Contributor Author

epage commented Oct 7, 2022

(hi I'm the one that found the behavior change)

It's definitely good to restore previous behavior here, but it's also I think worth discussing whether cargo test TESTARG and cargo test -- TESTARG should be behaving differently.

To me, it seems quite odd that being explicit about which arguments are passed to the test runner should change how the test runner is run.

Plus, in general, due to how rustdoc (ab)uses the test runner, flags can have distinctly different behavior. (The notable one I'm dealing with is --ignored.)

#6981 is the issue for that.

@bors
Copy link
Contributor

bors commented Oct 7, 2022

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 3cdf1ab to master...

@bors bors merged commit 3cdf1ab into rust-lang:master Oct 7, 2022
weihanglo added a commit to weihanglo/rust that referenced this pull request Oct 7, 2022
4 commits in 0b84a35c2c7d70df4875a03eb19084b0e7a543ef..3cdf1ab25dc4fe56f890e8c7330d53a23ad905d3

2022-10-03 19:13:21 +0000 to 2022-10-07 17:34:03 +0000
- fix(test): Distinguish 'testname' from escaped arguments (rust-lang/cargo#11190)
- Fix sparse registry lockfile urls containing 'registry+sparse+' (rust-lang/cargo#11177)
- doc(features2): polish docs a bit (rust-lang/cargo#11185)
- Import `cargo remove` into cargo (rust-lang/cargo#11099)
@epage epage deleted the test branch October 7, 2022 20:21
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 7, 2022
Update cargo

4 commits in 0b84a35c2c7d70df4875a03eb19084b0e7a543ef..3cdf1ab25dc4fe56f890e8c7330d53a23ad905d3

2022-10-03 19:13:21 +0000 to 2022-10-07 17:34:03 +0000
- fix(test): Distinguish 'testname' from escaped arguments (rust-lang/cargo#11190)
- Fix sparse registry lockfile urls containing 'registry+sparse+' (rust-lang/cargo#11177)
- doc(features2): polish docs a bit (rust-lang/cargo#11185)
- Import `cargo remove` into cargo (rust-lang/cargo#11099)
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Oct 9, 2022
Update cargo

4 commits in 0b84a35c2c7d70df4875a03eb19084b0e7a543ef..3cdf1ab25dc4fe56f890e8c7330d53a23ad905d3

2022-10-03 19:13:21 +0000 to 2022-10-07 17:34:03 +0000
- fix(test): Distinguish 'testname' from escaped arguments (rust-lang/cargo#11190)
- Fix sparse registry lockfile urls containing 'registry+sparse+' (rust-lang/cargo#11177)
- doc(features2): polish docs a bit (rust-lang/cargo#11185)
- Import `cargo remove` into cargo (rust-lang/cargo#11099)
@ehuss ehuss added this to the 1.66.0 milestone Oct 10, 2022
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo runs disabled unit tests when arguments are pased via --
6 participants