Skip to content

Commit 103e675

Browse files
committed
Auto merge of #14103 - linyihai:migrate-pub-priv, r=weihanglo
test: Migrate `pub_priv.rs` to snapshot ### What does this PR try to resolve? Apply snapshot assertion on `tests/testsuite/pub_priv.rs` ### How should we test and review this PR? The migration is almost one-to-one. ### Additional information Part of #14039
2 parents be78abd + 485c88c commit 103e675

File tree

1 file changed

+95
-104
lines changed

1 file changed

+95
-104
lines changed

tests/testsuite/pub_priv.rs

+95-104
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Tests for public/private dependencies.
22
3-
#![allow(deprecated)]
4-
3+
use cargo_test_support::prelude::*;
54
use cargo_test_support::project;
65
use cargo_test_support::registry::{Dependency, Package};
6+
use cargo_test_support::str;
77

88
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
99
fn exported_priv_warning() {
@@ -37,11 +37,11 @@ fn exported_priv_warning() {
3737

3838
p.cargo("check --message-format=short")
3939
.masquerade_as_nightly_cargo(&["public-dependency"])
40-
.with_stderr_contains(
41-
"\
42-
src/lib.rs:3:13: warning: type `[..]FromPriv` from private dependency 'priv_dep' in public interface
43-
",
44-
)
40+
.with_stderr_data(str![[r#"
41+
...
42+
src/lib.rs:3:13: [WARNING] type `FromPriv` from private dependency 'priv_dep' in public interface
43+
...
44+
"#]])
4545
.run()
4646
}
4747

@@ -77,17 +77,16 @@ fn exported_pub_dep() {
7777

7878
p.cargo("check --message-format=short")
7979
.masquerade_as_nightly_cargo(&["public-dependency"])
80-
.with_stderr(
81-
"\
82-
[UPDATING] `[..]` index
80+
.with_stderr_data(str![[r#"
81+
[UPDATING] `dummy-registry` index
8382
[LOCKING] 2 packages to latest compatible versions
8483
[DOWNLOADING] crates ...
85-
[DOWNLOADED] pub_dep v0.1.0 ([..])
84+
[DOWNLOADED] pub_dep v0.1.0 (registry `dummy-registry`)
8685
[CHECKING] pub_dep v0.1.0
87-
[CHECKING] foo v0.0.1 ([CWD])
88-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
89-
",
90-
)
86+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
87+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
88+
89+
"#]])
9190
.run()
9291
}
9392

@@ -105,16 +104,15 @@ pub fn requires_nightly_cargo() {
105104

106105
p.cargo("check --message-format=short")
107106
.with_status(101)
108-
.with_stderr(
109-
"\
110-
error: failed to parse manifest at `[..]`
107+
.with_stderr_data(str![[r#"
108+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
111109
112110
Caused by:
113111
the cargo feature `public-dependency` requires a nightly version of Cargo, but this is the `stable` channel
114112
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
115113
See https://doc.rust-lang.org/[..]cargo/reference/unstable.html#public-dependency for more information about using this feature.
116-
"
117-
)
114+
115+
"#]])
118116
.run()
119117
}
120118

@@ -142,18 +140,17 @@ fn requires_feature() {
142140

143141
p.cargo("check --message-format=short")
144142
.masquerade_as_nightly_cargo(&["public-dependency"])
145-
.with_stderr(
146-
"\
143+
.with_stderr_data(str![[r#"
147144
[WARNING] ignoring `public` on dependency pub_dep, pass `-Zpublic-dependency` to enable support for it
148-
[UPDATING] `[..]` index
145+
[UPDATING] `dummy-registry` index
149146
[LOCKING] 2 packages to latest compatible versions
150147
[DOWNLOADING] crates ...
151-
[DOWNLOADED] pub_dep v0.1.0 ([..])
148+
[DOWNLOADED] pub_dep v0.1.0 (registry `dummy-registry`)
152149
[CHECKING] pub_dep v0.1.0
153-
[CHECKING] foo v0.0.1 ([CWD])
154-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
155-
",
156-
)
150+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
151+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
152+
153+
"#]])
157154
.run()
158155
}
159156

@@ -190,14 +187,13 @@ fn pub_dev_dependency() {
190187
p.cargo("check --message-format=short")
191188
.masquerade_as_nightly_cargo(&["public-dependency"])
192189
.with_status(101)
193-
.with_stderr(
194-
"\
195-
error: failed to parse manifest at `[..]`
190+
.with_stderr_data(str![[r#"
191+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
196192
197193
Caused by:
198194
'public' specifier can only be used on regular dependencies, not dev-dependencies
199-
",
200-
)
195+
196+
"#]])
201197
.run()
202198
}
203199

@@ -231,14 +227,13 @@ fn pub_dev_dependency_without_feature() {
231227

232228
p.cargo("check --message-format=short")
233229
.masquerade_as_nightly_cargo(&["public-dependency"])
234-
.with_stderr(
235-
"\
230+
.with_stderr_data(str![[r#"
236231
[WARNING] 'public' specifier can only be used on regular dependencies, not dev-dependencies
237-
[UPDATING] `[..]` index
232+
[UPDATING] `dummy-registry` index
238233
[LOCKING] 2 packages to latest compatible versions
239-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
240-
",
241-
)
234+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
235+
236+
"#]])
242237
.run()
243238
}
244239

@@ -290,14 +285,13 @@ fn workspace_pub_disallowed() {
290285
p.cargo("check")
291286
.masquerade_as_nightly_cargo(&["public-dependency"])
292287
.with_status(101)
293-
.with_stderr(
294-
"\
295-
error: failed to parse manifest at `[CWD]/Cargo.toml`
288+
.with_stderr_data(str![[r#"
289+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
296290
297291
Caused by:
298292
foo2 is public, but workspace dependencies cannot be public
299-
",
300-
)
293+
294+
"#]])
301295
.run()
302296
}
303297

@@ -333,17 +327,16 @@ fn allow_priv_in_tests() {
333327

334328
p.cargo("check --tests --message-format=short")
335329
.masquerade_as_nightly_cargo(&["public-dependency"])
336-
.with_stderr(
337-
"\
338-
[UPDATING] `[..]` index
330+
.with_stderr_data(str![[r#"
331+
[UPDATING] `dummy-registry` index
339332
[LOCKING] 2 packages to latest compatible versions
340333
[DOWNLOADING] crates ...
341-
[DOWNLOADED] priv_dep v0.1.0 ([..])
334+
[DOWNLOADED] priv_dep v0.1.0 (registry `dummy-registry`)
342335
[CHECKING] priv_dep v0.1.0
343-
[CHECKING] foo v0.0.1 ([CWD])
344-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
345-
",
346-
)
336+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
337+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
338+
339+
"#]])
347340
.run()
348341
}
349342

@@ -379,17 +372,16 @@ fn allow_priv_in_benchs() {
379372

380373
p.cargo("check --benches --message-format=short")
381374
.masquerade_as_nightly_cargo(&["public-dependency"])
382-
.with_stderr(
383-
"\
384-
[UPDATING] `[..]` index
375+
.with_stderr_data(str![[r#"
376+
[UPDATING] `dummy-registry` index
385377
[LOCKING] 2 packages to latest compatible versions
386378
[DOWNLOADING] crates ...
387-
[DOWNLOADED] priv_dep v0.1.0 ([..])
379+
[DOWNLOADED] priv_dep v0.1.0 (registry `dummy-registry`)
388380
[CHECKING] priv_dep v0.1.0
389-
[CHECKING] foo v0.0.1 ([CWD])
390-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
391-
",
392-
)
381+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
382+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
383+
384+
"#]])
393385
.run()
394386
}
395387

@@ -426,17 +418,16 @@ fn allow_priv_in_bins() {
426418

427419
p.cargo("check --bins --message-format=short")
428420
.masquerade_as_nightly_cargo(&["public-dependency"])
429-
.with_stderr(
430-
"\
431-
[UPDATING] `[..]` index
421+
.with_stderr_data(str![[r#"
422+
[UPDATING] `dummy-registry` index
432423
[LOCKING] 2 packages to latest compatible versions
433424
[DOWNLOADING] crates ...
434-
[DOWNLOADED] priv_dep v0.1.0 ([..])
425+
[DOWNLOADED] priv_dep v0.1.0 (registry `dummy-registry`)
435426
[CHECKING] priv_dep v0.1.0
436-
[CHECKING] foo v0.0.1 ([CWD])
437-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
438-
",
439-
)
427+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
428+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
429+
430+
"#]])
440431
.run()
441432
}
442433

@@ -473,17 +464,16 @@ fn allow_priv_in_examples() {
473464

474465
p.cargo("check --examples --message-format=short")
475466
.masquerade_as_nightly_cargo(&["public-dependency"])
476-
.with_stderr(
477-
"\
478-
[UPDATING] `[..]` index
467+
.with_stderr_data(str![[r#"
468+
[UPDATING] `dummy-registry` index
479469
[LOCKING] 2 packages to latest compatible versions
480470
[DOWNLOADING] crates ...
481-
[DOWNLOADED] priv_dep v0.1.0 ([..])
471+
[DOWNLOADED] priv_dep v0.1.0 (registry `dummy-registry`)
482472
[CHECKING] priv_dep v0.1.0
483-
[CHECKING] foo v0.0.1 ([CWD])
484-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
485-
",
486-
)
473+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
474+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
475+
476+
"#]])
487477
.run()
488478
}
489479

@@ -521,17 +511,16 @@ fn allow_priv_in_custom_build() {
521511

522512
p.cargo("check --all-targets --message-format=short")
523513
.masquerade_as_nightly_cargo(&["public-dependency"])
524-
.with_stderr(
525-
"\
526-
[UPDATING] `[..]` index
514+
.with_stderr_data(str![[r#"
515+
[UPDATING] `dummy-registry` index
527516
[LOCKING] 2 packages to latest compatible versions
528517
[DOWNLOADING] crates ...
529-
[DOWNLOADED] priv_dep v0.1.0 ([..])
518+
[DOWNLOADED] priv_dep v0.1.0 (registry `dummy-registry`)
530519
[COMPILING] priv_dep v0.1.0
531-
[COMPILING] foo v0.0.1 ([CWD])
532-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
533-
",
534-
)
520+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
521+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
522+
523+
"#]])
535524
.run()
536525
}
537526

@@ -576,19 +565,18 @@ fn publish_package_with_public_dependency() {
576565

577566
p.cargo("check --message-format=short")
578567
.masquerade_as_nightly_cargo(&["public-dependency"])
579-
.with_stderr(
580-
"\
581-
[UPDATING] `[..]` index
568+
.with_stderr_data(str![[r#"
569+
[UPDATING] `dummy-registry` index
582570
[LOCKING] 3 packages to latest compatible versions
583571
[DOWNLOADING] crates ...
584-
[DOWNLOADED] pub_bar v0.1.0 ([..])
585-
[DOWNLOADED] bar v0.1.0 ([..])
572+
[DOWNLOADED] pub_bar v0.1.0 (registry `dummy-registry`)
573+
[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`)
586574
[CHECKING] pub_bar v0.1.0
587575
[CHECKING] bar v0.1.0
588-
[CHECKING] foo v0.0.1 ([..])
589-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
590-
",
591-
)
576+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
577+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
578+
579+
"#]])
592580
.run()
593581
}
594582

@@ -634,12 +622,12 @@ fn verify_mix_cargo_feature_z() {
634622

635623
p.cargo("check -Zpublic-dependency --message-format=short")
636624
.masquerade_as_nightly_cargo(&["public-dependency"])
637-
.with_stderr_contains(
638-
"\
639-
src/lib.rs:5:13: warning: type `FromDep` from private dependency 'dep' in public interface
640-
src/lib.rs:6:13: warning: type `FromPriv` from private dependency 'priv_dep' in public interface
641-
",
642-
)
625+
.with_stderr_data(str![[r#"
626+
...
627+
src/lib.rs:5:13: [WARNING] type `FromDep` from private dependency 'dep' in public interface
628+
src/lib.rs:6:13: [WARNING] type `FromPriv` from private dependency 'priv_dep' in public interface
629+
...
630+
"#]])
643631
.run();
644632
}
645633

@@ -684,11 +672,14 @@ fn verify_z_public_dependency() {
684672

685673
p.cargo("check -Zpublic-dependency --message-format=short")
686674
.masquerade_as_nightly_cargo(&["public-dependency"])
687-
.with_stderr_contains(
688-
"\
689-
src/lib.rs:5:13: warning: type `FromDep` from private dependency 'dep' in public interface
690-
src/lib.rs:6:13: warning: type `FromPriv` from private dependency 'priv_dep' in public interface
691-
",
675+
.with_stderr_data(
676+
str![[r#"
677+
...
678+
src/lib.rs:5:13: [WARNING] type `FromDep` from private dependency 'dep' in public interface
679+
src/lib.rs:6:13: [WARNING] type `FromPriv` from private dependency 'priv_dep' in public interface
680+
...
681+
"#]]
682+
.unordered(),
692683
)
693684
.run();
694685
}

0 commit comments

Comments
 (0)