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

View File

@ -1,5 +1,6 @@
use cargo_test_support::cargo_exe;
use cargo_test_support::compare::assert;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;
pub fn cargo_command() -> snapbox::cmd::Command {
@ -50,16 +51,6 @@ pub fn cargo_command() -> snapbox::cmd::Command {
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() {
cargo_test_support::registry::init();
add_registry_packages(false);