Skip to content

Commit bd5db30

Browse files
committed
Auto merge of #10868 - Muscraft:add-reason-for-nightly-tests, r=ehuss
add a reason to `masquerade_as_nightly_cargo` so it is searchable When I was working on the stabilization for workspace inheritance, it was very tedious to find all of the places to remove `.masquerade_as_nightly_cargo()`. I [suggested](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/problems.20finding.20.60.2Emasquerade_as_nightly_cargo.28.29.60) to add a reason to `.masquerade_as_nightly_cargo()` so that it would be easier to find all of the places to remove it. By adding the reason it makes it easy to search for all places with the features name. This PR adds the reason(s) to all of the places `.masquerade_as_nightly_cargo()` is called, as well as updates the documentation so it talks about adding a reason when making the call.
2 parents 6fc517b + c239e40 commit bd5db30

File tree

60 files changed

+409
-345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+409
-345
lines changed

crates/cargo-test-support/src/lib.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,14 @@ impl Execs {
806806
p.build_command()
807807
}
808808

809-
pub fn masquerade_as_nightly_cargo(&mut self) -> &mut Self {
809+
/// Enables nightly features for testing
810+
///
811+
/// The list of reasons should be why nightly cargo is needed. If it is
812+
/// becuase of an unstable feature put the name of the feature as the reason,
813+
/// e.g. `&["print-im-a-teapot"]`
814+
pub fn masquerade_as_nightly_cargo(&mut self, reasons: &[&str]) -> &mut Self {
810815
if let Some(ref mut p) = self.process_builder {
811-
p.masquerade_as_nightly_cargo();
816+
p.masquerade_as_nightly_cargo(reasons);
812817
}
813818
self
814819
}
@@ -1139,17 +1144,20 @@ fn _process(t: &OsStr) -> ProcessBuilder {
11391144

11401145
/// Enable nightly features for testing
11411146
pub trait ChannelChanger {
1142-
fn masquerade_as_nightly_cargo(self) -> Self;
1147+
/// The list of reasons should be why nightly cargo is needed. If it is
1148+
/// becuase of an unstable feature put the name of the feature as the reason,
1149+
/// e.g. `&["print-im-a-teapot"]`.
1150+
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self;
11431151
}
11441152

11451153
impl ChannelChanger for &mut ProcessBuilder {
1146-
fn masquerade_as_nightly_cargo(self) -> Self {
1154+
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self {
11471155
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
11481156
}
11491157
}
11501158

11511159
impl ChannelChanger for snapbox::cmd::Command {
1152-
fn masquerade_as_nightly_cargo(self) -> Self {
1160+
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self {
11531161
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
11541162
}
11551163
}

src/cargo/core/features.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@
8686
//! `CliUnstable. Remove the `(unstable)` note in the clap help text if
8787
//! necessary.
8888
//! 2. Remove `masquerade_as_nightly_cargo` from any tests, and remove
89-
//! `cargo-features` from `Cargo.toml` test files if any.
89+
//! `cargo-features` from `Cargo.toml` test files if any. You can
90+
//! quickly find what needs to be removed by searching for the name
91+
//! of the feature, e.g. `print_im_a_teapot`
9092
//! 3. Update the docs in unstable.md to move the section to the bottom
9193
//! and summarize it similar to the other entries. Update the rest of the
9294
//! documentation to add the new feature.

src/doc/contrib/src/tests/writing.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ fn <description>() {
7171
#### Testing Nightly Features
7272

7373
If you are testing a Cargo feature that only works on "nightly" Cargo, then
74-
you need to call `masquerade_as_nightly_cargo` on the process builder like
75-
this:
74+
you need to call `masquerade_as_nightly_cargo` on the process builder and pass
75+
the name of the feature as the reason, like this:
7676

7777
```rust,ignore
78-
p.cargo("build").masquerade_as_nightly_cargo()
78+
p.cargo("build").masquerade_as_nightly_cargo(&["print-im-a-teapot"])
7979
```
8080

8181
If you are testing a feature that only works on *nightly rustc* (such as
@@ -192,12 +192,12 @@ Be sure to check the snapshots to make sure they make sense.
192192
#### Testing Nightly Features
193193

194194
If you are testing a Cargo feature that only works on "nightly" Cargo, then
195-
you need to call `masquerade_as_nightly_cargo` on the process builder like
196-
this:
195+
you need to call `masquerade_as_nightly_cargo` on the process builder and pass
196+
the name of the feature as the reason, like this:
197197

198198
```rust,ignore
199199
snapbox::cmd::Command::cargo()
200-
.masquerade_as_nightly_cargo()
200+
.masquerade_as_nightly_cargo(&["print-im-a-teapot"])
201201
```
202202

203203
If you are testing a feature that only works on *nightly rustc* (such as

tests/build-std/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn enable_build_std(e: &mut Execs, arg: Option<&str>) {
3232
None => "-Zbuild-std".to_string(),
3333
};
3434
e.arg(arg);
35-
e.masquerade_as_nightly_cargo();
35+
e.masquerade_as_nightly_cargo(&["build-std"]);
3636
}
3737

3838
// Helper methods used in the tests below

tests/testsuite/advanced_env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn source_config_env() {
3131
let path = paths::root().join("registry");
3232

3333
p.cargo("check -Zadvanced-env")
34-
.masquerade_as_nightly_cargo()
34+
.masquerade_as_nightly_cargo(&["advanced-env"])
3535
.env("CARGO_SOURCE_crates-io_REPLACE_WITH", "my-local-source")
3636
.env("CARGO_SOURCE_my-local-source_LOCAL_REGISTRY", path)
3737
.run();

0 commit comments

Comments
 (0)