1212
1313use context:: Ctx ;
1414use core:: hashmap:: HashMap ;
15- use core:: { io, libc, os, result, run, str} ;
15+ use core:: { io, libc, os, result, run, str, vec } ;
1616use core:: prelude:: * ;
1717use extra:: tempfile:: mkdtemp;
1818use core:: run:: ProcessOutput ;
@@ -25,7 +25,7 @@ use path_util::{target_executable_in_workspace, target_library_in_workspace,
2525 make_dir_rwx, u_rwx, library_in_workspace,
2626 built_bench_in_workspace, built_test_in_workspace,
2727 built_library_in_workspace, built_executable_in_workspace,
28- installed_library_in_workspace} ;
28+ installed_library_in_workspace, rust_path } ;
2929use target:: * ;
3030
3131/// Returns the last-modified date as an Option
@@ -562,13 +562,58 @@ fn package_script_with_default_build() {
562562}
563563
564564#[test]
565- #[ignore (reason = " RUST_PATH not yet implemented -- # 5682 ")]
565+ #[ignore (reason = " Un -ignore when # 7071 is fixed ")]
566566fn rust_path_test() {
567- let dir = mk_workspace(&Path(" /home/more_rust"),
568- &normalize(RemotePath(Path(" foo"))),
569- &NoVersion);
570- // command_line_test(" RUST_PATH =/home/rust: /home/more_rust rustpkg install foo");
571- command_line_test([~" install", ~" foo"], &dir);
567+ let dir_for_path = mkdtemp(&os::tmpdir(), " more_rust").expect(" rust_path_test failed");
568+ let dir = mk_workspace(&dir_for_path, &normalize(RemotePath(Path(" foo"))), &NoVersion);
569+ debug!(" dir = %s", dir.to_str());
570+ writeFile(&Path(" /Users /tjc/more_rust/src/foo-0.1 /main. rs"),
571+ " fn main( ) { let _x = ( ) ; } ");
572+
573+ let cwd = os::getcwd();
574+ debug!(" cwd = %s", cwd.to_str());
575+ let mut prog = run::Process::new(" rustpkg",
576+ [~" install", ~" foo"],
577+ run::ProcessOptions { env: Some(&[(~" RUST_PATH ",
578+ dir_for_path.to_str())]),
579+ dir: Some(&cwd),
580+ in_fd: None,
581+ out_fd: None,
582+ err_fd: None
583+ });
584+ prog.finish_with_output();
585+ assert_executable_exists(&dir_for_path, " foo");
586+ }
587+
588+ #[test]
589+ fn rust_path_contents() {
590+ let dir = mkdtemp(&os::tmpdir(), " rust_path").expect(" rust_path_contents failed");
591+ let abc = &dir.push(" A ").push(" B ").push(" C ");
592+ assert!(os::mkdir_recursive(&abc.push(" . rust"), u_rwx));
593+ assert!(os::mkdir_recursive(&abc.pop().push(" . rust"), u_rwx));
594+ assert!(os::mkdir_recursive(&abc.pop().pop().push(" . rust"), u_rwx));
595+ assert!(do os::change_dir_locked(&dir.push(" A ").push(" B ").push(" C ")) {
596+ let p = rust_path();
597+ let cwd = os::getcwd().push(" . rust");
598+ let parent = cwd.pop().pop().push(" . rust");
599+ let grandparent = cwd.pop().pop().pop().push(" . rust");
600+ assert!(vec::contains(p, &cwd));
601+ assert!(vec::contains(p, &parent));
602+ assert!(vec::contains(p, &grandparent));
603+ for p.iter().advance() |a_path| {
604+ assert!(!a_path.components.is_empty());
605+ }
606+ });
607+ }
608+
609+ #[test]
610+ fn rust_path_parse() {
611+ os::setenv(" RUST_PATH ", " /a/b/c: /d/e/f: /g/h/i");
612+ let paths = rust_path();
613+ assert!(vec::contains(paths, &Path(" /g/h/i")));
614+ assert!(vec::contains(paths, &Path(" /d/e/f")));
615+ assert!(vec::contains(paths, &Path(" /a/b/c")));
616+ os::unsetenv(" RUST_PATH ");
572617}
573618
574619#[test]
0 commit comments