mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
Wrap ProcessBuilder in Execs & make .cargo return that
This commit is contained in:
parent
76e840bb45
commit
b5ee3635ef
@ -1,4 +1,3 @@
|
||||
use support::ChannelChanger;
|
||||
use support::registry::{self, alt_api_path, Package};
|
||||
use support::{basic_manifest, execs, paths, project};
|
||||
use support::hamcrest::assert_that;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::str;
|
||||
|
||||
use cargo::util::process;
|
||||
use support::{is_nightly, ChannelChanger};
|
||||
use support::is_nightly;
|
||||
use support::paths::CargoPathExt;
|
||||
use support::{basic_manifest, basic_bin_manifest, basic_lib_manifest, execs, project};
|
||||
use support::hamcrest::{assert_that, existing_file};
|
||||
|
@ -3,13 +3,12 @@ use std::fs::{self, File};
|
||||
use std::io::prelude::*;
|
||||
|
||||
use cargo::util::paths::dylib_path_envvar;
|
||||
use cargo::util::{process, ProcessBuilder};
|
||||
use cargo::util::process;
|
||||
use support::{basic_manifest, basic_bin_manifest, basic_lib_manifest, is_nightly, rustc_host, sleep_ms};
|
||||
use support::paths::{root, CargoPathExt};
|
||||
use support::ProjectBuilder;
|
||||
use support::{execs, main_file, project};
|
||||
use support::{Execs, execs, main_file, project};
|
||||
use support::registry::Package;
|
||||
use support::ChannelChanger;
|
||||
use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
|
||||
|
||||
#[test]
|
||||
@ -1553,15 +1552,15 @@ fn crate_authors_env_vars() {
|
||||
}
|
||||
|
||||
// The tester may already have LD_LIBRARY_PATH=::/foo/bar which leads to a false positive error
|
||||
fn setenv_for_removing_empty_component(mut p: ProcessBuilder) -> ProcessBuilder {
|
||||
fn setenv_for_removing_empty_component(mut execs: Execs) -> Execs {
|
||||
let v = dylib_path_envvar();
|
||||
if let Ok(search_path) = env::var(v) {
|
||||
let new_search_path = env::join_paths(
|
||||
env::split_paths(&search_path).filter(|e| !e.as_os_str().is_empty()),
|
||||
).expect("join_paths");
|
||||
p.env(v, new_search_path); // build_command() will override LD_LIBRARY_PATH accordingly
|
||||
execs.env(v, new_search_path); // build_command() will override LD_LIBRARY_PATH accordingly
|
||||
}
|
||||
p
|
||||
execs
|
||||
}
|
||||
|
||||
// Regression test for #4277
|
||||
|
@ -1,4 +1,3 @@
|
||||
use support::ChannelChanger;
|
||||
use support::{basic_manifest, basic_bin_manifest, execs, main_file, project};
|
||||
use support::hamcrest::{assert_that, existing_file, is_not};
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
use support::ChannelChanger;
|
||||
use support::{execs, project, publish};
|
||||
use support::hamcrest::assert_that;
|
||||
|
||||
|
@ -3,7 +3,7 @@ use std::str;
|
||||
use std::fs::{self, File};
|
||||
use std::io::Read;
|
||||
|
||||
use support::{is_nightly, rustc_host, ChannelChanger};
|
||||
use support::{is_nightly, rustc_host};
|
||||
use support::{basic_manifest, basic_lib_manifest, execs, git, project, path2url};
|
||||
use support::paths::CargoPathExt;
|
||||
use support::registry::Package;
|
||||
|
@ -1,5 +1,4 @@
|
||||
use support::{basic_lib_manifest, is_nightly, execs, project};
|
||||
use support::ChannelChanger;
|
||||
use support::hamcrest::assert_that;
|
||||
|
||||
#[test]
|
||||
|
@ -3,7 +3,6 @@ use std::io::prelude::*;
|
||||
|
||||
use support::paths::CargoPathExt;
|
||||
use support::{basic_manifest, execs, project};
|
||||
use support::ChannelChanger;
|
||||
use support::hamcrest::assert_that;
|
||||
use support::registry::Package;
|
||||
|
||||
|
@ -4,7 +4,7 @@ use git2;
|
||||
|
||||
use support::git;
|
||||
use support::{basic_manifest, execs, project};
|
||||
use support::{is_nightly, ChannelChanger};
|
||||
use support::is_nightly;
|
||||
use support::hamcrest::assert_that;
|
||||
|
||||
#[test]
|
||||
|
@ -3,7 +3,6 @@ use std::io::prelude::*;
|
||||
|
||||
use support::registry::Package;
|
||||
use support::{basic_manifest, execs, paths, project, ProjectBuilder};
|
||||
use support::ChannelChanger;
|
||||
use support::hamcrest::{assert_that, existing_file, is_not};
|
||||
|
||||
#[test]
|
||||
|
@ -11,7 +11,6 @@ use cargo::util::process;
|
||||
use support::sleep_ms;
|
||||
use support::paths::{self, CargoPathExt};
|
||||
use support::{basic_manifest, basic_lib_manifest, execs, git, main_file, project, path2url};
|
||||
use support::ChannelChanger;
|
||||
use support::hamcrest::{assert_that, existing_file};
|
||||
|
||||
#[test]
|
||||
|
@ -3,7 +3,7 @@ use serde_json;
|
||||
use std::str;
|
||||
use support::{
|
||||
basic_lib_manifest, basic_manifest, execs, hamcrest::assert_that, project, registry::Package,
|
||||
rustc_host, ChannelChanger, Project,
|
||||
rustc_host, Project,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use support::registry::Package;
|
||||
use support::{basic_bin_manifest, basic_lib_manifest, execs, main_file, project, ChannelChanger};
|
||||
use support::{basic_bin_manifest, basic_lib_manifest, execs, main_file, project};
|
||||
use support::hamcrest::assert_that;
|
||||
|
||||
#[test]
|
||||
|
@ -4,7 +4,7 @@ use std::env;
|
||||
|
||||
use support::hamcrest::assert_that;
|
||||
|
||||
use support::{process, sleep_ms, ChannelChanger};
|
||||
use support::{process, sleep_ms};
|
||||
use support::{basic_manifest, execs, project};
|
||||
|
||||
#[test]
|
||||
|
@ -4,7 +4,7 @@ use std::io::prelude::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use git2;
|
||||
use support::{cargo_process, sleep_ms, ChannelChanger};
|
||||
use support::{cargo_process, sleep_ms};
|
||||
use support::{basic_manifest, execs, git, is_nightly, paths, project, registry, path2url};
|
||||
use support::registry::Package;
|
||||
use flate2::read::GzDecoder;
|
||||
|
@ -1,5 +1,4 @@
|
||||
use support::{basic_lib_manifest, execs, paths, project};
|
||||
use support::ChannelChanger;
|
||||
use support::hamcrest::assert_that;
|
||||
|
||||
#[test]
|
||||
|
@ -1,5 +1,4 @@
|
||||
use support::{basic_manifest, basic_lib_manifest, execs, project};
|
||||
use support::ChannelChanger;
|
||||
use support::hamcrest::assert_that;
|
||||
|
||||
#[test]
|
||||
|
@ -2,7 +2,6 @@ use std::io::prelude::*;
|
||||
use std::fs::{self, File};
|
||||
use std::io::SeekFrom;
|
||||
|
||||
use support::ChannelChanger;
|
||||
use support::git::repo;
|
||||
use support::paths;
|
||||
use support::{basic_manifest, execs, project, publish};
|
||||
|
@ -750,7 +750,6 @@ fn update_lockfile() {
|
||||
|
||||
#[test]
|
||||
fn update_offline() {
|
||||
use support::ChannelChanger;
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
|
@ -1,4 +1,3 @@
|
||||
use support::ChannelChanger;
|
||||
use support::git;
|
||||
use support::paths;
|
||||
use support::registry::Package;
|
||||
|
@ -8,7 +8,6 @@ use cargo::core::{Dependency, PackageId, Registry, Summary, enable_nightly_featu
|
||||
use cargo::util::{CargoResult, Config, ToUrl};
|
||||
use cargo::core::resolver::{self, Method};
|
||||
|
||||
use support::ChannelChanger;
|
||||
use support::{execs, project};
|
||||
use support::registry::Package;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use cargo::util::paths::dylib_path_envvar;
|
||||
use support::{self, ChannelChanger};
|
||||
use support;
|
||||
use support::{basic_bin_manifest, basic_lib_manifest, execs, project, Project, path2url};
|
||||
use support::hamcrest::{assert_that, existing_file};
|
||||
|
||||
|
@ -118,12 +118,12 @@ use std::fs;
|
||||
use std::io::prelude::*;
|
||||
use std::os;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Output;
|
||||
use std::process::{Command, Output};
|
||||
use std::str;
|
||||
use std::time::Duration;
|
||||
use std::usize;
|
||||
|
||||
use cargo::util::{ProcessBuilder, ProcessError, Rustc};
|
||||
use cargo::util::{CargoResult, ProcessBuilder, ProcessError, Rustc};
|
||||
use cargo;
|
||||
use serde_json::{self, Value};
|
||||
use url::Url;
|
||||
@ -384,10 +384,10 @@ impl Project {
|
||||
/// Arguments can be separated by spaces.
|
||||
/// Example:
|
||||
/// assert_that(p.cargo("build --bin foo"), execs());
|
||||
pub fn cargo(&self, cmd: &str) -> ProcessBuilder {
|
||||
pub fn cargo(&self, cmd: &str) -> Execs {
|
||||
let mut p = self.process(&cargo_exe());
|
||||
split_and_add_args(&mut p, cmd);
|
||||
p
|
||||
execs().with_process_builder(p)
|
||||
}
|
||||
|
||||
/// Returns the contents of `Cargo.lock`.
|
||||
@ -526,6 +526,8 @@ pub fn cargo_exe() -> PathBuf {
|
||||
#[must_use]
|
||||
#[derive(Clone)]
|
||||
pub struct Execs {
|
||||
ran: bool,
|
||||
process_builder: Option<ProcessBuilder>,
|
||||
expect_stdout: Option<String>,
|
||||
expect_stdin: Option<String>,
|
||||
expect_stderr: Option<String>,
|
||||
@ -543,6 +545,11 @@ pub struct Execs {
|
||||
}
|
||||
|
||||
impl Execs {
|
||||
pub fn with_process_builder(mut self, p: ProcessBuilder) -> Execs {
|
||||
self.process_builder = Some(p);
|
||||
self
|
||||
}
|
||||
|
||||
/// Verify that stdout is equal to the given lines.
|
||||
/// See `lines_match` for supported patterns.
|
||||
pub fn with_stdout<S: ToString>(&mut self, expected: S) -> &mut Self {
|
||||
@ -674,6 +681,59 @@ impl Execs {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut Self {
|
||||
if let Some(ref mut p) = self.process_builder {
|
||||
p.arg(arg);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut Self {
|
||||
if let Some(ref mut p) = self.process_builder {
|
||||
p.cwd(path);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut Self {
|
||||
if let Some(ref mut p) = self.process_builder {
|
||||
p.env(key, val);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn env_remove(&mut self, key: &str) -> &mut Self {
|
||||
if let Some(ref mut p) = self.process_builder {
|
||||
p.env_remove(key);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn exec_with_output(&self) -> CargoResult<Output> {
|
||||
// TODO avoid unwrap
|
||||
let p = (&self.process_builder).clone().unwrap();
|
||||
p.exec_with_output()
|
||||
}
|
||||
|
||||
pub fn build_command(&self) -> Command {
|
||||
// TODO avoid unwrap
|
||||
let p = (&self.process_builder).clone().unwrap();
|
||||
p.build_command()
|
||||
}
|
||||
|
||||
pub fn masquerade_as_nightly_cargo(&mut self) -> &mut Self {
|
||||
if let Some(ref mut p) = self.process_builder {
|
||||
p.masquerade_as_nightly_cargo();
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn run(&mut self) {
|
||||
self.ran = true;
|
||||
let p = (&self.process_builder).clone().unwrap();
|
||||
ham::assert_that(p, self)
|
||||
}
|
||||
|
||||
fn match_process(&self, process: &ProcessBuilder) -> ham::MatchResult {
|
||||
println!("running {}", process);
|
||||
@ -1052,6 +1112,15 @@ impl Execs {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Execs {
|
||||
fn drop(&mut self) {
|
||||
if !self.ran {
|
||||
// TODO: Re-enable when everything goes through Execs#run
|
||||
// panic!("forgot to run this command");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
enum MatchKind {
|
||||
Exact,
|
||||
@ -1187,6 +1256,40 @@ impl fmt::Debug for Execs {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this temporary matcher while transitioning off of assert_that
|
||||
impl ham::Matcher<Execs> for Execs {
|
||||
fn matches(&self, mut execs: Execs) -> ham::MatchResult {
|
||||
self.matches(&mut execs)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this temporary matcher while transitioning off of assert_that
|
||||
impl<'a> ham::Matcher<&'a mut Execs> for Execs {
|
||||
fn matches(&self, execs: &'a mut Execs) -> ham::MatchResult {
|
||||
// TODO: avoid unwrap
|
||||
let mut p = (&execs.process_builder).clone().unwrap();
|
||||
self.matches(&mut p)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this temporary matcher while transitioning off of assert_that
|
||||
impl<'t> ham::Matcher<Execs> for &'t mut Execs {
|
||||
fn matches(&self, execs: Execs) -> ham::MatchResult {
|
||||
// TODO: avoid unwrap
|
||||
let mut p = (&execs.process_builder).clone().unwrap();
|
||||
self.matches(&mut p)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this temporary matcher while transitioning off of assert_that
|
||||
impl<'a, 't> ham::Matcher<&'a mut Execs> for &'t mut Execs {
|
||||
fn matches(&self, execs: &'a mut Execs) -> ham::MatchResult {
|
||||
// TODO: avoid unwrap
|
||||
let mut p = (&execs.process_builder).clone().unwrap();
|
||||
self.matches(&mut p)
|
||||
}
|
||||
}
|
||||
|
||||
impl ham::Matcher<ProcessBuilder> for Execs {
|
||||
fn matches(&self, process: ProcessBuilder) -> ham::MatchResult {
|
||||
self.match_process(&process)
|
||||
@ -1225,6 +1328,8 @@ impl<'t> ham::Matcher<Output> for &'t mut Execs {
|
||||
|
||||
pub fn execs() -> Execs {
|
||||
Execs {
|
||||
ran: false,
|
||||
process_builder: None,
|
||||
expect_stdout: None,
|
||||
expect_stderr: None,
|
||||
expect_stdin: None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user