// use std::io::fs::{mkdir_recursive,rmdir_recursive};
use std::io::fs;
-use std::os::tmpdir;
+use std::os;
use std::path::{Path};
+use cargo::util::{process,ProcessBuilder};
static CARGO_INTEGRATION_TEST_DIR : &'static str = "cargo-integration-tests";
static MKDIR_PERM : u32 = 0o755;
+/*
+ *
+ * ===== Builders =====
+ *
+ */
+
#[deriving(Eq,Clone)]
struct FileBuilder {
path: Path,
self.root.clone()
}
+ pub fn cargo_process(&self, program: &str) -> ProcessBuilder {
+ process(program)
+ .cwd(self.root())
+ .extra_path(cargo_dir())
+ }
+
pub fn file(mut self, path: &str, body: &str) -> ProjectBuilder {
self.files.push(FileBuilder::new(self.root.join(path), body));
self
// Generates a project layout
pub fn project(name: &str) -> ProjectBuilder {
- ProjectBuilder::new(name, tmpdir().join(CARGO_INTEGRATION_TEST_DIR))
+ ProjectBuilder::new(name, os::tmpdir().join(CARGO_INTEGRATION_TEST_DIR))
}
// === Helpers ===
}
}
}
+
+// Path to cargo executables
+pub fn cargo_dir() -> ~str {
+ os::getenv("CARGO_BIN_PATH").unwrap_or_else(|| {
+ fail!("CARGO_BIN_PATH wasn't set. Cannot continue running test")
+ })
+}
+
+/*
+ *
+ * ===== Matchers =====
+ *
+ */
use std;
use support::project;
-use hamcrest::{SelfDescribing,Description,Matcher,assert_that};
+use hamcrest::{assert_that,existing_file};
use cargo;
-#[deriving(Clone,Eq)]
-pub struct ExistingFile;
-
-impl SelfDescribing for ExistingFile {
- fn describe_to(&self, desc: &mut Description) {
- desc.append_text("an existing file");
- }
-}
-
-impl Matcher<Path> for ExistingFile {
- fn matches(&self, actual: &Path) -> bool {
- actual.exists()
- }
-
- fn describe_mismatch(&self, actual: &Path, desc: &mut Description) {
- desc.append_text(format!("`{}` was missing", actual.display()));
- }
-}
-
-pub fn existing_file() -> ExistingFile {
- ExistingFile
-}
-
fn setup() {
-
}
test!(cargo_compile_with_explicit_manifest_path {
}"#)
.build();
- let output = cargo::util::process("cargo-compile")
+ let output = p.cargo_process("cargo-compile")
.args([~"--manifest-path", ~"Cargo.toml"])
- .extra_path(target_path())
- .cwd(p.root())
.exec_with_output();
match output {
Err(e) => println!("err: {}", e)
}
- assert_that(p.root().join("target/foo/bar"), existing_file());
- assert!(p.root().join("target/foo").exists(), "the executable exists");
+ assert_that(&p.root().join("target/foo"), existing_file());
let o = cargo::util::process("foo")
.extra_path(format!("{}", p.root().join("target").display()))
})
// test!(compiling_project_with_invalid_manifest)
-
-fn target_path() -> ~str {
- std::os::getenv("CARGO_BIN_PATH").unwrap_or_else(|| {
- fail!("CARGO_BIN_PATH wasn't set. Cannot continue running test")
- })
-}