Make Project::process return Execs

This commit is contained in:
Dale Wijnand 2018-08-28 22:38:26 +02:00
parent 9ddf75a9da
commit 2554afe764
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
6 changed files with 34 additions and 49 deletions

View File

@ -1,10 +1,9 @@
use std::fs::File;
use std::io::prelude::*;
use support::hamcrest::assert_that;
use support::paths::CargoPathExt;
use support::registry::Package;
use support::{basic_manifest, execs, project};
use support::{basic_manifest, project};
#[test]
fn invalid1() {
@ -423,7 +422,7 @@ fn no_feature_doesnt_build() {
",
dir = p.url()
)).run();
assert_that(p.process(&p.bin("foo")), execs().with_stdout(""));
p.process(&p.bin("foo")).with_stdout("").run();
p.cargo("build --features bar")
.with_stderr(format!(
@ -434,7 +433,7 @@ fn no_feature_doesnt_build() {
",
dir = p.url()
)).run();
assert_that(p.process(&p.bin("foo")), execs().with_stdout("bar\n"));
p.process(&p.bin("foo")).with_stdout("bar\n").run();
}
#[test]
@ -478,7 +477,7 @@ fn default_feature_pulled_in() {
",
dir = p.url()
)).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")
.with_stderr(format!(
@ -488,7 +487,7 @@ fn default_feature_pulled_in() {
",
dir = p.url()
)).run();
assert_that(p.process(&p.bin("foo")), execs().with_stdout(""));
p.process(&p.bin("foo")).with_stdout("").run();
}
#[test]

View File

@ -5,7 +5,7 @@ use support::hamcrest::{assert_that, existing_file};
use support::paths::CargoPathExt;
use support::registry::Package;
use support::sleep_ms;
use support::{basic_manifest, execs, path2url, project};
use support::{basic_manifest, path2url, project};
#[test]
fn modifying_and_moving() {
@ -435,7 +435,7 @@ fn changing_bin_features_caches_targets() {
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
).run();
assert_that(foo_proc("off1"), execs().with_stdout("feature off"));
foo_proc("off1").with_stdout("feature off").run();
p.cargo("build --features foo")
.with_stderr(
@ -444,7 +444,7 @@ fn changing_bin_features_caches_targets() {
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
).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 */
@ -454,7 +454,7 @@ fn changing_bin_features_caches_targets() {
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
).run();
assert_that(foo_proc("off2"), execs().with_stdout("feature off"));
foo_proc("off2").with_stdout("feature off").run();
p.cargo("build --features foo")
.with_stderr(
@ -462,7 +462,7 @@ fn changing_bin_features_caches_targets() {
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
).run();
assert_that(foo_proc("on2"), execs().with_stdout("feature on"));
foo_proc("on2").with_stdout("feature on").run();
}
#[test]

View File

@ -700,7 +700,7 @@ fn two_revs_same_deps() {
foo.cargo("build -v").run();
assert_that(&foo.bin("foo"), existing_file());
assert_that(foo.process(&foo.bin("foo")), execs());
foo.process(&foo.bin("foo")).run();
}
#[test]
@ -1173,7 +1173,7 @@ fn stale_cached_version() {
).build();
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
// us pulling it down.
@ -1223,7 +1223,7 @@ fn stale_cached_version() {
bar = bar.url(),
foo = foo.url()
)).run();
assert_that(foo.process(&foo.bin("foo")), execs());
foo.process(&foo.bin("foo")).run();
}
#[test]

View File

@ -2,8 +2,7 @@ use std::net::TcpListener;
use std::process::Command;
use std::thread;
use support::hamcrest::assert_that;
use support::{cargo_exe, execs, project};
use support::{cargo_exe, project};
#[test]
fn jobserver_exists() {
@ -150,13 +149,11 @@ all:
drop((a2, a3));
});
assert_that(
p.process(make)
.env("CARGO", cargo_exe())
.env("ADDR", addr.to_string())
.arg("-j2"),
execs(),
);
p.process(make)
.env("CARGO", cargo_exe())
.env("ADDR", addr.to_string())
.arg("-j2")
.run();
child.join().unwrap();
}
@ -181,15 +178,15 @@ all:
",
).build();
assert_that(
p.process(make).env("CARGO", cargo_exe()).arg("-j2"),
execs().with_stderr(
p.process(make)
.env("CARGO", cargo_exe())
.arg("-j2")
.with_stderr(
"\
warning: a `-j` argument was passed to Cargo but Cargo is also configured \
with an external jobserver in its environment, ignoring the `-j` parameter
[COMPILING] [..]
[FINISHED] [..]
",
),
);
).run();
}

View File

@ -374,10 +374,10 @@ impl Project {
/// p.process(&p.bin("foo")),
/// 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);
p.cwd(self.root());
p
execs().with_process_builder(p)
}
/// Create a `ProcessBuilder` to run cargo.
@ -385,9 +385,11 @@ impl Project {
/// Example:
/// p.cargo("build --bin foo").run();
pub fn cargo(&self, cmd: &str) -> Execs {
let mut p = self.process(&cargo_exe());
split_and_add_args(&mut p, cmd);
execs().with_process_builder(p)
let mut execs = self.process(&cargo_exe());
if let Some(ref mut p) = execs.process_builder {
split_and_add_args(p, cmd);
}
execs
}
/// 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 {
fn matches(&self, output: Output) -> ham::MatchResult {
self.match_output(&output)

View File

@ -1722,10 +1722,9 @@ fn example_bin_same_name() {
assert_that(&p.bin("foo"), is_not(existing_file()));
assert_that(&p.bin("examples/foo"), existing_file());
assert_that(
p.process(&p.bin("examples/foo")),
execs().with_stdout("example\n"),
);
p.process(&p.bin("examples/foo"))
.with_stdout("example\n")
.run();
p.cargo("run")
.with_stderr(