Skip to content

Conversation

Eh2406
Copy link
Contributor

@Eh2406 Eh2406 commented Jun 26, 2018

closes #5648
The alternative was to use set_var to emulate masquerade_as_nightly_cargo but we worried that it would not get unset correctly. Although I think each test is its own process, so it should work.

@rust-highfive
Copy link

r? @matklad

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

@@ -354,6 +354,12 @@ fn test_resolving_minimum_version_with_transitive_deps() {
pkg!("bar" => [dep_req("util", ">=1.0.1")]),
]);

if !nightly_features_allowed() {
Copy link
Member

Choose a reason for hiding this comment

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

I feel like I've seen other cargo tests use something like is_nightly already, perhaps grep for #![feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call switched to is_nightly

@ehuss
Copy link
Contributor

ehuss commented Jun 26, 2018

I'm wondering if all the advanced-env config tests need this as well (everything that calls new_config()). It's not clear to me in what situation this is actually needed, though.

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 26, 2018

probably, update on the way.

@matklad
Copy link
Contributor

matklad commented Jun 26, 2018

Question: why these tests pass Cargo's own CI, which uses stable, in the first place?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 26, 2018

@matklad I don't fully understand ether, the best explanation so far is #5648 (comment)

@alexcrichton
Copy link
Member

Hm I agree with @matklad that it's a little worrisome how these tests are passing today. Could we perhaps:

  • Unconditionally set the release channel to "stable" for all tests
  • Have specific tests opt-out to using the nightly/dev version of Cargo

That way we should proactively catch this and it's clear which tests are opting in to nightly?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 28, 2018

@alexcrichton I do not, at this time, know this stuff well enough to make that happen. When we have a plan of action, someone could give mentoring instructions, or just submit an alternative PR. I made this PR as a quick fix, I was unclear if this was a crises (like blocking the 1.27 release.) that needed a fix before the knowledgeable people returned.

@alexcrichton
Copy link
Member

@Eh2406 oh no worries! I can try to help guide you through this if you want as well.

It actually looks like we already do this for everything using project(...) and invoking the Cargo executable. In that sense this may be exclusive to these tests which aren't using that and may just mean that new_config needs to change?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 28, 2018

Yes I believe that is true. I.E. "integration test" that use ProcessBuilder require masquerade_as_nightly_cargo to use nightly only things. But they do that by setting the env for the new spawned process. The problem is for tests that do not spawn a process, how do we default them all to "stable" and how do we override it when needed without rass conditions between tests.

@alexcrichton
Copy link
Member

Indeed yeah, I'd imagine that a method could be added to Config to override the channel?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 28, 2018

Can we just call set_var in that method or will other test get to see that we changed it?

@ehuss
Copy link
Contributor

ehuss commented Jun 28, 2018

One idea to ensure everything tests on stable by default is to change this line to "stable":

.unwrap_or_else(|| String::from("dev"))

I tested it, and only the tests fixed in this PR fail. That way, unittests that need nightly will be be explicit (either by overriding the channel or just ignoring the test).

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 28, 2018

@ehuss dose that means that cargo built from source does not allow nightly things?

@ehuss
Copy link
Contributor

ehuss commented Jun 28, 2018

@ehuss dose that means that cargo built from source does not allow nightly things?

Ah, yea, that probably would be annoying. Nevermind. 😛

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 28, 2018

I tried .unwrap_or_else(|| String::from(if cfg!(test) {"stable"} else {"dev"} )) but tests in the cfg!(test) is false for tests in cargo\tests directory. So that is a nogo.

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 28, 2018

Also this is buggy as nightly_features_allowed != is_nightly. I was wrong. is_nightly checks if rustc can compile nightly things. We want nightly_features_allowed that checks if cargo can use nightly things. But it is not worth fixing If we are going to use a different approach.

@alexcrichton
Copy link
Member

Could a global variable be added to src/cargo/core/features.rs with a function like disable_nightly_features()? That way all these tests would call that function (or the helper all these tests use would call that function). I think that'd be relatively uninvasive?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 29, 2018

@alexcrichton I don't quite understand your suggestion. Witch is ok, you could elaborate or make an alternative PR, whichever is easier for you.

The design constraints I see are:

  1. test see "stable" unless they opt out. (or we are likely to regress on this with the next nightly thing.)
  2. test do not get to see the setting from previous test. (or debugging with bee a nightmare.)
  3. a cargo build gives a binary that has nightly things. (or developing new feachers with be hard.)

So I think you are suggesting a global mutable variable, that defaults to "dev" (so we get 3) and can be changed to "stable" using the helper function disable_nightly_features. Isn't that the wrong default for 1, and how do we ensure it is reset between test for 2?

@alexcrichton
Copy link
Member

Ah yes those constraints are indeed correct! I think my idea wasn't quite what we wanted but I whipped this up -- https://gist.github.com/alexcrichton/9c878e9d1c81a1956af9323657dacf2b -- which is somewhat similar. I think that should solve everything?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 29, 2018

Clever!

@Eh2406 Eh2406 force-pushed the masquerade_as_nightly_cargo branch from 50906f1 to 6860dbc Compare June 29, 2018 18:37
@Eh2406 Eh2406 force-pushed the masquerade_as_nightly_cargo branch from 6860dbc to 75bb190 Compare June 29, 2018 19:21
@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 29, 2018

Updated to match your patch, + some additional comments.

@alexcrichton
Copy link
Member

@bors: r+

Thanks so much!

@bors
Copy link
Contributor

bors commented Jun 29, 2018

📌 Commit 75bb190 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jun 29, 2018

⌛ Testing commit 75bb190 with merge 94f7058...

bors added a commit that referenced this pull request Jun 29, 2018
skip test if not nightly; fix for #5648

closes #5648
The alternative was to use `set_var` to emulate `masquerade_as_nightly_cargo` but we worried that it would not get unset correctly. Although I think each test is its own process, so it should work.
@bors
Copy link
Contributor

bors commented Jun 29, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 94f7058 to master...

@bors bors merged commit 75bb190 into rust-lang:master Jun 29, 2018
@Eh2406 Eh2406 deleted the masquerade_as_nightly_cargo branch July 2, 2018 19:49
@ehuss ehuss added this to the 1.29.0 milestone Feb 6, 2022
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 v0.27 tests failed when build rust 1.26.2 on "stable" channel
7 participants