Skip to content

Commit 30ad4e3

Browse files
committed
test(patch-files): verify invalid manifest
1 parent 8b383cb commit 30ad4e3

File tree

1 file changed

+199
-1
lines changed

1 file changed

+199
-1
lines changed

tests/testsuite/patch_files.rs

+199-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//! Tests for unstable `patch-files` feature.
22
3-
use cargo_test_support::registry::Package;
3+
use cargo_test_support::basic_manifest;
4+
use cargo_test_support::git;
5+
use cargo_test_support::paths;
46
use cargo_test_support::project;
7+
use cargo_test_support::registry;
8+
use cargo_test_support::registry::Package;
59

610
#[cargo_test]
711
fn gated_manifest() {
@@ -116,3 +120,197 @@ fn warn_if_in_normal_dep() {
116120
)
117121
.run();
118122
}
123+
124+
#[cargo_test]
125+
fn disallow_non_exact_version() {
126+
Package::new("bar", "1.0.0").publish();
127+
let p = project()
128+
.file(
129+
"Cargo.toml",
130+
r#"
131+
cargo-features = ["patch-files"]
132+
133+
[package]
134+
name = "foo"
135+
edition = "2015"
136+
137+
[dependencies]
138+
bar = "1"
139+
140+
[patch.crates-io]
141+
bar = { version = "1.0.0", patches = [] }
142+
"#,
143+
)
144+
.file("src/lib.rs", "")
145+
.build();
146+
147+
p.cargo("check")
148+
.masquerade_as_nightly_cargo(&["patch-files"])
149+
.with_status(101)
150+
.with_stderr(
151+
"\
152+
[ERROR] failed to parse manifest at `[..]`
153+
154+
Caused by:
155+
patch for `bar` in `[..]` requires an exact version when patching with patch files
156+
",
157+
)
158+
.run();
159+
}
160+
161+
#[cargo_test]
162+
fn disallow_empty_patches_array() {
163+
Package::new("bar", "1.0.0").publish();
164+
let p = project()
165+
.file(
166+
"Cargo.toml",
167+
r#"
168+
cargo-features = ["patch-files"]
169+
170+
[package]
171+
name = "foo"
172+
edition = "2015"
173+
174+
[dependencies]
175+
bar = "1"
176+
177+
[patch.crates-io]
178+
bar = { version = "=1.0.0", patches = [] }
179+
"#,
180+
)
181+
.file("src/lib.rs", "")
182+
.build();
183+
184+
p.cargo("check")
185+
.masquerade_as_nightly_cargo(&["patch-files"])
186+
.with_status(101)
187+
.with_stderr(
188+
"\
189+
[ERROR] failed to parse manifest at `[..]`
190+
191+
Caused by:
192+
patch for `bar` in `[..]` requires at least one patch file when patching with patch files
193+
",
194+
)
195+
.run();
196+
}
197+
198+
#[cargo_test]
199+
fn disallow_mismatched_source_url() {
200+
registry::alt_init();
201+
Package::new("bar", "1.0.0").alternative(true).publish();
202+
let p = project()
203+
.file(
204+
"Cargo.toml",
205+
r#"
206+
cargo-features = ["patch-files"]
207+
208+
[package]
209+
name = "foo"
210+
edition = "2015"
211+
212+
[dependencies]
213+
bar = "1"
214+
215+
[patch.crates-io]
216+
bar = { version = "=1.0.0", registry = "alternative", patches = [] }
217+
"#,
218+
)
219+
.file("src/lib.rs", "")
220+
.build();
221+
222+
p.cargo("check")
223+
.masquerade_as_nightly_cargo(&["patch-files"])
224+
.with_status(101)
225+
.with_stderr(
226+
"\
227+
[ERROR] failed to parse manifest at `[..]`
228+
229+
Caused by:
230+
patch for `bar` in `[..]` must refer to the same source when patching with patch files
231+
",
232+
)
233+
.run();
234+
}
235+
236+
#[cargo_test]
237+
fn disallow_path_dep() {
238+
let p = project()
239+
.file(
240+
"Cargo.toml",
241+
r#"
242+
cargo-features = ["patch-files"]
243+
244+
[package]
245+
name = "foo"
246+
edition = "2015"
247+
248+
[dependencies]
249+
bar = "1"
250+
251+
[patch.crates-io]
252+
bar = { path = "bar", patches = [""] }
253+
"#,
254+
)
255+
.file("src/lib.rs", "")
256+
.file("bar/Cargo.toml", &basic_manifest("bar", "1.0.0"))
257+
.file("bar/src/lib.rs", "")
258+
.build();
259+
260+
p.cargo("check")
261+
.masquerade_as_nightly_cargo(&["patch-files"])
262+
.with_status(101)
263+
.with_stderr(
264+
"\
265+
[ERROR] failed to parse manifest at `[..]`
266+
267+
Caused by:
268+
patch for `bar` in `[..]` requires a registry source when patching with patch files
269+
",
270+
)
271+
.run();
272+
}
273+
274+
#[cargo_test]
275+
fn disallow_git_dep() {
276+
let git = git::repo(&paths::root().join("bar"))
277+
.file("Cargo.toml", &basic_manifest("bar", "1.0.0"))
278+
.file("src/lib.rs", "")
279+
.build();
280+
let url = git.url();
281+
282+
let p = project()
283+
.file(
284+
"Cargo.toml",
285+
&format!(
286+
r#"
287+
cargo-features = ["patch-files"]
288+
289+
[package]
290+
name = "foo"
291+
edition = "2015"
292+
293+
[dependencies]
294+
bar = "1"
295+
296+
[patch.crates-io]
297+
bar = {{ git = "{url}", patches = [""] }}
298+
"#
299+
),
300+
)
301+
.file("src/lib.rs", "")
302+
.build();
303+
304+
p.cargo("check")
305+
.masquerade_as_nightly_cargo(&["patch-files"])
306+
.with_status(101)
307+
.with_stderr(
308+
"\
309+
[ERROR] failed to parse manifest at `[..]`
310+
311+
Caused by:
312+
patch for `bar` in `[..]` requires a registry source when patching with patch files
313+
",
314+
)
315+
.run();
316+
}

0 commit comments

Comments
 (0)