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

add a reason to masquerade_as_nightly_cargo so it is searchable #10868

Merged
merged 1 commit into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,14 @@ impl Execs {
p.build_command()
}

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

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

impl ChannelChanger for &mut ProcessBuilder {
fn masquerade_as_nightly_cargo(self) -> Self {
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self {
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
}
}

impl ChannelChanger for snapbox::cmd::Command {
fn masquerade_as_nightly_cargo(self) -> Self {
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self {
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
//! `CliUnstable. Remove the `(unstable)` note in the clap help text if
//! necessary.
//! 2. Remove `masquerade_as_nightly_cargo` from any tests, and remove
//! `cargo-features` from `Cargo.toml` test files if any.
//! `cargo-features` from `Cargo.toml` test files if any. You can
//! quickly find what needs to be removed by searching for the name
//! of the feature, e.g. `print_im_a_teapot`
//! 3. Update the docs in unstable.md to move the section to the bottom
//! and summarize it similar to the other entries. Update the rest of the
//! documentation to add the new feature.
Expand Down
12 changes: 6 additions & 6 deletions src/doc/contrib/src/tests/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ fn <description>() {
#### Testing Nightly Features

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

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

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

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

```rust,ignore
snapbox::cmd::Command::cargo()
.masquerade_as_nightly_cargo()
.masquerade_as_nightly_cargo(&["print-im-a-teapot"])
```

If you are testing a feature that only works on *nightly rustc* (such as
Expand Down
2 changes: 1 addition & 1 deletion tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn enable_build_std(e: &mut Execs, arg: Option<&str>) {
None => "-Zbuild-std".to_string(),
};
e.arg(arg);
e.masquerade_as_nightly_cargo();
e.masquerade_as_nightly_cargo(&["build-std"]);
}

// Helper methods used in the tests below
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/advanced_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn source_config_env() {
let path = paths::root().join("registry");

p.cargo("check -Zadvanced-env")
.masquerade_as_nightly_cargo()
.masquerade_as_nightly_cargo(&["advanced-env"])
.env("CARGO_SOURCE_crates-io_REPLACE_WITH", "my-local-source")
.env("CARGO_SOURCE_my-local-source_LOCAL_REGISTRY", path)
.run();
Expand Down
Loading