mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Make Project::process return Execs
This commit is contained in:
parent
9ddf75a9da
commit
2554afe764
@ -1,10 +1,9 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
use support::hamcrest::assert_that;
|
|
||||||
use support::paths::CargoPathExt;
|
use support::paths::CargoPathExt;
|
||||||
use support::registry::Package;
|
use support::registry::Package;
|
||||||
use support::{basic_manifest, execs, project};
|
use support::{basic_manifest, project};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid1() {
|
fn invalid1() {
|
||||||
@ -423,7 +422,7 @@ fn no_feature_doesnt_build() {
|
|||||||
",
|
",
|
||||||
dir = p.url()
|
dir = p.url()
|
||||||
)).run();
|
)).run();
|
||||||
assert_that(p.process(&p.bin("foo")), execs().with_stdout(""));
|
p.process(&p.bin("foo")).with_stdout("").run();
|
||||||
|
|
||||||
p.cargo("build --features bar")
|
p.cargo("build --features bar")
|
||||||
.with_stderr(format!(
|
.with_stderr(format!(
|
||||||
@ -434,7 +433,7 @@ fn no_feature_doesnt_build() {
|
|||||||
",
|
",
|
||||||
dir = p.url()
|
dir = p.url()
|
||||||
)).run();
|
)).run();
|
||||||
assert_that(p.process(&p.bin("foo")), execs().with_stdout("bar\n"));
|
p.process(&p.bin("foo")).with_stdout("bar\n").run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -478,7 +477,7 @@ fn default_feature_pulled_in() {
|
|||||||
",
|
",
|
||||||
dir = p.url()
|
dir = p.url()
|
||||||
)).run();
|
)).run();
|
||||||
assert_that(p.process(&p.bin("foo")), execs().with_stdout("bar\n"));
|
p.process(&p.bin("foo")).with_stdout("bar\n").run();
|
||||||
|
|
||||||
p.cargo("build --no-default-features")
|
p.cargo("build --no-default-features")
|
||||||
.with_stderr(format!(
|
.with_stderr(format!(
|
||||||
@ -488,7 +487,7 @@ fn default_feature_pulled_in() {
|
|||||||
",
|
",
|
||||||
dir = p.url()
|
dir = p.url()
|
||||||
)).run();
|
)).run();
|
||||||
assert_that(p.process(&p.bin("foo")), execs().with_stdout(""));
|
p.process(&p.bin("foo")).with_stdout("").run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -5,7 +5,7 @@ use support::hamcrest::{assert_that, existing_file};
|
|||||||
use support::paths::CargoPathExt;
|
use support::paths::CargoPathExt;
|
||||||
use support::registry::Package;
|
use support::registry::Package;
|
||||||
use support::sleep_ms;
|
use support::sleep_ms;
|
||||||
use support::{basic_manifest, execs, path2url, project};
|
use support::{basic_manifest, path2url, project};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn modifying_and_moving() {
|
fn modifying_and_moving() {
|
||||||
@ -435,7 +435,7 @@ fn changing_bin_features_caches_targets() {
|
|||||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
||||||
",
|
",
|
||||||
).run();
|
).run();
|
||||||
assert_that(foo_proc("off1"), execs().with_stdout("feature off"));
|
foo_proc("off1").with_stdout("feature off").run();
|
||||||
|
|
||||||
p.cargo("build --features foo")
|
p.cargo("build --features foo")
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
@ -444,7 +444,7 @@ fn changing_bin_features_caches_targets() {
|
|||||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
||||||
",
|
",
|
||||||
).run();
|
).run();
|
||||||
assert_that(foo_proc("on1"), execs().with_stdout("feature on"));
|
foo_proc("on1").with_stdout("feature on").run();
|
||||||
|
|
||||||
/* Targets should be cached from the first build */
|
/* Targets should be cached from the first build */
|
||||||
|
|
||||||
@ -454,7 +454,7 @@ fn changing_bin_features_caches_targets() {
|
|||||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
||||||
",
|
",
|
||||||
).run();
|
).run();
|
||||||
assert_that(foo_proc("off2"), execs().with_stdout("feature off"));
|
foo_proc("off2").with_stdout("feature off").run();
|
||||||
|
|
||||||
p.cargo("build --features foo")
|
p.cargo("build --features foo")
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
@ -462,7 +462,7 @@ fn changing_bin_features_caches_targets() {
|
|||||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
||||||
",
|
",
|
||||||
).run();
|
).run();
|
||||||
assert_that(foo_proc("on2"), execs().with_stdout("feature on"));
|
foo_proc("on2").with_stdout("feature on").run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -700,7 +700,7 @@ fn two_revs_same_deps() {
|
|||||||
|
|
||||||
foo.cargo("build -v").run();
|
foo.cargo("build -v").run();
|
||||||
assert_that(&foo.bin("foo"), existing_file());
|
assert_that(&foo.bin("foo"), existing_file());
|
||||||
assert_that(foo.process(&foo.bin("foo")), execs());
|
foo.process(&foo.bin("foo")).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1173,7 +1173,7 @@ fn stale_cached_version() {
|
|||||||
).build();
|
).build();
|
||||||
|
|
||||||
foo.cargo("build").run();
|
foo.cargo("build").run();
|
||||||
assert_that(foo.process(&foo.bin("foo")), execs());
|
foo.process(&foo.bin("foo")).run();
|
||||||
|
|
||||||
// Update the repo, and simulate someone else updating the lockfile and then
|
// Update the repo, and simulate someone else updating the lockfile and then
|
||||||
// us pulling it down.
|
// us pulling it down.
|
||||||
@ -1223,7 +1223,7 @@ fn stale_cached_version() {
|
|||||||
bar = bar.url(),
|
bar = bar.url(),
|
||||||
foo = foo.url()
|
foo = foo.url()
|
||||||
)).run();
|
)).run();
|
||||||
assert_that(foo.process(&foo.bin("foo")), execs());
|
foo.process(&foo.bin("foo")).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -2,8 +2,7 @@ use std::net::TcpListener;
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use support::hamcrest::assert_that;
|
use support::{cargo_exe, project};
|
||||||
use support::{cargo_exe, execs, project};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn jobserver_exists() {
|
fn jobserver_exists() {
|
||||||
@ -150,13 +149,11 @@ all:
|
|||||||
drop((a2, a3));
|
drop((a2, a3));
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_that(
|
p.process(make)
|
||||||
p.process(make)
|
.env("CARGO", cargo_exe())
|
||||||
.env("CARGO", cargo_exe())
|
.env("ADDR", addr.to_string())
|
||||||
.env("ADDR", addr.to_string())
|
.arg("-j2")
|
||||||
.arg("-j2"),
|
.run();
|
||||||
execs(),
|
|
||||||
);
|
|
||||||
child.join().unwrap();
|
child.join().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,15 +178,15 @@ all:
|
|||||||
",
|
",
|
||||||
).build();
|
).build();
|
||||||
|
|
||||||
assert_that(
|
p.process(make)
|
||||||
p.process(make).env("CARGO", cargo_exe()).arg("-j2"),
|
.env("CARGO", cargo_exe())
|
||||||
execs().with_stderr(
|
.arg("-j2")
|
||||||
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
warning: a `-j` argument was passed to Cargo but Cargo is also configured \
|
warning: a `-j` argument was passed to Cargo but Cargo is also configured \
|
||||||
with an external jobserver in its environment, ignoring the `-j` parameter
|
with an external jobserver in its environment, ignoring the `-j` parameter
|
||||||
[COMPILING] [..]
|
[COMPILING] [..]
|
||||||
[FINISHED] [..]
|
[FINISHED] [..]
|
||||||
",
|
",
|
||||||
),
|
).run();
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -374,10 +374,10 @@ impl Project {
|
|||||||
/// p.process(&p.bin("foo")),
|
/// p.process(&p.bin("foo")),
|
||||||
/// execs().with_stdout("bar\n"),
|
/// execs().with_stdout("bar\n"),
|
||||||
/// );
|
/// );
|
||||||
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> ProcessBuilder {
|
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> Execs {
|
||||||
let mut p = ::support::process(program);
|
let mut p = ::support::process(program);
|
||||||
p.cwd(self.root());
|
p.cwd(self.root());
|
||||||
p
|
execs().with_process_builder(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `ProcessBuilder` to run cargo.
|
/// Create a `ProcessBuilder` to run cargo.
|
||||||
@ -385,9 +385,11 @@ impl Project {
|
|||||||
/// Example:
|
/// Example:
|
||||||
/// p.cargo("build --bin foo").run();
|
/// p.cargo("build --bin foo").run();
|
||||||
pub fn cargo(&self, cmd: &str) -> Execs {
|
pub fn cargo(&self, cmd: &str) -> Execs {
|
||||||
let mut p = self.process(&cargo_exe());
|
let mut execs = self.process(&cargo_exe());
|
||||||
split_and_add_args(&mut p, cmd);
|
if let Some(ref mut p) = execs.process_builder {
|
||||||
execs().with_process_builder(p)
|
split_and_add_args(p, cmd);
|
||||||
|
}
|
||||||
|
execs
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the contents of `Cargo.lock`.
|
/// Returns the contents of `Cargo.lock`.
|
||||||
@ -1272,18 +1274,6 @@ impl<'t> ham::Matcher<ProcessBuilder> for &'t mut Execs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ham::Matcher<&'a mut ProcessBuilder> for Execs {
|
|
||||||
fn matches(&self, process: &'a mut ProcessBuilder) -> ham::MatchResult {
|
|
||||||
self.match_process(process)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 't> ham::Matcher<&'a mut ProcessBuilder> for &'t mut Execs {
|
|
||||||
fn matches(&self, process: &'a mut ProcessBuilder) -> ham::MatchResult {
|
|
||||||
self.match_process(process)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ham::Matcher<Output> for Execs {
|
impl ham::Matcher<Output> for Execs {
|
||||||
fn matches(&self, output: Output) -> ham::MatchResult {
|
fn matches(&self, output: Output) -> ham::MatchResult {
|
||||||
self.match_output(&output)
|
self.match_output(&output)
|
||||||
|
@ -1722,10 +1722,9 @@ fn example_bin_same_name() {
|
|||||||
assert_that(&p.bin("foo"), is_not(existing_file()));
|
assert_that(&p.bin("foo"), is_not(existing_file()));
|
||||||
assert_that(&p.bin("examples/foo"), existing_file());
|
assert_that(&p.bin("examples/foo"), existing_file());
|
||||||
|
|
||||||
assert_that(
|
p.process(&p.bin("examples/foo"))
|
||||||
p.process(&p.bin("examples/foo")),
|
.with_stdout("example\n")
|
||||||
execs().with_stdout("example\n"),
|
.run();
|
||||||
);
|
|
||||||
|
|
||||||
p.cargo("run")
|
p.cargo("run")
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user