Cleanup integration test
authorCarl Lerche <me@carllerche.com>
Thu, 20 Mar 2014 22:17:19 +0000 (15:17 -0700)
committerCarl Lerche <me@carllerche.com>
Thu, 20 Mar 2014 22:17:19 +0000 (15:17 -0700)
libs/hamcrest-rust
src/cargo/util/mod.rs
tests/support.rs
tests/test_cargo_compile.rs

index 39f00624492fd648631041eadf1301a08cd2a482..4c7d8824550299dbddf2671515cba05f8d1a1fb2 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 39f00624492fd648631041eadf1301a08cd2a482
+Subproject commit 4c7d8824550299dbddf2671515cba05f8d1a1fb2
index 27784a1ec02593856ff609d79bd4800b101b8291..e4fbd2514acee007cdfcc263989053f6dd89f5a4 100644 (file)
@@ -1,2 +1,2 @@
-pub use self::process_builder::process;
+pub use self::process_builder::{process,ProcessBuilder};
 pub mod process_builder;
index 0c5242dffabaa9a54fcec5f63659e71d9182558a..dfe3497741a318dff65d9c4b93a2d8cc2b8475fc 100644 (file)
@@ -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 =====
+ *
+ */
index 3cdc5630d207008c0392de2520d5ce7a62e30a00..c4769bd323a937b9cf9ed5860db962ead62ccac3 100644 (file)
@@ -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")
-  })
-}