@@ -725,13 +725,98 @@ fn dont_run_examples() {
725
725
}
726
726
727
727
#[ cargo_test]
728
- fn pass_through_command_line ( ) {
728
+ fn pass_through_escaped ( ) {
729
729
let p = project ( )
730
730
. file (
731
731
"src/lib.rs" ,
732
732
"
733
- #[test] fn foo() {}
734
- #[test] fn bar() {}
733
+ /// ```rust
734
+ /// assert!(foo::foo());
735
+ /// ```
736
+ pub fn foo() -> bool {
737
+ true
738
+ }
739
+
740
+ /// ```rust
741
+ /// assert!(!foo::bar());
742
+ /// ```
743
+ pub fn bar() -> bool {
744
+ false
745
+ }
746
+
747
+ #[test] fn test_foo() {
748
+ assert!(foo());
749
+ }
750
+ #[test] fn test_bar() {
751
+ assert!(!bar());
752
+ }
753
+ " ,
754
+ )
755
+ . build ( ) ;
756
+
757
+ p. cargo ( "test -- bar" )
758
+ . with_stderr (
759
+ "\
760
+ [COMPILING] foo v0.0.1 ([CWD])
761
+ [FINISHED] test [unoptimized + debuginfo] target(s) in [..]
762
+ [RUNNING] [..] (target/debug/deps/foo-[..][EXE])
763
+ " ,
764
+ )
765
+ . with_stdout_contains ( "running 1 test" )
766
+ . with_stdout_contains ( "test test_bar ... ok" )
767
+ . run ( ) ;
768
+
769
+ p. cargo ( "test -- foo" )
770
+ . with_stderr (
771
+ "\
772
+ [FINISHED] test [unoptimized + debuginfo] target(s) in [..]
773
+ [RUNNING] [..] (target/debug/deps/foo-[..][EXE])
774
+ " ,
775
+ )
776
+ . with_stdout_contains ( "running 1 test" )
777
+ . with_stdout_contains ( "test test_foo ... ok" )
778
+ . run ( ) ;
779
+
780
+ p. cargo ( "test -- foo bar" )
781
+ . with_stderr (
782
+ "\
783
+ [FINISHED] test [unoptimized + debuginfo] target(s) in [..]
784
+ [RUNNING] [..] (target/debug/deps/foo-[..][EXE])
785
+ " ,
786
+ )
787
+ . with_stdout_contains ( "running 2 tests" )
788
+ . with_stdout_contains ( "test test_foo ... ok" )
789
+ . with_stdout_contains ( "test test_bar ... ok" )
790
+ . run ( ) ;
791
+ }
792
+
793
+ // Unlike `pass_through_escaped`, doctests won't run when using `testname` as an optimization
794
+ #[ cargo_test]
795
+ fn pass_through_testname ( ) {
796
+ let p = project ( )
797
+ . file (
798
+ "src/lib.rs" ,
799
+ "
800
+ /// ```rust
801
+ /// assert!(foo::foo());
802
+ /// ```
803
+ pub fn foo() -> bool {
804
+ true
805
+ }
806
+
807
+ /// ```rust
808
+ /// assert!(!foo::bar());
809
+ /// ```
810
+ pub fn bar() -> bool {
811
+ false
812
+ }
813
+
814
+ #[test] fn test_foo() {
815
+ assert!(foo());
816
+ }
817
+ #[test] fn test_bar() {
818
+ assert!(!bar());
819
+ }
735
820
" ,
736
821
)
737
822
. build ( ) ;
@@ -745,7 +830,7 @@ fn pass_through_command_line() {
745
830
" ,
746
831
)
747
832
. with_stdout_contains ( "running 1 test" )
748
- . with_stdout_contains ( "test bar ... ok" )
833
+ . with_stdout_contains ( "test test_bar ... ok" )
749
834
. run ( ) ;
750
835
751
836
p. cargo ( "test foo" )
@@ -756,7 +841,19 @@ fn pass_through_command_line() {
756
841
" ,
757
842
)
758
843
. with_stdout_contains ( "running 1 test" )
759
- . with_stdout_contains ( "test foo ... ok" )
844
+ . with_stdout_contains ( "test test_foo ... ok" )
845
+ . run ( ) ;
846
+
847
+ p. cargo ( "test foo -- bar" )
848
+ . with_stderr (
849
+ "\
850
+ [FINISHED] test [unoptimized + debuginfo] target(s) in [..]
851
+ [RUNNING] [..] (target/debug/deps/foo-[..][EXE])
852
+ " ,
853
+ )
854
+ . with_stdout_contains ( "running 2 tests" )
855
+ . with_stdout_contains ( "test test_foo ... ok" )
856
+ . with_stdout_contains ( "test test_bar ... ok" )
760
857
. run ( ) ;
761
858
}
762
859
0 commit comments