1
1
//! Tests for setting custom rustdoc flags.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: project;
6
4
use cargo_test_support:: rustc_host;
7
5
use cargo_test_support:: rustc_host_env;
6
+ use cargo_test_support:: str;
8
7
9
8
#[ cargo_test]
10
9
fn parses_env ( ) {
11
10
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
12
11
13
12
p. cargo ( "doc -v" )
14
13
. env ( "RUSTDOCFLAGS" , "--cfg=foo" )
15
- . with_stderr_contains ( "[RUNNING] `rustdoc [..] --cfg=foo[..]`" )
14
+ . with_stderr_data ( str![ [ r#"
15
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
16
+ [RUNNING] `rustdoc [..] --cfg=foo [..]`
17
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
18
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
19
+
20
+ "# ] ] )
16
21
. run ( ) ;
17
22
}
18
23
@@ -30,7 +35,13 @@ fn parses_config() {
30
35
. build ( ) ;
31
36
32
37
p. cargo ( "doc -v" )
33
- . with_stderr_contains ( "[RUNNING] `rustdoc [..] --cfg foo[..]`" )
38
+ . with_stderr_data ( str![ [ r#"
39
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
40
+ [RUNNING] `rustdoc [..] --cfg foo [..]`
41
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
42
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
43
+
44
+ "# ] ] )
34
45
. run ( ) ;
35
46
}
36
47
@@ -41,7 +52,13 @@ fn bad_flags() {
41
52
p. cargo ( "doc" )
42
53
. env ( "RUSTDOCFLAGS" , "--bogus" )
43
54
. with_status ( 101 )
44
- . with_stderr_contains ( "[..]bogus[..]" )
55
+ . with_stderr_data ( str![ [ r#"
56
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
57
+ [ERROR] Unrecognized option: 'bogus'
58
+
59
+ [ERROR] could not document `foo`
60
+
61
+ "# ] ] )
45
62
. run ( ) ;
46
63
}
47
64
@@ -52,20 +69,20 @@ fn rerun() {
52
69
p. cargo ( "doc" ) . env ( "RUSTDOCFLAGS" , "--cfg=foo" ) . run ( ) ;
53
70
p. cargo ( "doc" )
54
71
. env ( "RUSTDOCFLAGS" , "--cfg=foo" )
55
- . with_stderr (
56
- "[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
57
- [GENERATED] [CWD]/target/doc/foo/index.html" ,
58
- )
72
+ . with_stderr_data ( str![ [ r#"
73
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
74
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
75
+
76
+ "# ] ] )
59
77
. run ( ) ;
60
78
p. cargo ( "doc" )
61
79
. env ( "RUSTDOCFLAGS" , "--cfg=bar" )
62
- . with_stderr (
63
- "\
64
- [DOCUMENTING] foo v0.0.1 ([..])
65
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
66
- [GENERATED] [CWD]/target/doc/foo/index.html
67
- " ,
68
- )
80
+ . with_stderr_data ( str![ [ r#"
81
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
82
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
83
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
84
+
85
+ "# ] ] )
69
86
. run ( ) ;
70
87
}
71
88
@@ -102,7 +119,13 @@ fn rustdocflags_misspelled() {
102
119
103
120
p. cargo ( "doc" )
104
121
. env ( "RUSTDOC_FLAGS" , "foo" )
105
- . with_stderr_contains ( "[WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?" )
122
+ . with_stderr_data ( str![ [ r#"
123
+ [WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?
124
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
125
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
126
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
127
+
128
+ "# ] ] )
106
129
. run ( ) ;
107
130
}
108
131
@@ -114,7 +137,13 @@ fn whitespace() {
114
137
// "too many operands"
115
138
p. cargo ( "doc" )
116
139
. env ( "RUSTDOCFLAGS" , "--crate-version this has spaces" )
117
- . with_stderr_contains ( "[ERROR] could not document `foo`" )
140
+ . with_stderr_data ( str![ [ r#"
141
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
142
+ [ERROR] too many file operands
143
+
144
+ [ERROR] could not document `foo`
145
+
146
+ "# ] ] )
118
147
. with_status ( 101 )
119
148
. run ( ) ;
120
149
@@ -155,12 +184,30 @@ fn not_affected_by_target_rustflags() {
155
184
// `cargo build` should fail due to missing docs.
156
185
p. cargo ( "build -v" )
157
186
. with_status ( 101 )
158
- . with_stderr_contains ( "[RUNNING] `rustc [..] -D missing-docs[..]`" )
187
+ . with_stderr_data ( str![ [ r#"
188
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
189
+ [RUNNING] `rustc [..] -D missing-docs`
190
+ [ERROR] missing documentation for the crate
191
+ |
192
+ = [NOTE] requested on the command line with `-D missing-docs`
193
+
194
+ [ERROR] could not compile `foo` (lib) due to 1 previous error
195
+
196
+ Caused by:
197
+ process didn't exit successfully: `rustc [..] -D missing-docs` ([EXIT_STATUS]: 1)
198
+
199
+ "# ] ] )
159
200
. run ( ) ;
160
201
161
202
// `cargo doc` shouldn't fail.
162
203
p. cargo ( "doc -v" )
163
- . with_stderr_contains ( "[RUNNING] `rustdoc [..] --cfg foo[..]`" )
204
+ . with_stderr_data ( str![ [ r#"
205
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
206
+ [RUNNING] `rustdoc [..] --cfg foo [..]`
207
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
208
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
209
+
210
+ "# ] ] )
164
211
. run ( ) ;
165
212
}
166
213
@@ -176,14 +223,27 @@ fn target_triple_rustdocflags_works() {
176
223
& format ! ( "CARGO_TARGET_{host_env}_RUSTDOCFLAGS" ) ,
177
224
"--cfg=foo" ,
178
225
)
179
- . with_stderr_contains ( "[RUNNING] `rustdoc[..]--cfg[..]foo[..]`" )
226
+ . with_stderr_data ( str![ [ r#"
227
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
228
+ [RUNNING] `rustdoc [..] --cfg=foo [..]`
229
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
230
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
231
+
232
+ "# ] ] )
180
233
. run ( ) ;
181
234
182
235
// target.triple.rustdocflags in config works
183
236
p. cargo ( "doc -v" )
184
237
. arg ( "--config" )
185
238
. arg ( format ! ( "target.{host}.rustdocflags=['--cfg', 'foo']" ) )
186
- . with_stderr_contains ( "[RUNNING] `rustdoc[..]--cfg[..]foo[..]`" )
239
+ . with_stderr_data ( str![ [ r#"
240
+ [DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
241
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
242
+ [RUNNING] `rustdoc [..] --cfg foo [..]`
243
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
244
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
245
+
246
+ "# ] ] )
187
247
. run ( ) ;
188
248
}
189
249
@@ -208,27 +268,26 @@ fn target_triple_rustdocflags_works_through_cargo_test() {
208
268
& format ! ( "CARGO_TARGET_{host_env}_RUSTDOCFLAGS" ) ,
209
269
"--cfg=foo" ,
210
270
)
211
- . with_stderr_contains ( "[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`" )
212
- . with_stdout_contains (
213
- " \
214
- running 1 test
215
- test src/lib.rs - (line 2) ... ok
216
-
217
- test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]" ,
218
- )
271
+ . with_stderr_data ( str! [ [ r#"
272
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
273
+ [RUNNING] `rustc [..]`
274
+ [FINISHED] ` test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
275
+ [DOCTEST] foo
276
+ [RUNNING] `rustdoc [..] --test src/lib.rs [..] --cfg=foo [..]`
277
+
278
+ "# ] ] )
219
279
. run ( ) ;
220
280
221
281
// target.triple.rustdocflags in config works
222
282
p. cargo ( "test --doc -v" )
223
283
. arg ( "--config" )
224
284
. arg ( format ! ( "target.{host}.rustdocflags=['--cfg', 'foo']" ) )
225
- . with_stderr_contains ( "[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`" )
226
- . with_stdout_contains (
227
- " \
228
- running 1 test
229
- test src/lib.rs - (line 2) ... ok
285
+ . with_stderr_data ( str! [ [ r#"
286
+ [FRESH] foo v0.0.1 ([ROOT]/foo)
287
+ [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
288
+ [DOCTEST] foo
289
+ [RUNNING] `rustdoc [..] -- test src/lib.rs [..] --cfg foo [..]`
230
290
231
- test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]" ,
232
- )
291
+ "# ] ] )
233
292
. run ( ) ;
234
293
}
0 commit comments