1212
1313use context:: Ctx ;
1414use std:: hashmap:: HashMap ;
15- use std:: { io, libc, os, result, run, str, vec } ;
15+ use std:: { io, libc, os, result, run, str} ;
1616use extra:: tempfile:: mkdtemp;
1717use std:: run:: ProcessOutput ;
18+ use installed_packages:: list_installed_packages;
1819use package_path:: * ;
1920use package_id:: { PkgId } ;
2021use package_source:: * ;
@@ -128,20 +129,27 @@ fn test_sysroot() -> Path {
128129 self_path. pop ( )
129130}
130131
132+ fn command_line_test ( args : & [ ~str ] , cwd : & Path ) -> ProcessOutput {
133+ command_line_test_with_env ( args, cwd, None )
134+ }
135+
131136/// Runs `rustpkg` (based on the directory that this executable was
132137/// invoked from) with the given arguments, in the given working directory.
133138/// Returns the process's output.
134- fn command_line_test ( args : & [ ~str ] , cwd : & Path ) -> ProcessOutput {
139+ fn command_line_test_with_env ( args : & [ ~str ] , cwd : & Path , env : Option < ~[ ( ~str , ~str ) ] > )
140+ -> ProcessOutput {
135141 let cmd = test_sysroot ( ) . push ( "bin" ) . push ( "rustpkg" ) . to_str ( ) ;
136142 let cwd = normalize ( RemotePath ( copy * cwd) ) ;
137143 debug ! ( "About to run command: %? %? in %s" , cmd, args, cwd. to_str( ) ) ;
138144 assert ! ( os:: path_is_dir( & * cwd) ) ;
139- let mut prog = run:: Process :: new ( cmd, args, run:: ProcessOptions { env : None ,
140- dir : Some ( & * cwd) ,
141- in_fd : None ,
142- out_fd : None ,
143- err_fd : None
144- } ) ;
145+ let cwd = cwd. clone ( ) ;
146+ let mut prog = run:: Process :: new ( cmd, args, run:: ProcessOptions {
147+ env : env. map ( |v| v. slice ( 0 , v. len ( ) ) ) ,
148+ dir : Some ( & cwd) ,
149+ in_fd : None ,
150+ out_fd : None ,
151+ err_fd : None
152+ } ) ;
145153 let output = prog. finish_with_output ( ) ;
146154 debug ! ( "Output from command %s with args %? was %s {%s}[%?]" ,
147155 cmd, args, str :: from_bytes( output. output) ,
@@ -252,6 +260,16 @@ fn command_line_test_output(args: &[~str]) -> ~[~str] {
252260 result
253261}
254262
263+ fn command_line_test_output_with_env ( args : & [ ~str ] , env : ~[ ( ~str , ~str ) ] ) -> ~[ ~str ] {
264+ let mut result = ~[ ] ;
265+ let p_output = command_line_test_with_env ( args, & os:: getcwd ( ) , Some ( env) ) ;
266+ let test_output = str:: from_bytes ( p_output. output ) ;
267+ for test_output. split_iter( '\n' ) . advance |s| {
268+ result. push ( s. to_owned ( ) ) ;
269+ }
270+ result
271+ }
272+
255273// assumes short_name and local_path are one and the same -- I should fix
256274fn lib_output_file_name ( workspace : & Path , parent : & str , short_name : & str ) -> Path {
257275 debug ! ( "lib_output_file_name: given %s and parent %s and short name %s" ,
@@ -476,8 +494,9 @@ fn test_package_version() {
476494 push(" test_pkg_version")));
477495}
478496
479- // FIXME #7006: Fails on linux/mac for some reason
480- #[test] #[ignore]
497+ // FIXME #7006: Fails on linux for some reason
498+ #[test]
499+ #[ignore]
481500fn test_package_request_version() {
482501 let temp_pkg_id = PkgId::new(" github. com/catamorphism/test_pkg_version#0.3 ");
483502 let temp = mk_empty_workspace(&LocalPath(Path(" test_pkg_version")), &ExactRevision(~" 0.3 "));
@@ -613,7 +632,33 @@ fn rust_path_parse() {
613632}
614633
615634#[test]
616- #[ignore(reason = " Package database not yet implemented")]
635+ fn test_list() {
636+ let foo = PkgId::new(" foo");
637+ let dir = mkdtemp(&os::tmpdir(), " test_list").expect(" test_list failed");
638+ create_local_package_in(&foo, &dir);
639+ let bar = PkgId::new(" bar");
640+ create_local_package_in(&bar, &dir);
641+ let quux = PkgId::new(" quux");
642+ create_local_package_in(&quux, &dir);
643+
644+ command_line_test([~" install", ~" foo"], &dir);
645+ let env_arg = ~[(~" RUST_PATH ", dir.to_str())];
646+ let list_output = command_line_test_output_with_env([~" list"], env_arg.clone());
647+ assert!(list_output.iter().any(|x| x.starts_with(" foo-")));
648+
649+ command_line_test([~" install", ~" bar"], &dir);
650+ let list_output = command_line_test_output_with_env([~" list"], env_arg.clone());
651+ assert!(list_output.iter().any(|x| x.starts_with(" foo-")));
652+ assert!(list_output.iter().any(|x| x.starts_with(" bar-")));
653+
654+ command_line_test([~" install", ~" quux"], &dir);
655+ let list_output = command_line_test_output_with_env([~" list"], env_arg);
656+ assert!(list_output.iter().any(|x| x.starts_with(" foo-")));
657+ assert!(list_output.iter().any(|x| x.starts_with(" bar-")));
658+ assert!(list_output.iter().any(|x| x.starts_with(" quux-")));
659+ }
660+
661+ #[test]
617662fn install_remove() {
618663 let foo = PkgId::new(" foo");
619664 let bar = PkgId::new(" bar");
@@ -622,18 +667,43 @@ fn install_remove() {
622667 create_local_package_in(&foo, &dir);
623668 create_local_package_in(&bar, &dir);
624669 create_local_package_in(&quux, &dir);
670+ let rust_path_to_use = ~[(~" RUST_PATH ", dir.to_str())];
625671 command_line_test([~" install", ~" foo"], &dir);
626672 command_line_test([~" install", ~" bar"], &dir);
627673 command_line_test([~" install", ~" quux"], &dir);
628- let list_output = command_line_test_output([~" list"]);
629- assert!(list_output.iter().any(|x| x == &~" foo"));
630- assert!(list_output.iter().any(|x| x == &~" bar"));
631- assert!(list_output.iter().any(|x| x == &~" quux"));
632- command_line_test([~" remove", ~" foo"], &dir);
633- let list_output = command_line_test_output([~" list"]);
634- assert!(!list_output.iter().any(|x| x == &~" foo"));
635- assert!(list_output.iter().any(|x| x == &~" bar"));
636- assert!(list_output.iter().any(|x| x == &~" quux"));
674+ let list_output = command_line_test_output_with_env([~" list"], rust_path_to_use.clone());
675+ assert!(list_output.iter().any(|x| x.starts_with(" foo")));
676+ assert!(list_output.iter().any(|x| x.starts_with(" bar")));
677+ assert!(list_output.iter().any(|x| x.starts_with(" quux")));
678+ command_line_test([~" uninstall", ~" foo"], &dir);
679+ let list_output = command_line_test_output_with_env([~" list"], rust_path_to_use.clone());
680+ assert!(!list_output.iter().any(|x| x.starts_with(" foo")));
681+ assert!(list_output.iter().any(|x| x.starts_with(" bar")));
682+ assert!(list_output.iter().any(|x| x.starts_with(" quux")));
683+ }
684+
685+ #[test]
686+ fn install_check_duplicates() {
687+ // should check that we don't install two packages with the same full name *and* version
688+ // (" Is already installed -- doing nothing")
689+ // check invariant that there are no dups in the pkg database
690+ let dir = mkdtemp(&os::tmpdir(), " install_remove").expect(" install_remove");
691+ let foo = PkgId::new(" foo");
692+ create_local_package_in(&foo, &dir);
693+
694+ command_line_test([~" install", ~" foo"], &dir);
695+ command_line_test([~" install", ~" foo"], &dir);
696+ let mut contents = ~[];
697+ let check_dups = |p: &PkgId| {
698+ if contents.contains(p) {
699+ fail!(" package database contains duplicate ID ");
700+ }
701+ else {
702+ contents.push(copy *p);
703+ }
704+ false
705+ };
706+ list_installed_packages(check_dups);
637707}
638708
639709#[test]
0 commit comments