Skip to content

Commit 8ebe711

Browse files
committed
test(patch-files): verify non-blocking gates and warnings
1 parent c1ca923 commit 8ebe711

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

tests/testsuite/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ mod owner;
134134
mod package;
135135
mod package_features;
136136
mod patch;
137+
mod patch_files;
137138
mod path;
138139
mod paths;
139140
mod pkgid;

tests/testsuite/patch_files.rs

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
//! Tests for unstable `patch-files` feature.
2+
3+
use cargo_test_support::registry::Package;
4+
use cargo_test_support::project;
5+
use cargo_test_support::str;
6+
7+
#[cargo_test]
8+
fn gated_manifest() {
9+
Package::new("bar", "1.0.0").publish();
10+
let p = project()
11+
.file(
12+
"Cargo.toml",
13+
r#"
14+
[package]
15+
name = "foo"
16+
edition = "2015"
17+
18+
[dependencies]
19+
bar = "1"
20+
21+
[patch.crates-io]
22+
bar = { version = "=1.0.0", patches = [] }
23+
"#,
24+
)
25+
.file("src/lib.rs", "")
26+
.build();
27+
28+
p.cargo("check")
29+
.with_status(101)
30+
.with_stderr_data(str![[r#"
31+
[WARNING] ignoring `patches` on patch for `bar` in `https://github.com/rust-lang/crates.io-index`; see https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#patch-files about the status of this feature.
32+
[UPDATING] `dummy-registry` index
33+
[ERROR] failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
34+
35+
Caused by:
36+
patch for `bar` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
37+
38+
"#]])
39+
.run();
40+
}
41+
42+
#[cargo_test]
43+
fn gated_config() {
44+
Package::new("bar", "1.0.0").publish();
45+
let p = project()
46+
.file(
47+
"Cargo.toml",
48+
r#"
49+
[package]
50+
name = "foo"
51+
edition = "2015"
52+
53+
[dependencies]
54+
bar = "1"
55+
56+
[patch.crates-io]
57+
bar = { version = "=1.0.0", patches = [] }
58+
"#,
59+
)
60+
.file("src/lib.rs", "")
61+
.file(
62+
".cargo/config.toml",
63+
r#"
64+
[patch.crates-io]
65+
bar = { version = "=1.0.0", patches = [] }
66+
"#,
67+
)
68+
.build();
69+
70+
p.cargo("check")
71+
.with_status(101)
72+
.with_stderr_data(str![[r#"
73+
[WARNING] ignoring `patches` on patch for `bar` in `https://github.com/rust-lang/crates.io-index`; see https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#patch-files about the status of this feature.
74+
[WARNING] [patch] in cargo config: ignoring `patches` on patch for `bar` in `https://github.com/rust-lang/crates.io-index`; see https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#patch-files about the status of this feature.
75+
[UPDATING] `dummy-registry` index
76+
[ERROR] failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
77+
78+
Caused by:
79+
patch for `bar` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
80+
81+
"#]])
82+
.run();
83+
}
84+
85+
#[cargo_test]
86+
fn warn_if_in_normal_dep() {
87+
Package::new("bar", "1.0.0").publish();
88+
let p = project()
89+
.file(
90+
"Cargo.toml",
91+
r#"
92+
[package]
93+
name = "foo"
94+
edition = "2015"
95+
96+
[dependencies]
97+
bar = { version = "1", patches = [] }
98+
"#,
99+
)
100+
.file("src/lib.rs", "")
101+
.build();
102+
103+
p.cargo("check")
104+
.with_stderr_data(str![[r#"
105+
[WARNING] unused manifest key: dependencies.bar.patches; see https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#patch-files about the status of this feature.
106+
[UPDATING] `dummy-registry` index
107+
[LOCKING] 2 packages to latest compatible versions
108+
[DOWNLOADING] crates ...
109+
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
110+
[CHECKING] bar v1.0.0
111+
[CHECKING] foo v0.0.0 ([ROOT]/foo)
112+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
113+
114+
"#]])
115+
.run();
116+
}

0 commit comments

Comments
 (0)