Skip to content

Commit fa4f390

Browse files
committed
test: migrate rustdocflags to snapbox
1 parent 3a46ef1 commit fa4f390

File tree

1 file changed

+78
-32
lines changed

1 file changed

+78
-32
lines changed

tests/testsuite/rustdocflags.rs

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
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+
...
16+
[RUNNING] `rustdoc [..] --cfg=foo[..]`
17+
...
18+
"#]])
1619
.run();
1720
}
1821

@@ -30,7 +33,11 @@ fn parses_config() {
3033
.build();
3134

3235
p.cargo("doc -v")
33-
.with_stderr_contains("[RUNNING] `rustdoc [..] --cfg foo[..]`")
36+
.with_stderr_data(str![[r#"
37+
...
38+
[RUNNING] `rustdoc [..] --cfg foo [..]`
39+
...
40+
"#]])
3441
.run();
3542
}
3643

@@ -41,7 +48,11 @@ fn bad_flags() {
4148
p.cargo("doc")
4249
.env("RUSTDOCFLAGS", "--bogus")
4350
.with_status(101)
44-
.with_stderr_contains("[..]bogus[..]")
51+
.with_stderr_data(str![[r#"
52+
...
53+
[ERROR] Unrecognized option: 'bogus'
54+
...
55+
"#]])
4556
.run();
4657
}
4758

@@ -52,20 +63,20 @@ fn rerun() {
5263
p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo").run();
5364
p.cargo("doc")
5465
.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-
)
66+
.with_stderr_data(str![[r#"
67+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
68+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
69+
70+
"#]])
5971
.run();
6072
p.cargo("doc")
6173
.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-
)
74+
.with_stderr_data(str![[r#"
75+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
76+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
77+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
78+
79+
"#]])
6980
.run();
7081
}
7182

@@ -102,7 +113,10 @@ fn rustdocflags_misspelled() {
102113

103114
p.cargo("doc")
104115
.env("RUSTDOC_FLAGS", "foo")
105-
.with_stderr_contains("[WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?")
116+
.with_stderr_data(str![[r#"
117+
[WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?
118+
...
119+
"#]])
106120
.run();
107121
}
108122

@@ -114,7 +128,11 @@ fn whitespace() {
114128
// "too many operands"
115129
p.cargo("doc")
116130
.env("RUSTDOCFLAGS", "--crate-version this has spaces")
117-
.with_stderr_contains("[ERROR] could not document `foo`")
131+
.with_stderr_data(str![[r#"
132+
...
133+
[ERROR] could not document `foo`
134+
...
135+
"#]])
118136
.with_status(101)
119137
.run();
120138

@@ -155,12 +173,20 @@ fn not_affected_by_target_rustflags() {
155173
// `cargo build` should fail due to missing docs.
156174
p.cargo("build -v")
157175
.with_status(101)
158-
.with_stderr_contains("[RUNNING] `rustc [..] -D missing-docs[..]`")
176+
.with_stderr_data(str![[r#"
177+
...
178+
[RUNNING] `rustc [..] -D missing-docs`
179+
...
180+
"#]])
159181
.run();
160182

161183
// `cargo doc` shouldn't fail.
162184
p.cargo("doc -v")
163-
.with_stderr_contains("[RUNNING] `rustdoc [..] --cfg foo[..]`")
185+
.with_stderr_data(str![[r#"
186+
...
187+
[RUNNING] `rustdoc [..] --cfg foo[..]`
188+
...
189+
"#]])
164190
.run();
165191
}
166192

@@ -176,14 +202,22 @@ fn target_triple_rustdocflags_works() {
176202
&format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"),
177203
"--cfg=foo",
178204
)
179-
.with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`")
205+
.with_stderr_data(str![[r#"
206+
...
207+
[RUNNING] `rustdoc[..]--cfg[..]foo[..]`
208+
...
209+
"#]])
180210
.run();
181211

182212
// target.triple.rustdocflags in config works
183213
p.cargo("doc -v")
184214
.arg("--config")
185215
.arg(format!("target.{host}.rustdocflags=['--cfg', 'foo']"))
186-
.with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`")
216+
.with_stderr_data(str![[r#"
217+
...
218+
[RUNNING] `rustdoc [..] --cfg foo [..]`
219+
...
220+
"#]])
187221
.run();
188222
}
189223

@@ -208,27 +242,39 @@ fn target_triple_rustdocflags_works_through_cargo_test() {
208242
&format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"),
209243
"--cfg=foo",
210244
)
211-
.with_stderr_contains("[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`")
212-
.with_stdout_contains(
213-
"\
245+
.with_stderr_data(str![[r#"
246+
...
247+
[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`
248+
249+
"#]])
250+
.with_stdout_data(str![[r#"
251+
214252
running 1 test
215253
test src/lib.rs - (line 2) ... ok
216254
217-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
218-
)
255+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
256+
257+
258+
"#]])
219259
.run();
220260

221261
// target.triple.rustdocflags in config works
222262
p.cargo("test --doc -v")
223263
.arg("--config")
224264
.arg(format!("target.{host}.rustdocflags=['--cfg', 'foo']"))
225-
.with_stderr_contains("[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`")
226-
.with_stdout_contains(
227-
"\
265+
.with_stderr_data(str![[r#"
266+
...
267+
[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`
268+
269+
"#]])
270+
.with_stdout_data(str![[r#"
271+
228272
running 1 test
229273
test src/lib.rs - (line 2) ... ok
230274
231-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
232-
)
275+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
276+
277+
278+
"#]])
233279
.run();
234280
}

0 commit comments

Comments
 (0)