}
pub fn cargo_process(&self, program: &str) -> ProcessBuilder {
- process(program)
- .cwd(self.root())
- .extra_path(cargo_dir())
+ self.build();
+
+ process(program)
+ .cwd(self.root())
+ .extra_path(cargo_dir())
}
pub fn file<B: BytesContainer>(mut self, path: B, body: &str) -> ProjectBuilder {
}
// TODO: return something different than a ProjectBuilder
- pub fn build(self) -> ProjectBuilder {
+ pub fn build<'a>(&'a self) -> &'a ProjectBuilder {
match self.build_with_result() {
Err(e) => fail!(e),
_ => return self
match res {
Ok(out) => self.match_output(&out),
- Err(_) => Err("could not exec process".to_owned())
+ Err(_) => Err(format!("could not exec process {}", process))
}
}
}
use support::{ResultTest,project,execs};
use hamcrest::{assert_that,existing_file};
use cargo;
+use cargo::util::process;
fn setup() {
}
name = "foo"
"#)
- .file("src/foo.rs", r#"
- fn main() {
- println!("i am foo");
- }
- "#)
- .build();
-
- p.cargo_process("cargo-compile")
- .args([])
- .exec_with_output()
- .assert();
+ .file("src/foo.rs", main_file(r#""i am foo""#, []));
+ assert_that(p.cargo_process("cargo-compile"), execs());
assert_that(&p.root().join("target/foo"), existing_file());
+ let target = p.root().join("target");
+
assert_that(
- cargo::util::process("foo").extra_path(p.root().join("target")),
+ process("foo").extra_path(target),
execs().with_stdout("i am foo\n"));
})
+fn main_file(println: &str, deps: &[&str]) -> ~str {
+ let mut buf = StrBuf::new();
+
+ for dep in deps.iter() {
+ buf.push_str(format!("extern crate {};\n", dep));
+ }
+
+ buf.push_str("fn main() { println!(");
+ buf.push_str(println);
+ buf.push_str("); }\n");
+
+ buf.to_owned()
+}
+
test!(cargo_compile_with_nested_deps {
let mut p = project("foo");
let bar = p.root().join("bar");
name = "foo"
"#)
- .file("src/foo.rs", r#"
- extern crate bar;
-
- fn main() {
- println!("{}", bar::gimme());
- }
- "#)
+ .file("src/foo.rs", main_file(r#""{}", bar::gimme()"#, ["bar"]))
.file("bar/Cargo.toml", r#"
[project]
pub fn gimme() -> ~str {
"test passed".to_owned()
}
- "#)
- .build();
+ "#);
p.cargo_process("cargo-compile")
.exec_with_output()