feat(test-support): Expose masquerade_as_nightly_cargo to snapbox users

This commit is contained in:
Ed Page 2022-04-19 10:21:57 -05:00
parent 0d135a0b43
commit 79ef00c60b
2 changed files with 16 additions and 14 deletions

View File

@ -59,6 +59,10 @@ pub mod publish;
pub mod registry; pub mod registry;
pub mod tools; pub mod tools;
pub mod prelude {
pub use crate::ChannelChanger;
}
/* /*
* *
* ===== Builders ===== * ===== Builders =====
@ -1169,12 +1173,19 @@ fn _process(t: &OsStr) -> ProcessBuilder {
p p
} }
pub trait ChannelChanger: Sized { /// Enable nightly features for testing
fn masquerade_as_nightly_cargo(&mut self) -> &mut Self; pub trait ChannelChanger {
fn masquerade_as_nightly_cargo(self) -> Self;
} }
impl ChannelChanger for ProcessBuilder { impl ChannelChanger for &mut ProcessBuilder {
fn masquerade_as_nightly_cargo(&mut self) -> &mut Self { fn masquerade_as_nightly_cargo(self) -> 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 {
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly") self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
} }
} }

View File

@ -1,5 +1,6 @@
use cargo_test_support::cargo_exe; use cargo_test_support::cargo_exe;
use cargo_test_support::compare::assert; use cargo_test_support::compare::assert;
use cargo_test_support::prelude::*;
use cargo_test_support::Project; use cargo_test_support::Project;
pub fn cargo_command() -> snapbox::cmd::Command { pub fn cargo_command() -> snapbox::cmd::Command {
@ -50,16 +51,6 @@ pub fn cargo_command() -> snapbox::cmd::Command {
cmd cmd
} }
pub trait CommandExt {
fn masquerade_as_nightly_cargo(self) -> Self;
}
impl CommandExt for snapbox::cmd::Command {
fn masquerade_as_nightly_cargo(self) -> Self {
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
}
}
fn init_registry() { fn init_registry() {
cargo_test_support::registry::init(); cargo_test_support::registry::init();
add_registry_packages(false); add_registry_packages(false);