Skip to content

Commit 33e0634

Browse files
committed
test: migrate rustdocflags to snapbox
1 parent ce493b0 commit 33e0634

File tree

1 file changed

+96
-37
lines changed

1 file changed

+96
-37
lines changed

tests/testsuite/rustdocflags.rs

Lines changed: 96 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
//! Tests for setting custom rustdoc flags.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::project;
64
use cargo_test_support::rustc_host;
75
use cargo_test_support::rustc_host_env;
6+
use cargo_test_support::str;
87

98
#[cargo_test]
109
fn parses_env() {
1110
let p = project().file("src/lib.rs", "").build();
1211

1312
p.cargo("doc -v")
1413
.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+
"#]])
1621
.run();
1722
}
1823

@@ -30,7 +35,13 @@ fn parses_config() {
3035
.build();
3136

3237
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+
"#]])
3445
.run();
3546
}
3647

@@ -41,7 +52,13 @@ fn bad_flags() {
4152
p.cargo("doc")
4253
.env("RUSTDOCFLAGS", "--bogus")
4354
.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+
"#]])
4562
.run();
4663
}
4764

@@ -52,20 +69,20 @@ fn rerun() {
5269
p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo").run();
5370
p.cargo("doc")
5471
.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+
"#]])
5977
.run();
6078
p.cargo("doc")
6179
.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+
"#]])
6986
.run();
7087
}
7188

@@ -102,7 +119,13 @@ fn rustdocflags_misspelled() {
102119

103120
p.cargo("doc")
104121
.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+
"#]])
106129
.run();
107130
}
108131

@@ -114,7 +137,13 @@ fn whitespace() {
114137
// "too many operands"
115138
p.cargo("doc")
116139
.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+
"#]])
118147
.with_status(101)
119148
.run();
120149

@@ -155,12 +184,30 @@ fn not_affected_by_target_rustflags() {
155184
// `cargo build` should fail due to missing docs.
156185
p.cargo("build -v")
157186
.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+
"#]])
159200
.run();
160201

161202
// `cargo doc` shouldn't fail.
162203
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+
"#]])
164211
.run();
165212
}
166213

@@ -176,14 +223,27 @@ fn target_triple_rustdocflags_works() {
176223
&format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"),
177224
"--cfg=foo",
178225
)
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+
"#]])
180233
.run();
181234

182235
// target.triple.rustdocflags in config works
183236
p.cargo("doc -v")
184237
.arg("--config")
185238
.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+
"#]])
187247
.run();
188248
}
189249

@@ -208,27 +268,26 @@ fn target_triple_rustdocflags_works_through_cargo_test() {
208268
&format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"),
209269
"--cfg=foo",
210270
)
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+
"#]])
219279
.run();
220280

221281
// target.triple.rustdocflags in config works
222282
p.cargo("test --doc -v")
223283
.arg("--config")
224284
.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 [..]`
230290
231-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
232-
)
291+
"#]])
233292
.run();
234293
}

0 commit comments

Comments
 (0)