@@ -2,6 +2,7 @@ extern crate cargotest;
2
2
extern crate hamcrest;
3
3
4
4
use cargotest:: is_nightly;
5
+ use cargotest:: install:: { cargo_home, has_installed_exe} ;
5
6
use cargotest:: support:: { project, execs} ;
6
7
use hamcrest:: { assert_that, existing_file, not} ;
7
8
@@ -576,3 +577,154 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
576
577
. with_stdout ( "" ) ) ;
577
578
}
578
579
580
+ #[ test]
581
+ fn install_default_features ( ) {
582
+ let p = project ( "foo" )
583
+ . file ( "Cargo.toml" , r#"
584
+ [project]
585
+ name = "foo"
586
+ version = "0.0.1"
587
+ authors = []
588
+
589
+ [features]
590
+ default = ["a"]
591
+ a = []
592
+
593
+ [[bin]]
594
+ name = "foo"
595
+ required-features = ["a"]
596
+
597
+ [[example]]
598
+ name = "foo"
599
+ required-features = ["a"]
600
+ "# )
601
+ . file ( "src/main.rs" , "fn main() {}" )
602
+ . file ( "examples/foo.rs" , "fn main() {}" ) ;
603
+
604
+ assert_that ( p. cargo_process ( "install" ) ,
605
+ execs ( ) . with_status ( 0 ) ) ;
606
+ assert_that ( cargo_home ( ) , has_installed_exe ( "foo" ) ) ;
607
+ assert_that ( p. cargo_process ( "uninstall" ) . arg ( "foo" ) ,
608
+ execs ( ) . with_status ( 0 ) ) ;
609
+
610
+ assert_that ( p. cargo_process ( "install" ) . arg ( "--no-default-features" ) ,
611
+ execs ( ) . with_status ( 101 ) . with_stderr ( format ! ( "\
612
+ [INSTALLING] foo v0.0.1 ([..])
613
+ [FINISHED] release [optimized] target(s) in [..]
614
+ [ERROR] no binaries are available for install using the selected features
615
+ " ) ) ) ;
616
+ assert_that ( cargo_home ( ) , not ( has_installed_exe ( "foo" ) ) ) ;
617
+
618
+ assert_that ( p. cargo_process ( "install" ) . arg ( "--bin=foo" ) ,
619
+ execs ( ) . with_status ( 0 ) ) ;
620
+ assert_that ( cargo_home ( ) , has_installed_exe ( "foo" ) ) ;
621
+ assert_that ( p. cargo_process ( "uninstall" ) . arg ( "foo" ) ,
622
+ execs ( ) . with_status ( 0 ) ) ;
623
+
624
+ assert_that ( p. cargo_process ( "install" ) . arg ( "--bin=foo" ) . arg ( "--no-default-features" ) ,
625
+ execs ( ) . with_status ( 101 ) . with_stderr ( format ! ( "\
626
+ [INSTALLING] foo v0.0.1 ([..])
627
+ [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \
628
+ `[..]target`
629
+
630
+ Caused by:
631
+ target `foo` requires the features: `a`
632
+ Consider enabling them by passing e.g. `--features=\" a\" `
633
+ " ) ) ) ;
634
+ assert_that ( cargo_home ( ) , not ( has_installed_exe ( "foo" ) ) ) ;
635
+
636
+ assert_that ( p. cargo_process ( "install" ) . arg ( "--example=foo" ) ,
637
+ execs ( ) . with_status ( 0 ) ) ;
638
+ assert_that ( cargo_home ( ) , has_installed_exe ( "foo" ) ) ;
639
+ assert_that ( p. cargo_process ( "uninstall" ) . arg ( "foo" ) ,
640
+ execs ( ) . with_status ( 0 ) ) ;
641
+
642
+ assert_that ( p. cargo_process ( "install" ) . arg ( "--example=foo" ) . arg ( "--no-default-features" ) ,
643
+ execs ( ) . with_status ( 101 ) . with_stderr ( format ! ( "\
644
+ [INSTALLING] foo v0.0.1 ([..])
645
+ [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \
646
+ `[..]target`
647
+
648
+ Caused by:
649
+ target `foo` requires the features: `a`
650
+ Consider enabling them by passing e.g. `--features=\" a\" `
651
+ " ) ) ) ;
652
+ assert_that ( cargo_home ( ) , not ( has_installed_exe ( "foo" ) ) ) ;
653
+ }
654
+
655
+ #[ test]
656
+ fn install_arg_features ( ) {
657
+ let p = project ( "foo" )
658
+ . file ( "Cargo.toml" , r#"
659
+ [project]
660
+ name = "foo"
661
+ version = "0.0.1"
662
+ authors = []
663
+
664
+ [features]
665
+ a = []
666
+
667
+ [[bin]]
668
+ name = "foo"
669
+ required-features = ["a"]
670
+ "# )
671
+ . file ( "src/main.rs" , "fn main() {}" ) ;
672
+
673
+ assert_that ( p. cargo_process ( "install" ) . arg ( "--features" ) . arg ( "a" ) ,
674
+ execs ( ) . with_status ( 0 ) ) ;
675
+ assert_that ( cargo_home ( ) , has_installed_exe ( "foo" ) ) ;
676
+ assert_that ( p. cargo_process ( "uninstall" ) . arg ( "foo" ) ,
677
+ execs ( ) . with_status ( 0 ) ) ;
678
+ }
679
+
680
+ #[ test]
681
+ fn install_multiple_required_features ( ) {
682
+ let p = project ( "foo" )
683
+ . file ( "Cargo.toml" , r#"
684
+ [project]
685
+ name = "foo"
686
+ version = "0.0.1"
687
+ authors = []
688
+
689
+ [features]
690
+ default = ["a", "b"]
691
+ a = []
692
+ b = ["a"]
693
+ c = []
694
+
695
+ [[bin]]
696
+ name = "foo_1"
697
+ path = "src/foo_1.rs"
698
+ required-features = ["b", "c"]
699
+
700
+ [[bin]]
701
+ name = "foo_2"
702
+ path = "src/foo_2.rs"
703
+ required-features = ["a"]
704
+ "# )
705
+ . file ( "src/foo_1.rs" , "fn main() {}" )
706
+ . file ( "src/foo_2.rs" , "fn main() {}" ) ;
707
+
708
+ assert_that ( p. cargo_process ( "install" ) ,
709
+ execs ( ) . with_status ( 0 ) ) ;
710
+ assert_that ( cargo_home ( ) , not ( has_installed_exe ( "foo_1" ) ) ) ;
711
+ assert_that ( cargo_home ( ) , has_installed_exe ( "foo_2" ) ) ;
712
+ assert_that ( p. cargo_process ( "uninstall" ) . arg ( "foo" ) ,
713
+ execs ( ) . with_status ( 0 ) ) ;
714
+
715
+ assert_that ( p. cargo_process ( "install" ) . arg ( "--features" ) . arg ( "c" ) ,
716
+ execs ( ) . with_status ( 0 ) ) ;
717
+ assert_that ( cargo_home ( ) , has_installed_exe ( "foo_1" ) ) ;
718
+ assert_that ( cargo_home ( ) , has_installed_exe ( "foo_2" ) ) ;
719
+ assert_that ( p. cargo_process ( "uninstall" ) . arg ( "foo" ) ,
720
+ execs ( ) . with_status ( 0 ) ) ;
721
+
722
+ assert_that ( p. cargo_process ( "install" ) . arg ( "--no-default-features" ) ,
723
+ execs ( ) . with_status ( 101 ) . with_stderr ( "\
724
+ [INSTALLING] foo v0.0.1 ([..])
725
+ [FINISHED] release [optimized] target(s) in [..]
726
+ [ERROR] no binaries are available for install using the selected features
727
+ " ) ) ;
728
+ assert_that ( cargo_home ( ) , not ( has_installed_exe ( "foo_1" ) ) ) ;
729
+ assert_that ( cargo_home ( ) , not ( has_installed_exe ( "foo_2" ) ) ) ;
730
+ }
0 commit comments