@@ -4,7 +4,7 @@ use std::fs::{self, OpenOptions};
4
4
use std:: io:: prelude:: * ;
5
5
use std:: path:: Path ;
6
6
7
- use cargo_test_support:: compare;
7
+ use cargo_test_support:: { compare} ;
8
8
use cargo_test_support:: cross_compile;
9
9
use cargo_test_support:: git;
10
10
use cargo_test_support:: registry:: { self , registry_path, Package } ;
@@ -560,28 +560,107 @@ Available binaries:
560
560
}
561
561
562
562
#[ cargo_test]
563
- fn multiple_crates_error ( ) {
563
+ fn multiple_binaries_error ( ) {
564
564
let p = git:: repo ( & paths:: root ( ) . join ( "foo" ) )
565
565
. file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ) )
566
566
. file ( "src/main.rs" , "fn main() {}" )
567
567
. file ( "a/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
568
568
. file ( "a/src/main.rs" , "fn main() {}" )
569
569
. build ( ) ;
570
570
571
+ let git_url = p. url ( ) . to_string ( ) ;
571
572
cargo_process ( "install --git" )
572
573
. arg ( p. url ( ) . to_string ( ) )
573
574
. with_status ( 101 )
574
575
. with_stderr (
575
- "\
576
+ format ! ( "\
576
577
[UPDATING] git repository [..]
577
578
[ERROR] multiple packages with binaries found: bar, foo. \
578
- When installing a git repository, cargo will always search the entire repo for any Cargo.toml. \
579
- Please specify which to install.
580
- " ,
579
+ When installing a git repository, cargo will always search the entire repo for any Cargo.toml.\n \
580
+ Please specify a package, e.g. `cargo install --git {git_url} bar` .
581
+ " ) ,
581
582
)
582
583
. run ( ) ;
583
584
}
584
585
586
+ #[ cargo_test]
587
+ fn multiple_examples_error ( ) {
588
+ let p = git:: repo ( & paths:: root ( ) . join ( "foo" ) )
589
+ . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ) )
590
+ . file ( "src/lib.rs" , "" )
591
+ . file ( "examples/ex1.rs" , "fn main() {}" )
592
+ . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
593
+ . file ( "bar/src/lib.rs" , "" )
594
+ . file ( "bar/examples/ex1.rs" , "fn main() {}" , )
595
+ . build ( ) ;
596
+
597
+ let git_url = p. url ( ) . to_string ( ) ;
598
+ cargo_process ( "install --example ex1 --git" )
599
+ . arg ( p. url ( ) . to_string ( ) )
600
+ . with_status ( 101 )
601
+ . with_stderr ( format ! ( "\
602
+ [UPDATING] git repository [..]
603
+ [ERROR] multiple packages with examples found: bar, foo. \
604
+ When installing a git repository, cargo will always search the entire repo for any Cargo.toml.\n \
605
+ Please specify a package, e.g. `cargo install --git {git_url} bar`.") )
606
+ . run ( ) ;
607
+ }
608
+
609
+ #[ cargo_test]
610
+ fn multiple_binaries_deep_select_uses_package_name ( ) {
611
+ let p = git:: repo ( & paths:: root ( ) . join ( "foo" ) )
612
+ . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ) )
613
+ . file ( "src/main.rs" , "fn main() {}" )
614
+ . file ( "bar/baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ) )
615
+ . file ( "bar/baz/src/main.rs" , "fn main() {}" )
616
+ . build ( ) ;
617
+
618
+ cargo_process ( "install --git" )
619
+ . arg ( p. url ( ) . to_string ( ) )
620
+ . arg ( "baz" )
621
+ . run ( ) ;
622
+ }
623
+
624
+ #[ cargo_test]
625
+ fn multiple_binaries_in_selected_package_installs_all ( ) {
626
+ let p = git:: repo ( & paths:: root ( ) . join ( "foo" ) )
627
+ . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ) )
628
+ . file ( "src/lib.rs" , "" )
629
+ . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
630
+ . file ( "bar/src/bin/bin1.rs" , "fn main() {}" )
631
+ . file ( "bar/src/bin/bin2.rs" , "fn main() {}" )
632
+ . build ( ) ;
633
+
634
+ cargo_process ( "install --git" )
635
+ . arg ( p. url ( ) . to_string ( ) )
636
+ . arg ( "bar" )
637
+ . run ( ) ;
638
+
639
+ let cargo_home = cargo_home ( ) ;
640
+ assert_has_installed_exe ( & cargo_home, "bin1" ) ;
641
+ assert_has_installed_exe ( & cargo_home, "bin2" ) ;
642
+ }
643
+
644
+ #[ cargo_test]
645
+ fn multiple_binaries_in_selected_package_with_bin_option_installs_only_one ( ) {
646
+ let p = git:: repo ( & paths:: root ( ) . join ( "foo" ) )
647
+ . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ) )
648
+ . file ( "src/lib.rs" , "" )
649
+ . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
650
+ . file ( "bar/src/bin/bin1.rs" , "fn main() {}" )
651
+ . file ( "bar/src/bin/bin2.rs" , "fn main() {}" )
652
+ . build ( ) ;
653
+
654
+ cargo_process ( "install --bin bin1 --git" )
655
+ . arg ( p. url ( ) . to_string ( ) )
656
+ . arg ( "bar" )
657
+ . run ( ) ;
658
+
659
+ let cargo_home = cargo_home ( ) ;
660
+ assert_has_installed_exe ( & cargo_home, "bin1" ) ;
661
+ assert_has_not_installed_exe ( & cargo_home, "bin2" ) ;
662
+ }
663
+
585
664
#[ cargo_test]
586
665
fn multiple_crates_select ( ) {
587
666
let p = git:: repo ( & paths:: root ( ) . join ( "foo" ) )
@@ -689,6 +768,7 @@ fn multiple_crates_auto_examples() {
689
768
assert_has_installed_exe ( cargo_home ( ) , "foo" ) ;
690
769
}
691
770
771
+
692
772
#[ cargo_test]
693
773
fn no_binaries_or_examples ( ) {
694
774
let p = project ( )
0 commit comments