Skip to content

Commit e41c718

Browse files
committed
test: migrate build_script_extra_link_arg to snapbox
1 parent 00ea165 commit e41c718

File tree

1 file changed

+73
-50
lines changed

1 file changed

+73
-50
lines changed

tests/testsuite/build_script_extra_link_arg.rs

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
// because MSVC link.exe just gives a warning on unknown flags (how helpful!),
55
// and other linkers will return an error.
66

7-
#![allow(deprecated)]
8-
97
use cargo_test_support::registry::Package;
8+
use cargo_test_support::str;
109
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project};
1110

1211
#[cargo_test]
@@ -26,8 +25,11 @@ fn build_script_extra_link_arg_bin() {
2625

2726
p.cargo("build -v")
2827
.without_status()
29-
.with_stderr_contains(
30-
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
28+
.with_stderr_data(
29+
"\
30+
...
31+
[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]
32+
...",
3133
)
3234
.run();
3335
}
@@ -66,11 +68,17 @@ fn build_script_extra_link_arg_bin_single() {
6668

6769
p.cargo("build -v")
6870
.without_status()
69-
.with_stderr_contains(
70-
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-foo[..]",
71+
.with_stderr_data(
72+
"\
73+
...
74+
[RUNNING] `rustc --crate-name foo [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-foo[..]
75+
...",
7176
)
72-
.with_stderr_contains(
73-
"[RUNNING] `rustc --crate-name bar [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-bar[..]",
77+
.with_stderr_data(
78+
"\
79+
...
80+
[RUNNING] `rustc --crate-name bar [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-bar[..]
81+
...",
7482
)
7583
.run();
7684
}
@@ -92,8 +100,11 @@ fn build_script_extra_link_arg() {
92100

93101
p.cargo("build -v")
94102
.without_status()
95-
.with_stderr_contains(
96-
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
103+
.with_stderr_data(
104+
"\
105+
...
106+
[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]
107+
...",
97108
)
98109
.run();
99110
}
@@ -127,11 +138,12 @@ fn link_arg_missing_target() {
127138

128139
p.cargo("check")
129140
.with_status(101)
130-
.with_stderr("\
131-
[COMPILING] foo [..]
132-
error: invalid instruction `cargo::rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)`
141+
.with_stderr_data(str![[r#"
142+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
143+
[ERROR] invalid instruction `cargo::rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)`
133144
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target.
134-
")
145+
146+
"#]])
135147
.run();
136148

137149
p.change_file(
@@ -141,13 +153,12 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target.
141153

142154
p.cargo("check")
143155
.with_status(101)
144-
.with_stderr(
145-
"\
146-
[COMPILING] foo [..]
147-
error: invalid instruction `cargo::rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)`
156+
.with_stderr_data(str![[r#"
157+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
158+
[ERROR] invalid instruction `cargo::rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)`
148159
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `abc`.
149-
",
150-
)
160+
161+
"#]])
151162
.run();
152163

153164
p.change_file(
@@ -157,13 +168,12 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `ab
157168

158169
p.cargo("check")
159170
.with_status(101)
160-
.with_stderr(
161-
"\
162-
[COMPILING] foo [..]
163-
error: invalid instruction `cargo::rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)`
171+
.with_stderr_data(str![[r#"
172+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
173+
[ERROR] invalid instruction `cargo::rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)`
164174
The instruction should have the form cargo::rustc-link-arg-bin=BIN=ARG
165-
",
166-
)
175+
176+
"#]])
167177
.run();
168178
}
169179

@@ -203,24 +213,26 @@ fn cdylib_link_arg_transitive() {
203213
.build();
204214
p.cargo("build -v")
205215
.without_status()
206-
.with_stderr_contains(
216+
.with_stderr_data(
207217
"\
208-
[COMPILING] bar v1.0.0 [..]
218+
...
219+
[COMPILING] bar v1.0.0 ([ROOT]/foo/bar)
209220
[RUNNING] `rustc --crate-name build_script_build --edition=2015 bar/build.rs [..]
210-
[RUNNING] `[..]build-script-build[..]
211-
warning: [email protected]: cargo::rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \
221+
[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build`
222+
[WARNING] [email protected]: cargo::rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \
212223
([ROOT]/foo/bar), but that package does not contain a cdylib target
213224
214225
Allowing this was an unintended change in the 1.50 release, and may become an error in \
215226
the future. For more information, see <https://github.com/rust-lang/cargo/issues/9562>.
216227
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]
217-
[COMPILING] foo v0.1.0 [..]
228+
[COMPILING] foo v0.1.0 ([ROOT]/foo)
218229
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]-C link-arg=--bogus[..]`
219-
",
230+
...",
220231
)
221232
.run();
222233
}
223234

235+
#[allow(deprecated)]
224236
#[cargo_test]
225237
fn link_arg_transitive_not_allowed() {
226238
// Verify that transitive dependencies don't pass link args.
@@ -260,21 +272,20 @@ fn link_arg_transitive_not_allowed() {
260272
.build();
261273

262274
p.cargo("build -v")
263-
.with_stderr(
264-
"\
265-
[UPDATING] [..]
275+
.with_stderr_data(str![[r#"
276+
[UPDATING] `dummy-registry` index
266277
[LOCKING] 2 packages to latest compatible versions
267-
[DOWNLOADING] [..]
268-
[DOWNLOADED] [..]
278+
[DOWNLOADING] crates ...
279+
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
269280
[COMPILING] bar v1.0.0
270281
[RUNNING] `rustc --crate-name build_script_build [..]
271-
[RUNNING] `[..]/build-script-build[..]
282+
[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build`
272283
[RUNNING] `rustc --crate-name bar [..]
273-
[COMPILING] foo v0.1.0 [..]
284+
[COMPILING] foo v0.1.0 ([ROOT]/foo)
274285
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]
275-
[FINISHED] `dev` profile [..]
276-
",
277-
)
286+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
287+
288+
"#]])
278289
.with_stderr_does_not_contain("--bogus")
279290
.run();
280291
}
@@ -303,8 +314,11 @@ fn link_arg_with_doctest() {
303314

304315
p.cargo("test --doc -v")
305316
.without_status()
306-
.with_stderr_contains(
307-
"[RUNNING] `rustdoc [..]--crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
317+
.with_stderr_data(
318+
"\
319+
...
320+
[RUNNING] `rustdoc [..]--crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]
321+
...",
308322
)
309323
.run();
310324
}
@@ -327,8 +341,11 @@ fn build_script_extra_link_arg_tests() {
327341

328342
p.cargo("test -v")
329343
.without_status()
330-
.with_stderr_contains(
331-
"[RUNNING] `rustc --crate-name test_foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
344+
.with_stderr_data(
345+
"\
346+
...
347+
[RUNNING] `rustc --crate-name test_foo [..]-C link-arg=--this-is-a-bogus-flag[..]
348+
...",
332349
)
333350
.run();
334351
}
@@ -351,8 +368,11 @@ fn build_script_extra_link_arg_benches() {
351368

352369
p.cargo("bench -v")
353370
.without_status()
354-
.with_stderr_contains(
355-
"[RUNNING] `rustc --crate-name bench_foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
371+
.with_stderr_data(
372+
"\
373+
...
374+
[RUNNING] `rustc --crate-name bench_foo [..]-C link-arg=--this-is-a-bogus-flag[..]
375+
...",
356376
)
357377
.run();
358378
}
@@ -375,8 +395,11 @@ fn build_script_extra_link_arg_examples() {
375395

376396
p.cargo("build -v --examples")
377397
.without_status()
378-
.with_stderr_contains(
379-
"[RUNNING] `rustc --crate-name example_foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
398+
.with_stderr_data(
399+
"\
400+
...
401+
[RUNNING] `rustc --crate-name example_foo [..]-C link-arg=--this-is-a-bogus-flag[..]
402+
...",
380403
)
381404
.run();
382405
}

0 commit comments

Comments
 (0)