Skip to content

Commit 79ef00c

Browse files
committed
feat(test-support): Expose masquerade_as_nightly_cargo to snapbox users
1 parent 0d135a0 commit 79ef00c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub mod publish;
5959
pub mod registry;
6060
pub mod tools;
6161

62+
pub mod prelude {
63+
pub use crate::ChannelChanger;
64+
}
65+
6266
/*
6367
*
6468
* ===== Builders =====
@@ -1169,12 +1173,19 @@ fn _process(t: &OsStr) -> ProcessBuilder {
11691173
p
11701174
}
11711175

1172-
pub trait ChannelChanger: Sized {
1173-
fn masquerade_as_nightly_cargo(&mut self) -> &mut Self;
1176+
/// Enable nightly features for testing
1177+
pub trait ChannelChanger {
1178+
fn masquerade_as_nightly_cargo(self) -> Self;
1179+
}
1180+
1181+
impl ChannelChanger for &mut ProcessBuilder {
1182+
fn masquerade_as_nightly_cargo(self) -> Self {
1183+
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
1184+
}
11741185
}
11751186

1176-
impl ChannelChanger for ProcessBuilder {
1177-
fn masquerade_as_nightly_cargo(&mut self) -> &mut Self {
1187+
impl ChannelChanger for snapbox::cmd::Command {
1188+
fn masquerade_as_nightly_cargo(self) -> Self {
11781189
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
11791190
}
11801191
}

tests/testsuite/cargo_add.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cargo_test_support::cargo_exe;
22
use cargo_test_support::compare::assert;
3+
use cargo_test_support::prelude::*;
34
use cargo_test_support::Project;
45

56
pub fn cargo_command() -> snapbox::cmd::Command {
@@ -50,16 +51,6 @@ pub fn cargo_command() -> snapbox::cmd::Command {
5051
cmd
5152
}
5253

53-
pub trait CommandExt {
54-
fn masquerade_as_nightly_cargo(self) -> Self;
55-
}
56-
57-
impl CommandExt for snapbox::cmd::Command {
58-
fn masquerade_as_nightly_cargo(self) -> Self {
59-
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
60-
}
61-
}
62-
6354
fn init_registry() {
6455
cargo_test_support::registry::init();
6556
add_registry_packages(false);

0 commit comments

Comments
 (0)