Skip to content

Commit be78abd

Browse files
committed
Auto merge of #14098 - eth3lbert:snapbox-rustdoc, r=weihanglo
test: migrate rustdoc and rustdocflags to snapbox ### What does this PR try to resolve? Part of #14039. Migrate following to snapbox: - `tests/testsuite/rustdoc.rs` - `tests/testsuite/rustdocflags.rs`
2 parents 3ed207e + fa4f390 commit be78abd

File tree

2 files changed

+168
-150
lines changed

2 files changed

+168
-150
lines changed

tests/testsuite/rustdoc.rs

Lines changed: 90 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
//! Tests for the `cargo rustdoc` command.
22
3-
#![allow(deprecated)]
4-
3+
use cargo_test_support::str;
54
use cargo_test_support::{basic_manifest, cross_compile, project};
65

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

1110
p.cargo("rustdoc -v")
12-
.with_stderr(
13-
"\
14-
[DOCUMENTING] foo v0.0.1 ([CWD])
15-
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
16-
-o [CWD]/target/doc \
17-
[..] \
18-
-L dependency=[CWD]/target/debug/deps [..]`
19-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
20-
[GENERATED] [CWD]/target/doc/foo/index.html
21-
",
22-
)
11+
.with_stderr_data(str![[r#"
12+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
13+
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
14+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
15+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
16+
17+
"#]])
2318
.run();
2419
}
2520

@@ -29,13 +24,12 @@ fn rustdoc_simple_html() {
2924

3025
p.cargo("rustdoc --output-format html --open -v")
3126
.with_status(101)
32-
.with_stderr(
33-
"\
34-
error: the `--output-format` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
35-
[..]
27+
.with_stderr_data(str![[r#"
28+
[ERROR] the `--output-format` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
29+
See https://doc.rust-lang.org/book/[..].html for more information about Rust release channels.
3630
See https://github.com/rust-lang/cargo/issues/12103 for more information about the `--output-format` flag.
37-
",
38-
)
31+
32+
"#]])
3933
.run();
4034
}
4135

@@ -45,14 +39,13 @@ fn rustdoc_simple_json() {
4539

4640
p.cargo("rustdoc -Z unstable-options --output-format json -v")
4741
.masquerade_as_nightly_cargo(&["rustdoc-output-format"])
48-
.with_stderr(
49-
"\
50-
[DOCUMENTING] foo v0.0.1 ([CWD])
51-
[RUNNING] `rustdoc [..]--crate-name foo [..]-o [CWD]/target/doc [..]--output-format=json[..]
52-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
53-
[GENERATED] [CWD]/target/doc/foo.json
54-
",
55-
)
42+
.with_stderr_data(str![[r#"
43+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
44+
[RUNNING] `rustdoc [..] --crate-name foo [..]-o [ROOT]/foo/target/doc [..] --output-format=json[..]
45+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
46+
[GENERATED] [ROOT]/foo/target/doc/foo.json
47+
48+
"#]])
5649
.run();
5750
assert!(p.root().join("target/doc/foo.json").is_file());
5851
}
@@ -64,14 +57,13 @@ fn rustdoc_invalid_output_format() {
6457
p.cargo("rustdoc -Z unstable-options --output-format pdf -v")
6558
.masquerade_as_nightly_cargo(&["rustdoc-output-format"])
6659
.with_status(1)
67-
.with_stderr(
68-
"\
69-
error: invalid value 'pdf' for '--output-format <FMT>'
60+
.with_stderr_data(str![[r#"
61+
[ERROR] invalid value 'pdf' for '--output-format <FMT>'
7062
[possible values: html, json]
7163
7264
For more information, try '--help'.
73-
",
74-
)
65+
66+
"#]])
7567
.run();
7668
}
7769

@@ -81,11 +73,12 @@ fn rustdoc_json_stable() {
8173

8274
p.cargo("rustdoc -Z unstable-options --output-format json -v")
8375
.with_status(101)
84-
.with_stderr(
85-
"\
86-
error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
87-
[..]
88-
",
76+
.with_stderr_data(
77+
str![[r#"
78+
[ERROR] the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
79+
See https://doc.rust-lang.org/book/[..].html for more information about Rust release channels.
80+
81+
"#]]
8982
)
9083
.run();
9184
}
@@ -97,12 +90,11 @@ fn rustdoc_json_without_unstable_options() {
9790
p.cargo("rustdoc --output-format json -v")
9891
.masquerade_as_nightly_cargo(&["rustdoc-output-format"])
9992
.with_status(101)
100-
.with_stderr(
101-
"\
102-
error: the `--output-format` flag is unstable, pass `-Z unstable-options` to enable it
103-
[..]
104-
",
105-
)
93+
.with_stderr_data(str![[r#"
94+
[ERROR] the `--output-format` flag is unstable, pass `-Z unstable-options` to enable it
95+
See https://github.com/rust-lang/cargo/issues/12103 for more information about the `--output-format` flag.
96+
97+
"#]])
10698
.run();
10799
}
108100

@@ -111,19 +103,13 @@ fn rustdoc_args() {
111103
let p = project().file("src/lib.rs", "").build();
112104

113105
p.cargo("rustdoc -v -- --cfg=foo")
114-
.with_stderr(
115-
"\
116-
[DOCUMENTING] foo v0.0.1 ([CWD])
117-
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
118-
-o [CWD]/target/doc \
119-
[..] \
120-
--cfg=foo \
121-
-C metadata=[..] \
122-
-L dependency=[CWD]/target/debug/deps [..]`
123-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
124-
[GENERATED] [CWD]/target/doc/foo/index.html
125-
",
126-
)
106+
.with_stderr_data(str![[r#"
107+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
108+
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
109+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
110+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
111+
112+
"#]])
127113
.run();
128114
}
129115

@@ -134,7 +120,11 @@ fn rustdoc_binary_args_passed() {
134120
p.cargo("rustdoc -v")
135121
.arg("--")
136122
.arg("--markdown-no-toc")
137-
.with_stderr_contains("[RUNNING] `rustdoc [..] --markdown-no-toc[..]`")
123+
.with_stderr_data(str![[r#"
124+
...
125+
[RUNNING] `rustdoc [..] --markdown-no-toc[..]`
126+
...
127+
"#]])
138128
.run();
139129
}
140130

@@ -163,23 +153,16 @@ fn rustdoc_foo_with_bar_dependency() {
163153
.build();
164154

165155
foo.cargo("rustdoc -v -- --cfg=foo")
166-
.with_stderr(
167-
"\
156+
.with_stderr_data(str![[r#"
168157
[LOCKING] 2 packages to latest compatible versions
169-
[CHECKING] bar v0.0.1 ([..])
170-
[RUNNING] `rustc [..]bar/src/lib.rs [..]`
171-
[DOCUMENTING] foo v0.0.1 ([CWD])
172-
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
173-
-o [CWD]/target/doc \
174-
[..] \
175-
--cfg=foo \
176-
-C metadata=[..] \
177-
-L dependency=[CWD]/target/debug/deps \
178-
--extern [..]`
179-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
180-
[GENERATED] [CWD]/target/doc/foo/index.html
181-
",
182-
)
158+
[CHECKING] bar v0.0.1 ([ROOT]/bar)
159+
[RUNNING] `rustc [..] [ROOT]/bar/src/lib.rs [..]`
160+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
161+
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps --extern [..]`
162+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
163+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
164+
165+
"#]])
183166
.run();
184167
}
185168

@@ -208,20 +191,14 @@ fn rustdoc_only_bar_dependency() {
208191
.build();
209192

210193
foo.cargo("rustdoc -v -p bar -- --cfg=foo")
211-
.with_stderr(
212-
"\
194+
.with_stderr_data(str![[r#"
213195
[LOCKING] 2 packages to latest compatible versions
214-
[DOCUMENTING] bar v0.0.1 ([..])
215-
[RUNNING] `rustdoc [..]--crate-name bar [..]bar/src/lib.rs [..]\
216-
-o [CWD]/target/doc \
217-
[..] \
218-
--cfg=foo \
219-
-C metadata=[..] \
220-
-L dependency=[CWD]/target/debug/deps [..]`
221-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
222-
[GENERATED] [CWD]/target/doc/bar/index.html
223-
",
224-
)
196+
[DOCUMENTING] bar v0.0.1 ([ROOT]/bar)
197+
[RUNNING] `rustdoc [..] --crate-name bar [ROOT]/bar/src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
198+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
199+
[GENERATED] [ROOT]/foo/target/doc/bar/index.html
200+
201+
"#]])
225202
.run();
226203
}
227204

@@ -233,19 +210,13 @@ fn rustdoc_same_name_documents_lib() {
233210
.build();
234211

235212
p.cargo("rustdoc -v -- --cfg=foo")
236-
.with_stderr(
237-
"\
238-
[DOCUMENTING] foo v0.0.1 ([..])
239-
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
240-
-o [CWD]/target/doc \
241-
[..] \
242-
--cfg=foo \
243-
-C metadata=[..] \
244-
-L dependency=[CWD]/target/debug/deps [..]`
245-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
246-
[GENERATED] [CWD]/target/doc/foo/index.html
247-
",
248-
)
213+
.with_stderr_data(str![[r#"
214+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
215+
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
216+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
217+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
218+
219+
"#]])
249220
.run();
250221
}
251222

@@ -269,7 +240,11 @@ fn features() {
269240
.build();
270241

271242
p.cargo("rustdoc --verbose --features quux")
272-
.with_stderr_contains("[..]feature=[..]quux[..]")
243+
.with_stderr_data(str![[r#"
244+
...
245+
[RUNNING] `rustdoc [..]feature=[..]quux[..]`
246+
...
247+
"#]])
273248
.run();
274249
}
275250

@@ -294,11 +269,11 @@ fn proc_macro_crate_type() {
294269
.build();
295270

296271
p.cargo("rustdoc --verbose")
297-
.with_stderr_contains(
298-
"\
272+
.with_stderr_data(str![[r#"
273+
...
299274
[RUNNING] `rustdoc --edition=2015 --crate-type proc-macro [..]`
300-
",
301-
)
275+
...
276+
"#]])
302277
.run();
303278
}
304279

@@ -312,19 +287,13 @@ fn rustdoc_target() {
312287

313288
p.cargo("rustdoc --verbose --target")
314289
.arg(cross_compile::alternate())
315-
.with_stderr(format!(
316-
"\
317-
[DOCUMENTING] foo v0.0.1 ([..])
318-
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
319-
--target {target} \
320-
-o [CWD]/target/{target}/doc \
321-
[..] \
322-
-L dependency=[CWD]/target/{target}/debug/deps \
323-
-L dependency=[CWD]/target/debug/deps[..]`
324-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
325-
[GENERATED] [CWD]/target/[..]/doc/foo/index.html",
326-
target = cross_compile::alternate()
327-
))
290+
.with_stderr_data(str![[r#"
291+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
292+
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]--target [ALT_TARGET] -o [ROOT]/foo/target/[ALT_TARGET]/doc [..] -L dependency=[ROOT]/foo/target/[ALT_TARGET]/debug/deps -L dependency=[ROOT]/foo/target/debug/deps[..]`
293+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
294+
[GENERATED] [ROOT]/foo/target/[..]/doc/foo/index.html
295+
296+
"#]])
328297
.run();
329298
}
330299

@@ -344,6 +313,9 @@ fn fail_with_glob() {
344313

345314
p.cargo("rustdoc -p '*z'")
346315
.with_status(101)
347-
.with_stderr("[ERROR] Glob patterns on package selection are not supported.")
316+
.with_stderr_data(str![[r#"
317+
[ERROR] Glob patterns on package selection are not supported.
318+
319+
"#]])
348320
.run();
349321
}

0 commit comments

Comments
 (0)