mirror of
https://github.com/rust-lang/cargo.git
synced 2026-05-06 08:36:38 -04:00
Cleanup integration test
This commit is contained in:
+1
-1
Submodule libs/hamcrest-rust updated: 39f0062449...4c7d882455
@@ -1,2 +1,2 @@
|
||||
pub use self::process_builder::process;
|
||||
pub use self::process_builder::{process,ProcessBuilder};
|
||||
pub mod process_builder;
|
||||
|
||||
+28
-2
@@ -1,11 +1,18 @@
|
||||
// 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,
|
||||
@@ -53,6 +60,12 @@ impl ProjectBuilder {
|
||||
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
|
||||
@@ -94,7 +107,7 @@ impl ProjectBuilder {
|
||||
|
||||
// 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 ===
|
||||
@@ -121,3 +134,16 @@ impl<T, E> ErrMsg<T> for Result<T, E> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 =====
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,33 +1,9 @@
|
||||
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 {
|
||||
@@ -49,10 +25,8 @@ 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 {
|
||||
@@ -63,8 +37,7 @@ test!(cargo_compile_with_explicit_manifest_path {
|
||||
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()))
|
||||
@@ -75,9 +48,3 @@ test!(cargo_compile_with_explicit_manifest_path {
|
||||
})
|
||||
|
||||
// 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")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user