diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-04-24 17:37:59 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-04-24 17:51:31 -0700 |
| commit | 4e2c8f422aec1aef910fdfdac57f5f66a7465355 (patch) | |
| tree | fb63b27dcf1fe7ce2bc366e7ed70d57ff0414535 /src/librustpkg/tests.rs | |
| parent | f945e57bd050227bbf92f151303785991173f2fe (diff) | |
| download | rust-4e2c8f422aec1aef910fdfdac57f5f66a7465355.tar.gz rust-4e2c8f422aec1aef910fdfdac57f5f66a7465355.zip | |
rustpkg: Preliminary work on install command
Mostly just tests (that are ignored); install command is still stubbed out.
Diffstat (limited to 'src/librustpkg/tests.rs')
| -rw-r--r-- | src/librustpkg/tests.rs | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index f5948606072..70c03c845ce 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -9,3 +9,96 @@ // except according to those terms. // rustpkg unit tests + +use context::Ctx; +use core::hashmap::HashMap; +use core::path::Path; +use core::os; +use core::io; +use core::option::*; +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}; + +fn fake_ctxt() -> Ctx { + Ctx { + json: false, + dep_cache: @mut HashMap::new() + } +} + +fn fake_pkg() -> PkgId { + PkgId { + path: Path(~"bogus"), + version: default_version() + } +} + +fn mk_temp_workspace() -> Path { + mkdtemp(&os::tmpdir(), "test").expect("couldn't create temp dir") +} + +fn is_rwx(p: &Path) -> bool { + use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; + + match p.get_mode() { + None => return false, + 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) + } + } +} + +#[test] +fn test_make_dir_rwx() { + let temp = &os::tmpdir(); + let dir = temp.push(~"quux"); + let _ = os::remove_dir(&dir); + assert!(make_dir_rwx(&dir)); + assert!(os::path_is_dir(&dir)); + assert!(is_rwx(&dir)); + assert!(os::remove_dir(&dir)); +} + +#[test] +#[ignore(reason = "install not yet implemented")] +fn test_install_valid() { + let ctxt = fake_ctxt(); + let temp_pkg_id = fake_pkg(); + let temp_workspace() = mk_temp_workspace(); + // 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); + assert!(os::path_exists(&exec)); + assert!(is_rwx(&exec)); + let lib = target_library_in_workspace(temp_pkg_id, &temp_workspace); + 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))); +} + +#[test] +#[ignore(reason = "install not yet implemented")] +fn test_install_invalid() { + use conditions::nonexistent_package::cond; + + let ctxt = fake_ctxt(); + let pkgid = fake_pkg(); + let temp_workspace = mk_temp_workspace(); + let expected_path = Path(~"quux"); + let substituted: Path = do cond.trap(|_| { + expected_path + }).in { + ctxt.install(&temp_workspace, pkgid); + // ok + fail!(~"test_install_invalid failed, should have raised a condition"); + }; + assert!(substituted == expected_path); +} \ No newline at end of file |
