File tree 2 files changed +72
-1
lines changed
2 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 1
1
use command_prelude:: * ;
2
2
3
- use cargo:: ops;
3
+ use cargo:: ops:: { self , CompileFilter } ;
4
4
5
5
pub fn cli ( ) -> App {
6
6
subcommand ( "test" )
@@ -92,8 +92,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
92
92
let ws = args. workspace ( config) ?;
93
93
94
94
let mut compile_opts = args. compile_options ( config, CompileMode :: Test ) ?;
95
+
95
96
let doc = args. is_present ( "doc" ) ;
96
97
if doc {
98
+ if let CompileFilter :: Only { .. } = compile_opts. filter {
99
+ return Err ( CliError :: new ( format_err ! ( "Can't mix --doc with other target selecting options" ) , 101 ) )
100
+ }
97
101
compile_opts. build_config . mode = CompileMode :: Doctest ;
98
102
compile_opts. filter = ops:: CompileFilter :: new (
99
103
true ,
Original file line number Diff line number Diff line change @@ -3101,3 +3101,70 @@ fn doctest_skip_staticlib() {
3101
3101
[RUNNING] target/debug/deps/foo-[..]" ,
3102
3102
) . run ( ) ;
3103
3103
}
3104
+
3105
+ #[ test]
3106
+ fn can_not_mix_doc_tests_and_regular_tests ( ) {
3107
+ let p = project ( )
3108
+ . file ( "src/lib.rs" , "\
3109
+ /// ```
3110
+ /// assert_eq!(1, 1)
3111
+ /// ```
3112
+ pub fn foo() -> u8 { 1 }
3113
+
3114
+ #[cfg(test)] mod tests {
3115
+ #[test] fn it_works() { assert_eq!(2 + 2, 4); }
3116
+ }
3117
+ " )
3118
+ . build ( ) ;
3119
+
3120
+ p. cargo ( "test" )
3121
+ . with_stderr ( "\
3122
+ [COMPILING] foo v0.0.1 ([CWD])
3123
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
3124
+ [RUNNING] target/debug/deps/foo-[..]
3125
+ [DOCTEST] foo
3126
+ " )
3127
+ . with_stdout ( "
3128
+ running 1 test
3129
+ test tests::it_works ... ok
3130
+
3131
+ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
3132
+
3133
+
3134
+ running 1 test
3135
+ test src/lib.rs - foo (line 1) ... ok
3136
+
3137
+ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
3138
+ \n ")
3139
+ . run ( ) ;
3140
+
3141
+ p. cargo ( "test --lib" )
3142
+ . with_stderr ( "\
3143
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
3144
+ [RUNNING] target/debug/deps/foo-[..]\n " )
3145
+ . with_stdout ( "
3146
+ running 1 test
3147
+ test tests::it_works ... ok
3148
+
3149
+ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
3150
+ \n ")
3151
+ . run ( ) ;
3152
+
3153
+ p. cargo ( "test --doc" )
3154
+ . with_stderr ( "\
3155
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
3156
+ [DOCTEST] foo
3157
+ " )
3158
+ . with_stdout ( "
3159
+ running 1 test
3160
+ test src/lib.rs - foo (line 1) ... ok
3161
+
3162
+ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
3163
+
3164
+ " ) . run ( ) ;
3165
+
3166
+ p. cargo ( "test --lib --doc" )
3167
+ . with_status ( 101 )
3168
+ . with_stderr ( "[ERROR] Can't mix --doc with other target selecting options\n " )
3169
+ . run ( ) ;
3170
+ }
You can’t perform that action at this time.
0 commit comments