about summary refs log tree commit diff
path: root/src/librustpkg/tests.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-05-05 15:11:04 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-05-05 15:11:04 -0400
commit4300d4d2fa9d35ac73742c7d815ee157ce0f9c17 (patch)
tree9e5db5a04493a573f280b2c8863d0eaf0ca47c0d /src/librustpkg/tests.rs
parent6cb273ed4efb6724b1c713c3ac35d14e52999fb1 (diff)
parent063851ffa1b8388a0b70446c0209af16264e8181 (diff)
downloadrust-4300d4d2fa9d35ac73742c7d815ee157ce0f9c17.tar.gz
rust-4300d4d2fa9d35ac73742c7d815ee157ce0f9c17.zip
Merge remote-tracking branch 'mozilla/incoming' into issue-5910-dyna-freeze
Conflicts:
	src/libcore/core.rc
	src/libcore/hashmap.rs
	src/libcore/num/f32.rs
	src/libcore/num/f64.rs
	src/libcore/num/float.rs
	src/libcore/num/int-template.rs
	src/libcore/num/num.rs
	src/libcore/num/strconv.rs
	src/libcore/num/uint-template.rs
	src/libcore/ops.rs
	src/libcore/os.rs
	src/libcore/prelude.rs
	src/libcore/rt/mod.rs
	src/libcore/unstable/lang.rs
	src/librustc/driver/session.rs
	src/librustc/middle/astencode.rs
	src/librustc/middle/borrowck/check_loans.rs
	src/librustc/middle/borrowck/gather_loans.rs
	src/librustc/middle/borrowck/loan.rs
	src/librustc/middle/borrowck/preserve.rs
	src/librustc/middle/liveness.rs
	src/librustc/middle/mem_categorization.rs
	src/librustc/middle/region.rs
	src/librustc/middle/trans/base.rs
	src/librustc/middle/trans/inline.rs
	src/librustc/middle/trans/reachable.rs
	src/librustc/middle/typeck/check/_match.rs
	src/librustc/middle/typeck/check/regionck.rs
	src/librustc/util/ppaux.rs
	src/libstd/arena.rs
	src/libstd/ebml.rs
	src/libstd/json.rs
	src/libstd/serialize.rs
	src/libstd/std.rc
	src/libsyntax/ast_map.rs
	src/libsyntax/parse/parser.rs
	src/test/compile-fail/borrowck-uniq-via-box.rs
	src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs
	src/test/run-pass/borrowck-nested-calls.rs
Diffstat (limited to 'src/librustpkg/tests.rs')
-rw-r--r--src/librustpkg/tests.rs118
1 files changed, 95 insertions, 23 deletions
diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs
index bcee2992e5a..486e2959e9e 100644
--- a/src/librustpkg/tests.rs
+++ b/src/librustpkg/tests.rs
@@ -17,10 +17,12 @@ use std::tempfile::mkdtemp;
 use util::{PkgId, default_version};
 use path_util::{target_executable_in_workspace, target_library_in_workspace,
                target_test_in_workspace, target_bench_in_workspace,
-               make_dir_rwx};
+               make_dir_rwx, u_rwx};
+use core::os::mkdir_recursive;
 
-fn fake_ctxt() -> Ctx {
+fn fake_ctxt(sysroot_opt: Option<@Path>) -> Ctx {
     Ctx {
+        sysroot_opt: sysroot_opt,
         json: false,
         dep_cache: @mut HashMap::new()
     }
@@ -33,8 +35,34 @@ fn fake_pkg() -> PkgId {
     }
 }
 
-fn mk_temp_workspace() -> Path {
-    mkdtemp(&os::tmpdir(), "test").expect("couldn't create temp dir")
+fn remote_pkg() -> PkgId {
+    PkgId {
+        path: Path(~"github.com/catamorphism/test-pkg"),
+        version: default_version()
+    }
+}
+
+fn writeFile(file_path: &Path, contents: ~str) {
+    let out: @io::Writer =
+        result::get(&io::file_writer(file_path,
+                                     ~[io::Create, io::Truncate]));
+    out.write_line(contents);
+}
+
+fn mk_temp_workspace(short_name: &Path) -> Path {
+    let workspace = mkdtemp(&os::tmpdir(), "test").expect("couldn't create temp dir");
+    let package_dir = workspace.push(~"src").push_rel(short_name);
+    assert!(mkdir_recursive(&package_dir, u_rwx));
+    // Create main, lib, test, and bench files
+    writeFile(&package_dir.push(~"main.rs"),
+              ~"fn main() { let _x = (); }");
+    writeFile(&package_dir.push(~"lib.rs"),
+              ~"pub fn f() { let _x = (); }");
+    writeFile(&package_dir.push(~"test.rs"),
+              ~"#[test] pub fn f() { (); }");
+    writeFile(&package_dir.push(~"bench.rs"),
+              ~"#[bench] pub fn f() { (); }");
+    workspace
 }
 
 fn is_rwx(p: &Path) -> bool {
@@ -42,60 +70,104 @@ fn is_rwx(p: &Path) -> bool {
 
     match p.get_mode() {
         None => return false,
-        Some(m) => {
+        Some(m) =>
             ((m & S_IRUSR as uint) == S_IRUSR as uint
             && (m & S_IWUSR as uint) == S_IWUSR as uint
             && (m & S_IXUSR as uint) == S_IXUSR as uint)
-        }
     }
 }
 
+#[cfg(test)]
+fn test_sysroot() -> Path {
+    // Totally gross hack but it's just for test cases.
+    // Infer the sysroot from the exe name and tack "stage2"
+    // onto it. (Did I mention it was a gross hack?)
+    let self_path = os::self_exe_path().expect("Couldn't get self_exe path");
+    self_path.pop().push("stage2")
+}
+
 #[test]
 fn test_make_dir_rwx() {
     let temp = &os::tmpdir();
     let dir = temp.push(~"quux");
-    let _ = os::remove_dir(&dir);
+    assert!(!os::path_exists(&dir) ||
+            os::remove_dir_recursive(&dir));
+    debug!("Trying to make %s", dir.to_str());
     assert!(make_dir_rwx(&dir));
     assert!(os::path_is_dir(&dir));
     assert!(is_rwx(&dir));
-    assert!(os::remove_dir(&dir));
+    assert!(os::remove_dir_recursive(&dir));
 }
 
 #[test]
-#[ignore(reason = "install not yet implemented")]
 fn test_install_valid() {
-    let ctxt = fake_ctxt();
+    let sysroot = test_sysroot();
+    debug!("sysroot = %s", sysroot.to_str());
+    let ctxt = fake_ctxt(Some(@sysroot));
     let temp_pkg_id = fake_pkg();
-    let temp_workspace = mk_temp_workspace();
+    let temp_workspace = mk_temp_workspace(&temp_pkg_id.path);
     // should have test, bench, lib, and main
     ctxt.install(&temp_workspace, temp_pkg_id);
     // Check that all files exist
     let exec = target_executable_in_workspace(temp_pkg_id, &temp_workspace);
+    debug!("exec = %s", exec.to_str());
     assert!(os::path_exists(&exec));
     assert!(is_rwx(&exec));
     let lib = target_library_in_workspace(temp_pkg_id, &temp_workspace);
+    debug!("lib = %s", lib.to_str());
     assert!(os::path_exists(&lib));
     assert!(is_rwx(&lib));
     // And that the test and bench executables aren't installed
     assert!(!os::path_exists(&target_test_in_workspace(temp_pkg_id, &temp_workspace)));
-    assert!(!os::path_exists(&target_bench_in_workspace(temp_pkg_id, &temp_workspace)));
+    let bench = target_bench_in_workspace(temp_pkg_id, &temp_workspace);
+    debug!("bench = %s", bench.to_str());
+    assert!(!os::path_exists(&bench));
 }
 
 #[test]
-#[ignore(reason = "install not yet implemented")]
 fn test_install_invalid() {
     use conditions::nonexistent_package::cond;
+    use cond1 = conditions::missing_pkg_files::cond;
 
-    let ctxt = fake_ctxt();
+    let ctxt = fake_ctxt(None);
     let pkgid = fake_pkg();
-    let temp_workspace = mk_temp_workspace();
-    let expected_path = Path(~"quux");
-    let substituted: Path = do cond.trap(|_| {
-        expected_path
+    let temp_workspace = mkdtemp(&os::tmpdir(), "test").expect("couldn't create temp dir");
+    let mut error_occurred = false;
+    let mut error1_occurred = false;
+    do cond1.trap(|_| {
+        error1_occurred = true;
     }).in {
-        ctxt.install(&temp_workspace, pkgid);
-        // ok
-        fail!(~"test_install_invalid failed, should have raised a condition");
-    };
-    assert!(substituted == expected_path);
+        do cond.trap(|_| {
+            error_occurred = true;
+        }).in {
+            ctxt.install(&temp_workspace, pkgid);
+        }
+    }
+    assert!(error_occurred && error1_occurred);
 }
+
+#[test]
+#[ignore(reason = "install from URL-fragment not yet implemented")]
+fn test_install_url() {
+    let sysroot = test_sysroot();
+    debug!("sysroot = %s", sysroot.to_str());
+    let ctxt = fake_ctxt(Some(@sysroot));
+    let temp_pkg_id = remote_pkg();
+    let temp_workspace = mk_temp_workspace(&temp_pkg_id.path);
+    // should have test, bench, lib, and main
+    ctxt.install(&temp_workspace, temp_pkg_id);
+    // Check that all files exist
+    let exec = target_executable_in_workspace(temp_pkg_id, &temp_workspace);
+    debug!("exec = %s", exec.to_str());
+    assert!(os::path_exists(&exec));
+    assert!(is_rwx(&exec));
+    let lib = target_library_in_workspace(temp_pkg_id, &temp_workspace);
+    debug!("lib = %s", lib.to_str());
+    assert!(os::path_exists(&lib));
+    assert!(is_rwx(&lib));
+    // And that the test and bench executables aren't installed
+    assert!(!os::path_exists(&target_test_in_workspace(temp_pkg_id, &temp_workspace)));
+    let bench = target_bench_in_workspace(temp_pkg_id, &temp_workspace);
+    debug!("bench = %s", bench.to_str());
+    assert!(!os::path_exists(&bench));
+}
\ No newline at end of file