]> git.proxmox.com Git - cargo.git/blame - tests/testsuite/registry.rs
Require http-registry URLs to end with a '/'
[cargo.git] / tests / testsuite / registry.rs
CommitLineData
83571aee
EH
1//! Tests for normal registry dependencies.
2
1dae5acb 3use cargo::core::SourceId;
9115b2c3 4use cargo_test_support::paths::{self, CargoPathExt};
412b6339
AS
5use cargo_test_support::registry::{
6 self, registry_path, serve_registry, Dependency, Package, RegistryServer,
7};
8use cargo_test_support::{basic_manifest, project, Execs, Project};
05a8127c
SJ
9use cargo_test_support::{cargo_process, registry::registry_url};
10use cargo_test_support::{git, install::cargo_home, t};
1dae5acb 11use cargo_util::paths::remove_dir_all;
4ae79d2f 12use std::fs::{self, File};
88f3bb9a 13use std::io::{BufRead, BufReader, Write};
4ae79d2f 14use std::path::Path;
88f3bb9a 15use std::process::Stdio;
07b06e9a 16
412b6339
AS
17fn cargo_http(p: &Project, s: &str) -> Execs {
18 let mut e = p.cargo(s);
19 e.arg("-Zhttp-registry").masquerade_as_nightly_cargo();
20 e
21}
22
23fn cargo_stable(p: &Project, s: &str) -> Execs {
24 p.cargo(s)
25}
26
27fn setup_http() -> RegistryServer {
28 let server = serve_registry(registry_path());
29 configure_source_replacement_for_http(&server.addr().to_string());
30 server
31}
32
33fn configure_source_replacement_for_http(addr: &str) {
34 let root = paths::root();
35 t!(fs::create_dir(&root.join(".cargo")));
36 t!(fs::write(
37 root.join(".cargo/config"),
38 format!(
39 "
40 [source.crates-io]
41 replace-with = 'dummy-registry'
42
43 [source.dummy-registry]
2622074d 44 registry = 'sparse+http://{}/'
412b6339
AS
45 ",
46 addr
47 )
48 ));
49}
50
0e0d9688 51#[cargo_test]
412b6339
AS
52fn simple_http() {
53 let _server = setup_http();
54 simple(cargo_http);
55}
56
57#[cargo_test]
58fn simple_git() {
59 simple(cargo_stable);
60}
61
62fn simple(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 63 let p = project()
1e682848
AC
64 .file(
65 "Cargo.toml",
66 r#"
6f8c7d5a
EH
67 [project]
68 name = "foo"
69 version = "0.0.1"
70 authors = []
07b06e9a 71
6f8c7d5a
EH
72 [dependencies]
73 bar = ">= 0.0.0"
74 "#,
fecb7246
AC
75 )
76 .file("src/main.rs", "fn main() {}")
d43ee1dd 77 .build();
07b06e9a 78
80d1ba7f 79 Package::new("bar", "0.0.1").publish();
a23c49ba 80
412b6339 81 cargo(&p, "build")
8c75e2ff 82 .with_stderr(
1e682848 83 "\
8c75e2ff 84[UPDATING] `dummy-registry` index
e2637b65 85[DOWNLOADING] crates ...
8c75e2ff 86[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
8214bb95 87[COMPILING] bar v0.0.1
89f43938 88[COMPILING] foo v0.0.1 ([CWD])
35728137 89[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
07b06e9a 90",
8c75e2ff 91 )
fecb7246 92 .run();
eccdcae0 93
412b6339 94 cargo(&p, "clean").run();
5e8eef97 95
7e366c2e
MP
96 assert!(paths::home().join(".cargo/registry/CACHEDIR.TAG").is_file());
97
eccdcae0 98 // Don't download a second time
412b6339 99 cargo(&p, "build")
2cd9cce6 100 .with_stderr(
1e682848 101 "\
8214bb95 102[COMPILING] bar v0.0.1
89f43938 103[COMPILING] foo v0.0.1 ([CWD])
35728137 104[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
eccdcae0 105",
fecb7246
AC
106 )
107 .run();
6950bbb0 108}
07b06e9a 109
0e0d9688 110#[cargo_test]
412b6339
AS
111fn deps_http() {
112 let _server = setup_http();
113 deps(cargo_http);
114}
115
116#[cargo_test]
117fn deps_git() {
118 deps(cargo_stable);
119}
120
121fn deps(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 122 let p = project()
1e682848
AC
123 .file(
124 "Cargo.toml",
125 r#"
6f8c7d5a
EH
126 [project]
127 name = "foo"
128 version = "0.0.1"
129 authors = []
07b06e9a 130
6f8c7d5a
EH
131 [dependencies]
132 bar = ">= 0.0.0"
133 "#,
fecb7246
AC
134 )
135 .file("src/main.rs", "fn main() {}")
d43ee1dd 136 .build();
07b06e9a 137
80d1ba7f
AC
138 Package::new("baz", "0.0.1").publish();
139 Package::new("bar", "0.0.1").dep("baz", "*").publish();
a23c49ba 140
412b6339 141 cargo(&p, "build")
8c75e2ff 142 .with_stderr(
1e682848 143 "\
8c75e2ff 144[UPDATING] `dummy-registry` index
e2637b65 145[DOWNLOADING] crates ...
8c75e2ff
WL
146[DOWNLOADED] [..] v0.0.1 (registry `dummy-registry`)
147[DOWNLOADED] [..] v0.0.1 (registry `dummy-registry`)
8214bb95
AC
148[COMPILING] baz v0.0.1
149[COMPILING] bar v0.0.1
89f43938 150[COMPILING] foo v0.0.1 ([CWD])
35728137 151[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
07b06e9a 152",
8c75e2ff 153 )
fecb7246 154 .run();
7e366c2e
MP
155
156 assert!(paths::home().join(".cargo/registry/CACHEDIR.TAG").is_file());
6950bbb0 157}
07b06e9a 158
0e0d9688 159#[cargo_test]
412b6339
AS
160fn nonexistent_http() {
161 let _server = setup_http();
162 nonexistent(cargo_http);
163}
164
165#[cargo_test]
166fn nonexistent_git() {
167 nonexistent(cargo_stable);
168}
169
170fn nonexistent(cargo: fn(&Project, &str) -> Execs) {
80d1ba7f
AC
171 Package::new("init", "0.0.1").publish();
172
7fe2fbc8 173 let p = project()
1e682848
AC
174 .file(
175 "Cargo.toml",
176 r#"
6f8c7d5a
EH
177 [project]
178 name = "foo"
179 version = "0.0.1"
180 authors = []
07b06e9a 181
6f8c7d5a
EH
182 [dependencies]
183 nonexistent = ">= 0.0.0"
184 "#,
fecb7246
AC
185 )
186 .file("src/main.rs", "fn main() {}")
d43ee1dd 187 .build();
07b06e9a 188
412b6339 189 cargo(&p, "build")
85984a87
DW
190 .with_status(101)
191 .with_stderr(
1e682848 192 "\
41aa6fba 193[UPDATING] [..] index
0117eb1f 194error: no matching package named `nonexistent` found
8214bb95 195location searched: registry [..]
0117eb1f 196required by package `foo v0.0.1 ([..])`
1e682848 197",
fecb7246
AC
198 )
199 .run();
6950bbb0 200}
07b06e9a 201
0e0d9688 202#[cargo_test]
412b6339
AS
203fn wrong_case_http() {
204 let _server = setup_http();
205 wrong_case(cargo_http);
206}
207
208#[cargo_test]
209fn wrong_case_git() {
210 wrong_case(cargo_stable);
211}
212
213fn wrong_case(cargo: fn(&Project, &str) -> Execs) {
3fafca17
E
214 Package::new("init", "0.0.1").publish();
215
7fe2fbc8 216 let p = project()
3fafca17
E
217 .file(
218 "Cargo.toml",
219 r#"
6f8c7d5a
EH
220 [project]
221 name = "foo"
222 version = "0.0.1"
223 authors = []
3fafca17 224
6f8c7d5a
EH
225 [dependencies]
226 Init = ">= 0.0.0"
227 "#,
fecb7246
AC
228 )
229 .file("src/main.rs", "fn main() {}")
3fafca17
E
230 .build();
231
84cc3d8b 232 // #5678 to make this work
412b6339 233 cargo(&p, "build")
85984a87
DW
234 .with_status(101)
235 .with_stderr(
3fafca17 236 "\
41aa6fba 237[UPDATING] [..] index
dc0e53b7 238error: no matching package found
239searched package name: `Init`
240perhaps you meant: init
3fafca17
E
241location searched: registry [..]
242required by package `foo v0.0.1 ([..])`
243",
fecb7246
AC
244 )
245 .run();
3fafca17
E
246}
247
0e0d9688 248#[cargo_test]
412b6339
AS
249fn mis_hyphenated_http() {
250 let _server = setup_http();
251 mis_hyphenated(cargo_http);
252}
253
254#[cargo_test]
255fn mis_hyphenated_git() {
256 mis_hyphenated(cargo_stable);
257}
258
259fn mis_hyphenated(cargo: fn(&Project, &str) -> Execs) {
3fafca17
E
260 Package::new("mis-hyphenated", "0.0.1").publish();
261
7fe2fbc8 262 let p = project()
3fafca17
E
263 .file(
264 "Cargo.toml",
265 r#"
6f8c7d5a
EH
266 [project]
267 name = "foo"
268 version = "0.0.1"
269 authors = []
3fafca17 270
6f8c7d5a
EH
271 [dependencies]
272 mis_hyphenated = ">= 0.0.0"
273 "#,
fecb7246
AC
274 )
275 .file("src/main.rs", "fn main() {}")
3fafca17
E
276 .build();
277
84cc3d8b 278 // #2775 to make this work
412b6339 279 cargo(&p, "build")
85984a87
DW
280 .with_status(101)
281 .with_stderr(
3fafca17 282 "\
41aa6fba 283[UPDATING] [..] index
dc0e53b7 284error: no matching package found
285searched package name: `mis_hyphenated`
286perhaps you meant: mis-hyphenated
3fafca17
E
287location searched: registry [..]
288required by package `foo v0.0.1 ([..])`
289",
fecb7246
AC
290 )
291 .run();
3fafca17
E
292}
293
0e0d9688 294#[cargo_test]
412b6339
AS
295fn wrong_version_http() {
296 let _server = setup_http();
297 wrong_version(cargo_http);
298}
299
300#[cargo_test]
301fn wrong_version_git() {
302 wrong_version(cargo_stable);
303}
304
305fn wrong_version(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 306 let p = project()
1e682848
AC
307 .file(
308 "Cargo.toml",
309 r#"
6f8c7d5a
EH
310 [project]
311 name = "foo"
312 version = "0.0.1"
313 authors = []
96589b35 314
6f8c7d5a
EH
315 [dependencies]
316 foo = ">= 1.0.0"
317 "#,
fecb7246
AC
318 )
319 .file("src/main.rs", "fn main() {}")
d43ee1dd 320 .build();
96589b35 321
80d1ba7f
AC
322 Package::new("foo", "0.0.1").publish();
323 Package::new("foo", "0.0.2").publish();
96589b35 324
412b6339 325 cargo(&p, "build")
85984a87
DW
326 .with_status(101)
327 .with_stderr_contains(
1e682848 328 "\
556c236f 329error: failed to select a version for the requirement `foo = \">=1.0.0\"`
6514c289
AC
330candidate versions found which didn't match: 0.0.2, 0.0.1
331location searched: `[..]` index (which is replacing registry `[..]`)
0117eb1f 332required by package `foo v0.0.1 ([..])`
1e682848 333",
fecb7246
AC
334 )
335 .run();
96589b35 336
80d1ba7f
AC
337 Package::new("foo", "0.0.3").publish();
338 Package::new("foo", "0.0.4").publish();
96589b35 339
412b6339 340 cargo(&p, "build")
85984a87
DW
341 .with_status(101)
342 .with_stderr_contains(
1e682848 343 "\
556c236f 344error: failed to select a version for the requirement `foo = \">=1.0.0\"`
6514c289
AC
345candidate versions found which didn't match: 0.0.4, 0.0.3, 0.0.2, ...
346location searched: `[..]` index (which is replacing registry `[..]`)
0117eb1f 347required by package `foo v0.0.1 ([..])`
1e682848 348",
fecb7246
AC
349 )
350 .run();
6950bbb0 351}
96589b35 352
0e0d9688 353#[cargo_test]
412b6339
AS
354fn bad_cksum_http() {
355 let _server = setup_http();
356 bad_cksum(cargo_http);
357}
358
359#[cargo_test]
360fn bad_cksum_git() {
361 bad_cksum(cargo_stable);
362}
363
364fn bad_cksum(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 365 let p = project()
1e682848
AC
366 .file(
367 "Cargo.toml",
368 r#"
6f8c7d5a
EH
369 [project]
370 name = "foo"
371 version = "0.0.1"
372 authors = []
07b06e9a 373
6f8c7d5a
EH
374 [dependencies]
375 bad-cksum = ">= 0.0.0"
376 "#,
fecb7246
AC
377 )
378 .file("src/main.rs", "fn main() {}")
d43ee1dd 379 .build();
07b06e9a 380
80d1ba7f
AC
381 let pkg = Package::new("bad-cksum", "0.0.1");
382 pkg.publish();
c3a95990 383 t!(File::create(&pkg.archive_dst()));
a23c49ba 384
412b6339 385 cargo(&p, "build -v")
85984a87
DW
386 .with_status(101)
387 .with_stderr(
1e682848 388 "\
41aa6fba 389[UPDATING] [..] index
e2637b65
AC
390[DOWNLOADING] crates ...
391[DOWNLOADED] bad-cksum [..]
8c75e2ff 392[ERROR] failed to download replaced source registry `crates-io`
8214bb95 393
07b06e9a 394Caused by:
8c75e2ff 395 failed to verify the checksum of `bad-cksum v0.0.1 (registry `dummy-registry`)`
1e682848 396",
fecb7246
AC
397 )
398 .run();
6950bbb0 399}
07b06e9a 400
0e0d9688 401#[cargo_test]
412b6339
AS
402fn update_registry_http() {
403 let _server = setup_http();
404 update_registry(cargo_http);
405}
406
407#[cargo_test]
408fn update_registry_git() {
409 update_registry(cargo_stable);
410}
411
412fn update_registry(cargo: fn(&Project, &str) -> Execs) {
80d1ba7f
AC
413 Package::new("init", "0.0.1").publish();
414
7fe2fbc8 415 let p = project()
1e682848
AC
416 .file(
417 "Cargo.toml",
418 r#"
6f8c7d5a
EH
419 [project]
420 name = "foo"
421 version = "0.0.1"
422 authors = []
07b06e9a 423
6f8c7d5a
EH
424 [dependencies]
425 notyet = ">= 0.0.0"
426 "#,
fecb7246
AC
427 )
428 .file("src/main.rs", "fn main() {}")
d43ee1dd 429 .build();
07b06e9a 430
412b6339 431 cargo(&p, "build")
85984a87
DW
432 .with_status(101)
433 .with_stderr_contains(
1e682848 434 "\
0117eb1f
E
435error: no matching package named `notyet` found
436location searched: registry `[..]`
437required by package `foo v0.0.1 ([..])`
1e682848 438",
fecb7246
AC
439 )
440 .run();
07b06e9a 441
80d1ba7f 442 Package::new("notyet", "0.0.1").publish();
07b06e9a 443
412b6339 444 cargo(&p, "build")
8c75e2ff 445 .with_stderr(
1e682848 446 "\
8c75e2ff 447[UPDATING] `dummy-registry` index
e2637b65 448[DOWNLOADING] crates ...
8c75e2ff 449[DOWNLOADED] notyet v0.0.1 (registry `dummy-registry`)
8214bb95 450[COMPILING] notyet v0.0.1
89f43938 451[COMPILING] foo v0.0.1 ([CWD])
35728137 452[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
07b06e9a 453",
8c75e2ff 454 )
fecb7246 455 .run();
6950bbb0 456}
9fba127e 457
0e0d9688 458#[cargo_test]
412b6339
AS
459fn package_with_path_deps_http() {
460 let _server = setup_http();
461 package_with_path_deps(cargo_http);
462}
463
464#[cargo_test]
465fn package_with_path_deps_git() {
466 package_with_path_deps(cargo_stable);
467}
468
469fn package_with_path_deps(cargo: fn(&Project, &str) -> Execs) {
80d1ba7f
AC
470 Package::new("init", "0.0.1").publish();
471
7fe2fbc8 472 let p = project()
1e682848
AC
473 .file(
474 "Cargo.toml",
475 r#"
6f8c7d5a
EH
476 [project]
477 name = "foo"
478 version = "0.0.1"
479 authors = []
480 license = "MIT"
481 description = "foo"
482 repository = "bar"
9fba127e 483
6f8c7d5a
EH
484 [dependencies.notyet]
485 version = "0.0.1"
486 path = "notyet"
487 "#,
fecb7246
AC
488 )
489 .file("src/main.rs", "fn main() {}")
ab19c483 490 .file("notyet/Cargo.toml", &basic_manifest("notyet", "0.0.1"))
d43ee1dd
NK
491 .file("notyet/src/lib.rs", "")
492 .build();
9fba127e 493
412b6339 494 cargo(&p, "package")
85984a87
DW
495 .with_status(101)
496 .with_stderr_contains(
1e682848 497 "\
156c6512
EH
498[PACKAGING] foo [..]
499[UPDATING] [..]
500[ERROR] failed to prepare local package for uploading
501
502Caused by:
503 no matching package named `notyet` found
8c75e2ff 504 location searched: registry `crates-io`
6514c289 505 required by package `foo v0.0.1 [..]`
1e682848 506",
fecb7246
AC
507 )
508 .run();
9fba127e 509
80d1ba7f 510 Package::new("notyet", "0.0.1").publish();
9fba127e 511
412b6339 512 cargo(&p, "package")
2cd9cce6 513 .with_stderr(
1e682848 514 "\
90887707 515[PACKAGING] foo v0.0.1 ([CWD])
156c6512 516[UPDATING] `[..]` index
34307c61 517[VERIFYING] foo v0.0.1 ([CWD])
e2637b65 518[DOWNLOADING] crates ...
8c75e2ff 519[DOWNLOADED] notyet v0.0.1 (registry `dummy-registry`)
8214bb95 520[COMPILING] notyet v0.0.1
89f43938 521[COMPILING] foo v0.0.1 ([CWD][..])
35728137 522[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
1e682848 523",
fecb7246
AC
524 )
525 .run();
6950bbb0 526}
816373d9 527
0e0d9688 528#[cargo_test]
412b6339
AS
529fn lockfile_locks_http() {
530 let _server = setup_http();
531 lockfile_locks(cargo_http);
532}
533
534#[cargo_test]
535fn lockfile_locks_git() {
536 lockfile_locks(cargo_stable);
537}
538
539fn lockfile_locks(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 540 let p = project()
1e682848
AC
541 .file(
542 "Cargo.toml",
543 r#"
6f8c7d5a
EH
544 [project]
545 name = "foo"
546 version = "0.0.1"
547 authors = []
816373d9 548
6f8c7d5a
EH
549 [dependencies]
550 bar = "*"
551 "#,
fecb7246
AC
552 )
553 .file("src/main.rs", "fn main() {}")
d43ee1dd 554 .build();
816373d9 555
80d1ba7f 556 Package::new("bar", "0.0.1").publish();
816373d9 557
412b6339 558 cargo(&p, "build")
2cd9cce6 559 .with_stderr(
1e682848 560 "\
41aa6fba 561[UPDATING] `[..]` index
e2637b65 562[DOWNLOADING] crates ...
8c75e2ff 563[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
8214bb95 564[COMPILING] bar v0.0.1
89f43938 565[COMPILING] foo v0.0.1 ([CWD])
35728137 566[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 567",
fecb7246
AC
568 )
569 .run();
816373d9 570
763ba535 571 p.root().move_into_the_past();
80d1ba7f 572 Package::new("bar", "0.0.2").publish();
816373d9 573
412b6339 574 cargo(&p, "build").with_stdout("").run();
6950bbb0 575}
816373d9 576
0e0d9688 577#[cargo_test]
412b6339
AS
578fn lockfile_locks_transitively_http() {
579 let _server = setup_http();
580 lockfile_locks_transitively(cargo_http);
581}
582
583#[cargo_test]
584fn lockfile_locks_transitively_git() {
585 lockfile_locks_transitively(cargo_stable);
586}
587
588fn lockfile_locks_transitively(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 589 let p = project()
1e682848
AC
590 .file(
591 "Cargo.toml",
592 r#"
6f8c7d5a
EH
593 [project]
594 name = "foo"
595 version = "0.0.1"
596 authors = []
816373d9 597
6f8c7d5a
EH
598 [dependencies]
599 bar = "*"
600 "#,
fecb7246
AC
601 )
602 .file("src/main.rs", "fn main() {}")
d43ee1dd 603 .build();
816373d9 604
80d1ba7f
AC
605 Package::new("baz", "0.0.1").publish();
606 Package::new("bar", "0.0.1").dep("baz", "*").publish();
816373d9 607
412b6339 608 cargo(&p, "build")
2cd9cce6 609 .with_stderr(
1e682848 610 "\
41aa6fba 611[UPDATING] `[..]` index
e2637b65 612[DOWNLOADING] crates ...
8c75e2ff
WL
613[DOWNLOADED] [..] v0.0.1 (registry `dummy-registry`)
614[DOWNLOADED] [..] v0.0.1 (registry `dummy-registry`)
8214bb95
AC
615[COMPILING] baz v0.0.1
616[COMPILING] bar v0.0.1
89f43938 617[COMPILING] foo v0.0.1 ([CWD])
35728137 618[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 619",
fecb7246
AC
620 )
621 .run();
816373d9 622
763ba535 623 p.root().move_into_the_past();
80d1ba7f
AC
624 Package::new("baz", "0.0.2").publish();
625 Package::new("bar", "0.0.2").dep("baz", "*").publish();
816373d9 626
412b6339 627 cargo(&p, "build").with_stdout("").run();
6950bbb0 628}
88116d4d 629
0e0d9688 630#[cargo_test]
412b6339
AS
631fn yanks_are_not_used_http() {
632 let _server = setup_http();
633 yanks_are_not_used(cargo_http);
634}
635
636#[cargo_test]
637fn yanks_are_not_used_git() {
638 yanks_are_not_used(cargo_stable);
639}
640
641fn yanks_are_not_used(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 642 let p = project()
1e682848
AC
643 .file(
644 "Cargo.toml",
645 r#"
6f8c7d5a
EH
646 [project]
647 name = "foo"
648 version = "0.0.1"
649 authors = []
88116d4d 650
6f8c7d5a
EH
651 [dependencies]
652 bar = "*"
653 "#,
fecb7246
AC
654 )
655 .file("src/main.rs", "fn main() {}")
d43ee1dd 656 .build();
88116d4d 657
80d1ba7f
AC
658 Package::new("baz", "0.0.1").publish();
659 Package::new("baz", "0.0.2").yanked(true).publish();
660 Package::new("bar", "0.0.1").dep("baz", "*").publish();
1e682848
AC
661 Package::new("bar", "0.0.2")
662 .dep("baz", "*")
663 .yanked(true)
664 .publish();
88116d4d 665
412b6339 666 cargo(&p, "build")
2cd9cce6 667 .with_stderr(
1e682848 668 "\
41aa6fba 669[UPDATING] `[..]` index
e2637b65 670[DOWNLOADING] crates ...
8c75e2ff
WL
671[DOWNLOADED] [..] v0.0.1 (registry `dummy-registry`)
672[DOWNLOADED] [..] v0.0.1 (registry `dummy-registry`)
8214bb95
AC
673[COMPILING] baz v0.0.1
674[COMPILING] bar v0.0.1
89f43938 675[COMPILING] foo v0.0.1 ([CWD])
35728137 676[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 677",
fecb7246
AC
678 )
679 .run();
6950bbb0 680}
88116d4d 681
0e0d9688 682#[cargo_test]
412b6339
AS
683fn relying_on_a_yank_is_bad_http() {
684 let _server = setup_http();
685 relying_on_a_yank_is_bad(cargo_http);
686}
687
688#[cargo_test]
689fn relying_on_a_yank_is_bad_git() {
690 relying_on_a_yank_is_bad(cargo_stable);
691}
692
693fn relying_on_a_yank_is_bad(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 694 let p = project()
1e682848
AC
695 .file(
696 "Cargo.toml",
697 r#"
6f8c7d5a
EH
698 [project]
699 name = "foo"
700 version = "0.0.1"
701 authors = []
88116d4d 702
6f8c7d5a
EH
703 [dependencies]
704 bar = "*"
705 "#,
fecb7246
AC
706 )
707 .file("src/main.rs", "fn main() {}")
d43ee1dd 708 .build();
88116d4d 709
80d1ba7f
AC
710 Package::new("baz", "0.0.1").publish();
711 Package::new("baz", "0.0.2").yanked(true).publish();
712 Package::new("bar", "0.0.1").dep("baz", "=0.0.2").publish();
88116d4d 713
412b6339 714 cargo(&p, "build")
85984a87
DW
715 .with_status(101)
716 .with_stderr_contains(
1e682848 717 "\
556c236f 718error: failed to select a version for the requirement `baz = \"=0.0.2\"`
6514c289
AC
719candidate versions found which didn't match: 0.0.1
720location searched: `[..]` index (which is replacing registry `[..]`)
0117eb1f 721required by package `bar v0.0.1`
0afd40b4 722 ... which satisfies dependency `bar = \"*\"` of package `foo [..]`
1e682848 723",
fecb7246
AC
724 )
725 .run();
6950bbb0 726}
88116d4d 727
0e0d9688 728#[cargo_test]
412b6339
AS
729fn yanks_in_lockfiles_are_ok_http() {
730 let _server = setup_http();
731 yanks_in_lockfiles_are_ok(cargo_http);
732}
733
734#[cargo_test]
735fn yanks_in_lockfiles_are_ok_git() {
736 yanks_in_lockfiles_are_ok(cargo_stable);
737}
738
739fn yanks_in_lockfiles_are_ok(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 740 let p = project()
1e682848
AC
741 .file(
742 "Cargo.toml",
743 r#"
6f8c7d5a
EH
744 [project]
745 name = "foo"
746 version = "0.0.1"
747 authors = []
88116d4d 748
6f8c7d5a
EH
749 [dependencies]
750 bar = "*"
751 "#,
fecb7246
AC
752 )
753 .file("src/main.rs", "fn main() {}")
d43ee1dd 754 .build();
88116d4d 755
80d1ba7f 756 Package::new("bar", "0.0.1").publish();
88116d4d 757
412b6339 758 cargo(&p, "build").run();
88116d4d 759
b5144c7f 760 registry_path().join("3").rm_rf();
88116d4d 761
80d1ba7f 762 Package::new("bar", "0.0.1").yanked(true).publish();
88116d4d 763
412b6339 764 cargo(&p, "build").with_stdout("").run();
88116d4d 765
412b6339 766 cargo(&p, "update")
85984a87
DW
767 .with_status(101)
768 .with_stderr_contains(
1e682848 769 "\
0117eb1f 770error: no matching package named `bar` found
8214bb95 771location searched: registry [..]
0117eb1f 772required by package `foo v0.0.1 ([..])`
1e682848 773",
fecb7246
AC
774 )
775 .run();
6950bbb0 776}
640487c9 777
0e0d9688 778#[cargo_test]
412b6339
AS
779fn yanks_in_lockfiles_are_ok_for_other_update_http() {
780 let _server = setup_http();
781 yanks_in_lockfiles_are_ok_for_other_update(cargo_http);
782}
783
784#[cargo_test]
785fn yanks_in_lockfiles_are_ok_for_other_update_git() {
786 yanks_in_lockfiles_are_ok_for_other_update(cargo_stable);
787}
788
789fn yanks_in_lockfiles_are_ok_for_other_update(cargo: fn(&Project, &str) -> Execs) {
6953ef85
E
790 let p = project()
791 .file(
792 "Cargo.toml",
793 r#"
6f8c7d5a
EH
794 [project]
795 name = "foo"
796 version = "0.0.1"
797 authors = []
6953ef85 798
6f8c7d5a
EH
799 [dependencies]
800 bar = "*"
801 baz = "*"
802 "#,
6953ef85
E
803 )
804 .file("src/main.rs", "fn main() {}")
805 .build();
806
807 Package::new("bar", "0.0.1").publish();
808 Package::new("baz", "0.0.1").publish();
809
412b6339 810 cargo(&p, "build").run();
6953ef85
E
811
812 registry_path().join("3").rm_rf();
813
814 Package::new("bar", "0.0.1").yanked(true).publish();
815 Package::new("baz", "0.0.1").publish();
816
412b6339 817 cargo(&p, "build").with_stdout("").run();
6953ef85
E
818
819 Package::new("baz", "0.0.2").publish();
820
412b6339 821 cargo(&p, "update")
6953ef85
E
822 .with_status(101)
823 .with_stderr_contains(
824 "\
825error: no matching package named `bar` found
826location searched: registry [..]
827required by package `foo v0.0.1 ([..])`
828",
829 )
830 .run();
831
412b6339 832 cargo(&p, "update -p baz")
6953ef85
E
833 .with_stderr_contains(
834 "\
835[UPDATING] `[..]` index
836[UPDATING] baz v0.0.1 -> v0.0.2
837",
838 )
839 .run();
840}
841
0e0d9688 842#[cargo_test]
412b6339
AS
843fn yanks_in_lockfiles_are_ok_with_new_dep_http() {
844 let _server = setup_http();
845 yanks_in_lockfiles_are_ok_with_new_dep(cargo_http);
846}
847
848#[cargo_test]
849fn yanks_in_lockfiles_are_ok_with_new_dep_git() {
850 yanks_in_lockfiles_are_ok_with_new_dep(cargo_stable);
851}
852
853fn yanks_in_lockfiles_are_ok_with_new_dep(cargo: fn(&Project, &str) -> Execs) {
6953ef85
E
854 let p = project()
855 .file(
856 "Cargo.toml",
857 r#"
6f8c7d5a
EH
858 [project]
859 name = "foo"
860 version = "0.0.1"
861 authors = []
6953ef85 862
6f8c7d5a
EH
863 [dependencies]
864 bar = "*"
865 "#,
6953ef85
E
866 )
867 .file("src/main.rs", "fn main() {}")
868 .build();
869
870 Package::new("bar", "0.0.1").publish();
871
412b6339 872 cargo(&p, "build").run();
6953ef85
E
873
874 registry_path().join("3").rm_rf();
875
876 Package::new("bar", "0.0.1").yanked(true).publish();
877 Package::new("baz", "0.0.1").publish();
878
4ae79d2f
EH
879 p.change_file(
880 "Cargo.toml",
881 r#"
6953ef85
E
882 [project]
883 name = "foo"
884 version = "0.0.1"
885 authors = []
886
887 [dependencies]
888 bar = "*"
889 baz = "*"
4ae79d2f
EH
890 "#,
891 );
6953ef85 892
412b6339 893 cargo(&p, "build").with_stdout("").run();
6953ef85
E
894}
895
0e0d9688 896#[cargo_test]
412b6339
AS
897fn update_with_lockfile_if_packages_missing_http() {
898 let _server = setup_http();
899 update_with_lockfile_if_packages_missing(cargo_http);
900}
901
902#[cargo_test]
903fn update_with_lockfile_if_packages_missing_git() {
904 update_with_lockfile_if_packages_missing(cargo_stable);
905}
906
907fn update_with_lockfile_if_packages_missing(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 908 let p = project()
1e682848
AC
909 .file(
910 "Cargo.toml",
911 r#"
6f8c7d5a
EH
912 [project]
913 name = "foo"
914 version = "0.0.1"
915 authors = []
640487c9 916
6f8c7d5a
EH
917 [dependencies]
918 bar = "*"
919 "#,
fecb7246
AC
920 )
921 .file("src/main.rs", "fn main() {}")
d43ee1dd 922 .build();
640487c9 923
80d1ba7f 924 Package::new("bar", "0.0.1").publish();
412b6339 925 cargo(&p, "build").run();
763ba535 926 p.root().move_into_the_past();
640487c9 927
763ba535 928 paths::home().join(".cargo/registry").rm_rf();
412b6339 929 cargo(&p, "build")
85984a87 930 .with_stderr(
1e682848 931 "\
41aa6fba 932[UPDATING] `[..]` index
e2637b65 933[DOWNLOADING] crates ...
8c75e2ff 934[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
35728137 935[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
1e682848 936",
fecb7246
AC
937 )
938 .run();
6950bbb0 939}
640487c9 940
0e0d9688 941#[cargo_test]
412b6339
AS
942fn update_lockfile_http() {
943 let _server = setup_http();
944 update_lockfile(cargo_http);
945}
946
947#[cargo_test]
948fn update_lockfile_git() {
949 update_lockfile(cargo_stable);
950}
951
952fn update_lockfile(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 953 let p = project()
1e682848
AC
954 .file(
955 "Cargo.toml",
956 r#"
6f8c7d5a
EH
957 [project]
958 name = "foo"
959 version = "0.0.1"
960 authors = []
640487c9 961
6f8c7d5a
EH
962 [dependencies]
963 bar = "*"
964 "#,
fecb7246
AC
965 )
966 .file("src/main.rs", "fn main() {}")
d43ee1dd 967 .build();
640487c9 968
70eecd3d 969 println!("0.0.1");
80d1ba7f 970 Package::new("bar", "0.0.1").publish();
412b6339 971 cargo(&p, "build").run();
640487c9 972
80d1ba7f
AC
973 Package::new("bar", "0.0.2").publish();
974 Package::new("bar", "0.0.3").publish();
763ba535 975 paths::home().join(".cargo/registry").rm_rf();
70eecd3d 976 println!("0.0.2 update");
412b6339 977 cargo(&p, "update -p bar --precise 0.0.2")
85984a87 978 .with_stderr(
1e682848 979 "\
41aa6fba 980[UPDATING] `[..]` index
8214bb95 981[UPDATING] bar v0.0.1 -> v0.0.2
1e682848 982",
fecb7246
AC
983 )
984 .run();
640487c9 985
70eecd3d 986 println!("0.0.2 build");
412b6339 987 cargo(&p, "build")
2cd9cce6 988 .with_stderr(
1e682848 989 "\
e2637b65 990[DOWNLOADING] crates ...
8c75e2ff 991[DOWNLOADED] [..] v0.0.2 (registry `dummy-registry`)
8214bb95 992[COMPILING] bar v0.0.2
89f43938 993[COMPILING] foo v0.0.1 ([CWD])
35728137 994[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 995",
fecb7246
AC
996 )
997 .run();
70eecd3d
AC
998
999 println!("0.0.3 update");
412b6339 1000 cargo(&p, "update -p bar")
85984a87 1001 .with_stderr(
1e682848 1002 "\
41aa6fba 1003[UPDATING] `[..]` index
8214bb95 1004[UPDATING] bar v0.0.2 -> v0.0.3
1e682848 1005",
fecb7246
AC
1006 )
1007 .run();
70eecd3d
AC
1008
1009 println!("0.0.3 build");
412b6339 1010 cargo(&p, "build")
2cd9cce6 1011 .with_stderr(
1e682848 1012 "\
e2637b65 1013[DOWNLOADING] crates ...
8c75e2ff 1014[DOWNLOADED] [..] v0.0.3 (registry `dummy-registry`)
8214bb95 1015[COMPILING] bar v0.0.3
89f43938 1016[COMPILING] foo v0.0.1 ([CWD])
35728137 1017[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 1018",
fecb7246
AC
1019 )
1020 .run();
1e682848
AC
1021
1022 println!("new dependencies update");
1023 Package::new("bar", "0.0.4").dep("spam", "0.2.5").publish();
1024 Package::new("spam", "0.2.5").publish();
412b6339 1025 cargo(&p, "update -p bar")
85984a87 1026 .with_stderr(
1e682848 1027 "\
41aa6fba 1028[UPDATING] `[..]` index
8214bb95
AC
1029[UPDATING] bar v0.0.3 -> v0.0.4
1030[ADDING] spam v0.2.5
1e682848 1031",
fecb7246
AC
1032 )
1033 .run();
1e682848
AC
1034
1035 println!("new dependencies update");
1036 Package::new("bar", "0.0.5").publish();
412b6339 1037 cargo(&p, "update -p bar")
85984a87 1038 .with_stderr(
1e682848 1039 "\
41aa6fba 1040[UPDATING] `[..]` index
8214bb95
AC
1041[UPDATING] bar v0.0.4 -> v0.0.5
1042[REMOVING] spam v0.2.5
1e682848 1043",
fecb7246
AC
1044 )
1045 .run();
6950bbb0 1046}
3b5994e7 1047
0e0d9688 1048#[cargo_test]
412b6339
AS
1049fn dev_dependency_not_used_http() {
1050 let _server = setup_http();
1051 dev_dependency_not_used(cargo_http);
1052}
1053
1054#[cargo_test]
1055fn dev_dependency_not_used_git() {
1056 dev_dependency_not_used(cargo_stable);
1057}
1058
1059fn dev_dependency_not_used(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1060 let p = project()
1e682848
AC
1061 .file(
1062 "Cargo.toml",
1063 r#"
6f8c7d5a
EH
1064 [project]
1065 name = "foo"
1066 version = "0.0.1"
1067 authors = []
3b5994e7 1068
6f8c7d5a
EH
1069 [dependencies]
1070 bar = "*"
1071 "#,
fecb7246
AC
1072 )
1073 .file("src/main.rs", "fn main() {}")
d43ee1dd 1074 .build();
3b5994e7 1075
80d1ba7f
AC
1076 Package::new("baz", "0.0.1").publish();
1077 Package::new("bar", "0.0.1").dev_dep("baz", "*").publish();
3b5994e7 1078
412b6339 1079 cargo(&p, "build")
2cd9cce6 1080 .with_stderr(
1e682848 1081 "\
41aa6fba 1082[UPDATING] `[..]` index
e2637b65 1083[DOWNLOADING] crates ...
8c75e2ff 1084[DOWNLOADED] [..] v0.0.1 (registry `dummy-registry`)
8214bb95 1085[COMPILING] bar v0.0.1
89f43938 1086[COMPILING] foo v0.0.1 ([CWD])
35728137 1087[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 1088",
fecb7246
AC
1089 )
1090 .run();
6950bbb0 1091}
efcdf6c9 1092
0e0d9688 1093#[cargo_test]
6950bbb0 1094fn login_with_no_cargo_dir() {
70f84bf3
EH
1095 // Create a config in the root directory because `login` requires the
1096 // index to be updated, and we don't want to hit crates.io.
1097 registry::init();
1098 fs::rename(paths::home().join(".cargo"), paths::root().join(".cargo")).unwrap();
1099 paths::home().rm_rf();
85984a87 1100 cargo_process("login foo -v").run();
70f84bf3
EH
1101 let credentials = fs::read_to_string(paths::home().join(".cargo/credentials")).unwrap();
1102 assert_eq!(credentials, "[registry]\ntoken = \"foo\"\n");
6950bbb0 1103}
5acb5f56 1104
0e0d9688 1105#[cargo_test]
da3db83d 1106fn login_with_differently_sized_token() {
70f84bf3
EH
1107 // Verify that the configuration file gets properly truncated.
1108 registry::init();
b5144c7f
EH
1109 let credentials = paths::home().join(".cargo/credentials");
1110 fs::remove_file(&credentials).unwrap();
85984a87
DW
1111 cargo_process("login lmaolmaolmao -v").run();
1112 cargo_process("login lmao -v").run();
1113 cargo_process("login lmaolmaolmao -v").run();
b5144c7f 1114 let credentials = fs::read_to_string(&credentials).unwrap();
70f84bf3 1115 assert_eq!(credentials, "[registry]\ntoken = \"lmaolmaolmao\"\n");
da3db83d
MU
1116}
1117
88f3bb9a
JF
1118#[cargo_test]
1119fn login_with_token_on_stdin() {
1120 registry::init();
1121 let credentials = paths::home().join(".cargo/credentials");
1122 fs::remove_file(&credentials).unwrap();
1123 cargo_process("login lmao -v").run();
1124 let mut cargo = cargo_process("login").build_command();
1125 cargo
1126 .stdin(Stdio::piped())
1127 .stdout(Stdio::piped())
1128 .stderr(Stdio::piped());
1129 let mut child = cargo.spawn().unwrap();
1130 let out = BufReader::new(child.stdout.as_mut().unwrap())
1131 .lines()
1132 .next()
1133 .unwrap()
1134 .unwrap();
1135 assert!(out.starts_with("please paste the API Token found on "));
1136 assert!(out.ends_with("/me below"));
1137 child
1138 .stdin
1139 .as_ref()
1140 .unwrap()
1141 .write_all(b"some token\n")
1142 .unwrap();
1143 child.wait().unwrap();
1144 let credentials = fs::read_to_string(&credentials).unwrap();
1145 assert_eq!(credentials, "[registry]\ntoken = \"some token\"\n");
1146}
1147
0e0d9688 1148#[cargo_test]
412b6339
AS
1149fn bad_license_file_http() {
1150 let _server = setup_http();
1151 bad_license_file(cargo_http);
1152}
1153
1154#[cargo_test]
1155fn bad_license_file_git() {
1156 bad_license_file(cargo_stable);
1157}
1158
1159fn bad_license_file(cargo: fn(&Project, &str) -> Execs) {
f9945926 1160 Package::new("foo", "1.0.0").publish();
f8c9928c 1161 let p = project()
1e682848
AC
1162 .file(
1163 "Cargo.toml",
1164 r#"
6f8c7d5a
EH
1165 [project]
1166 name = "foo"
1167 version = "0.0.1"
1168 authors = []
1169 license-file = "foo"
1170 description = "bar"
1171 repository = "baz"
1172 "#,
fecb7246
AC
1173 )
1174 .file("src/main.rs", "fn main() {}")
d43ee1dd 1175 .build();
412b6339 1176 cargo(&p, "publish -v --token sekrit")
85984a87
DW
1177 .with_status(101)
1178 .with_stderr_contains("[ERROR] the license file `foo` does not exist")
1179 .run();
6950bbb0 1180}
493d3108 1181
0e0d9688 1182#[cargo_test]
412b6339
AS
1183fn updating_a_dep_http() {
1184 let _server = setup_http();
1185 updating_a_dep(cargo_http);
1186}
1187
1188#[cargo_test]
1189fn updating_a_dep_git() {
1190 updating_a_dep(cargo_stable);
1191}
1192
1193fn updating_a_dep(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1194 let p = project()
1e682848
AC
1195 .file(
1196 "Cargo.toml",
1197 r#"
6f8c7d5a
EH
1198 [project]
1199 name = "foo"
1200 version = "0.0.1"
1201 authors = []
493d3108 1202
6f8c7d5a
EH
1203 [dependencies.a]
1204 path = "a"
1205 "#,
fecb7246
AC
1206 )
1207 .file("src/main.rs", "fn main() {}")
1e682848
AC
1208 .file(
1209 "a/Cargo.toml",
1210 r#"
6f8c7d5a
EH
1211 [project]
1212 name = "a"
1213 version = "0.0.1"
1214 authors = []
493d3108 1215
6f8c7d5a
EH
1216 [dependencies]
1217 bar = "*"
1218 "#,
fecb7246
AC
1219 )
1220 .file("a/src/lib.rs", "")
d43ee1dd 1221 .build();
493d3108 1222
80d1ba7f 1223 Package::new("bar", "0.0.1").publish();
493d3108 1224
412b6339 1225 cargo(&p, "build")
2cd9cce6 1226 .with_stderr(
1e682848 1227 "\
41aa6fba 1228[UPDATING] `[..]` index
e2637b65 1229[DOWNLOADING] crates ...
8c75e2ff 1230[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
8214bb95 1231[COMPILING] bar v0.0.1
89f43938
ZL
1232[COMPILING] a v0.0.1 ([CWD]/a)
1233[COMPILING] foo v0.0.1 ([CWD])
35728137 1234[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 1235",
fecb7246
AC
1236 )
1237 .run();
7e366c2e 1238 assert!(paths::home().join(".cargo/registry/CACHEDIR.TAG").is_file());
493d3108 1239
0c525bbb
MP
1240 // Now delete the CACHEDIR.TAG file: this is the situation we'll be in after
1241 // upgrading from a version of Cargo that doesn't mark this directory, to one that
1242 // does. It should be recreated.
1243 fs::remove_file(paths::home().join(".cargo/registry/CACHEDIR.TAG"))
1244 .expect("remove CACHEDIR.TAG");
1245
4ae79d2f
EH
1246 p.change_file(
1247 "a/Cargo.toml",
1248 r#"
493d3108
AC
1249 [project]
1250 name = "a"
1251 version = "0.0.1"
1252 authors = []
1253
1254 [dependencies]
1255 bar = "0.1.0"
4ae79d2f
EH
1256 "#,
1257 );
80d1ba7f 1258 Package::new("bar", "0.1.0").publish();
493d3108
AC
1259
1260 println!("second");
412b6339 1261 cargo(&p, "build")
2cd9cce6 1262 .with_stderr(
1e682848 1263 "\
41aa6fba 1264[UPDATING] `[..]` index
e2637b65 1265[DOWNLOADING] crates ...
8c75e2ff 1266[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`)
8214bb95 1267[COMPILING] bar v0.1.0
89f43938
ZL
1268[COMPILING] a v0.0.1 ([CWD]/a)
1269[COMPILING] foo v0.0.1 ([CWD])
35728137 1270[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 1271",
fecb7246
AC
1272 )
1273 .run();
0c525bbb
MP
1274
1275 assert!(
1276 paths::home().join(".cargo/registry/CACHEDIR.TAG").is_file(),
1277 "CACHEDIR.TAG recreated in existing registry"
1278 );
6950bbb0 1279}
aa97b32e 1280
0e0d9688 1281#[cargo_test]
412b6339
AS
1282fn git_and_registry_dep_http() {
1283 let _server = setup_http();
1284 git_and_registry_dep(cargo_http);
1285}
1286
1287#[cargo_test]
1288fn git_and_registry_dep_git() {
1289 git_and_registry_dep(cargo_stable);
1290}
1291
1292fn git_and_registry_dep(cargo: fn(&Project, &str) -> Execs) {
aa97b32e 1293 let b = git::repo(&paths::root().join("b"))
1e682848
AC
1294 .file(
1295 "Cargo.toml",
1296 r#"
6f8c7d5a
EH
1297 [project]
1298 name = "b"
1299 version = "0.0.1"
1300 authors = []
aa97b32e 1301
6f8c7d5a
EH
1302 [dependencies]
1303 a = "0.0.1"
1304 "#,
fecb7246
AC
1305 )
1306 .file("src/lib.rs", "")
d43ee1dd 1307 .build();
7fe2fbc8 1308 let p = project()
1e682848
AC
1309 .file(
1310 "Cargo.toml",
1311 &format!(
1312 r#"
6f8c7d5a
EH
1313 [project]
1314 name = "foo"
1315 version = "0.0.1"
1316 authors = []
aa97b32e 1317
6f8c7d5a
EH
1318 [dependencies]
1319 a = "0.0.1"
aa97b32e 1320
6f8c7d5a
EH
1321 [dependencies.b]
1322 git = '{}'
1323 "#,
1e682848
AC
1324 b.url()
1325 ),
fecb7246
AC
1326 )
1327 .file("src/main.rs", "fn main() {}")
d43ee1dd 1328 .build();
aa97b32e 1329
80d1ba7f 1330 Package::new("a", "0.0.1").publish();
aa97b32e 1331
763ba535 1332 p.root().move_into_the_past();
412b6339 1333 cargo(&p, "build")
2cd9cce6 1334 .with_stderr(
1e682848 1335 "\
29cdad4f
AK
1336[UPDATING] [..]
1337[UPDATING] [..]
e2637b65 1338[DOWNLOADING] crates ...
8c75e2ff 1339[DOWNLOADED] a v0.0.1 (registry `dummy-registry`)
8214bb95 1340[COMPILING] a v0.0.1
29cdad4f 1341[COMPILING] b v0.0.1 ([..])
89f43938 1342[COMPILING] foo v0.0.1 ([CWD])
35728137 1343[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 1344",
fecb7246
AC
1345 )
1346 .run();
763ba535 1347 p.root().move_into_the_past();
aa97b32e
AC
1348
1349 println!("second");
412b6339 1350 cargo(&p, "build").with_stdout("").run();
6950bbb0 1351}
240ed1a3 1352
0e0d9688 1353#[cargo_test]
412b6339
AS
1354fn update_publish_then_update_http() {
1355 let _server = setup_http();
1356 update_publish_then_update(cargo_http);
1357}
1358
1359#[cargo_test]
1360fn update_publish_then_update_git() {
1361 update_publish_then_update(cargo_stable);
1362}
1363
1364fn update_publish_then_update(cargo: fn(&Project, &str) -> Execs) {
5430db61
AC
1365 // First generate a Cargo.lock and a clone of the registry index at the
1366 // "head" of the current registry.
7fe2fbc8 1367 let p = project()
1e682848
AC
1368 .file(
1369 "Cargo.toml",
1370 r#"
6f8c7d5a
EH
1371 [project]
1372 name = "foo"
1373 version = "0.5.0"
1374 authors = []
240ed1a3 1375
6f8c7d5a
EH
1376 [dependencies]
1377 a = "0.1.0"
1378 "#,
fecb7246
AC
1379 )
1380 .file("src/main.rs", "fn main() {}")
d43ee1dd 1381 .build();
80d1ba7f 1382 Package::new("a", "0.1.0").publish();
412b6339 1383 cargo(&p, "build").run();
240ed1a3 1384
5430db61
AC
1385 // Next, publish a new package and back up the copy of the registry we just
1386 // created.
80d1ba7f 1387 Package::new("a", "0.1.1").publish();
5430db61
AC
1388 let registry = paths::home().join(".cargo/registry");
1389 let backup = paths::root().join("registry-backup");
c3a95990 1390 t!(fs::rename(&registry, &backup));
240ed1a3 1391
5430db61
AC
1392 // Generate a Cargo.lock with the newer version, and then move the old copy
1393 // of the registry back into place.
85984a87
DW
1394 let p2 = project()
1395 .at("foo2")
1e682848
AC
1396 .file(
1397 "Cargo.toml",
1398 r#"
6f8c7d5a
EH
1399 [project]
1400 name = "foo"
1401 version = "0.5.0"
1402 authors = []
5430db61 1403
6f8c7d5a
EH
1404 [dependencies]
1405 a = "0.1.1"
1406 "#,
fecb7246
AC
1407 )
1408 .file("src/main.rs", "fn main() {}")
d43ee1dd 1409 .build();
412b6339 1410 cargo(&p2, "build").run();
c3a95990
AC
1411 registry.rm_rf();
1412 t!(fs::rename(&backup, &registry));
1e682848
AC
1413 t!(fs::rename(
1414 p2.root().join("Cargo.lock"),
1415 p.root().join("Cargo.lock")
1416 ));
240ed1a3 1417
5430db61
AC
1418 // Finally, build the first project again (with our newer Cargo.lock) which
1419 // should force an update of the old registry, download the new crate, and
1420 // then build everything again.
412b6339 1421 cargo(&p, "build")
2cd9cce6 1422 .with_stderr(
1e682848 1423 "\
29cdad4f 1424[UPDATING] [..]
e2637b65 1425[DOWNLOADING] crates ...
8c75e2ff 1426[DOWNLOADED] a v0.1.1 (registry `dummy-registry`)
8214bb95 1427[COMPILING] a v0.1.1
89f43938 1428[COMPILING] foo v0.5.0 ([CWD])
35728137 1429[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
fee4308b 1430",
fecb7246
AC
1431 )
1432 .run();
6950bbb0 1433}
93fa4c16 1434
0e0d9688 1435#[cargo_test]
412b6339
AS
1436fn fetch_downloads_http() {
1437 let _server = setup_http();
1438 fetch_downloads(cargo_http);
1439}
1440
1441#[cargo_test]
1442fn fetch_downloads_git() {
1443 fetch_downloads(cargo_stable);
1444}
1445
1446fn fetch_downloads(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1447 let p = project()
1e682848
AC
1448 .file(
1449 "Cargo.toml",
1450 r#"
6f8c7d5a
EH
1451 [project]
1452 name = "foo"
1453 version = "0.5.0"
1454 authors = []
93fa4c16 1455
6f8c7d5a
EH
1456 [dependencies]
1457 a = "0.1.0"
1458 "#,
fecb7246
AC
1459 )
1460 .file("src/main.rs", "fn main() {}")
d43ee1dd 1461 .build();
93fa4c16 1462
80d1ba7f 1463 Package::new("a", "0.1.0").publish();
93fa4c16 1464
412b6339 1465 cargo(&p, "fetch")
85984a87 1466 .with_stderr(
1e682848 1467 "\
41aa6fba 1468[UPDATING] `[..]` index
e2637b65
AC
1469[DOWNLOADING] crates ...
1470[DOWNLOADED] a v0.1.0 (registry [..])
1e682848 1471",
fecb7246
AC
1472 )
1473 .run();
6950bbb0 1474}
242f8c42 1475
0e0d9688 1476#[cargo_test]
412b6339
AS
1477fn update_transitive_dependency_http() {
1478 let _server = setup_http();
1479 update_transitive_dependency(cargo_http);
1480}
1481
1482#[cargo_test]
1483fn update_transitive_dependency_git() {
1484 update_transitive_dependency(cargo_stable);
1485}
1486
1487fn update_transitive_dependency(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1488 let p = project()
1e682848
AC
1489 .file(
1490 "Cargo.toml",
1491 r#"
6f8c7d5a
EH
1492 [project]
1493 name = "foo"
1494 version = "0.5.0"
1495 authors = []
242f8c42 1496
6f8c7d5a
EH
1497 [dependencies]
1498 a = "0.1.0"
1499 "#,
fecb7246
AC
1500 )
1501 .file("src/main.rs", "fn main() {}")
d43ee1dd 1502 .build();
242f8c42 1503
80d1ba7f
AC
1504 Package::new("a", "0.1.0").dep("b", "*").publish();
1505 Package::new("b", "0.1.0").publish();
242f8c42 1506
412b6339 1507 cargo(&p, "fetch").run();
242f8c42 1508
80d1ba7f 1509 Package::new("b", "0.1.1").publish();
242f8c42 1510
412b6339 1511 cargo(&p, "update -pb")
85984a87 1512 .with_stderr(
1e682848 1513 "\
41aa6fba 1514[UPDATING] `[..]` index
8214bb95 1515[UPDATING] b v0.1.0 -> v0.1.1
1e682848 1516",
fecb7246
AC
1517 )
1518 .run();
242f8c42 1519
412b6339 1520 cargo(&p, "build")
85984a87 1521 .with_stderr(
1e682848 1522 "\
e2637b65 1523[DOWNLOADING] crates ...
8c75e2ff 1524[DOWNLOADED] b v0.1.1 (registry `dummy-registry`)
8214bb95
AC
1525[COMPILING] b v0.1.1
1526[COMPILING] a v0.1.0
29cdad4f 1527[COMPILING] foo v0.5.0 ([..])
35728137 1528[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
1e682848 1529",
fecb7246
AC
1530 )
1531 .run();
6950bbb0 1532}
88f5bb5a 1533
0e0d9688 1534#[cargo_test]
412b6339
AS
1535fn update_backtracking_ok_http() {
1536 let _server = setup_http();
1537 update_backtracking_ok(cargo_http);
1538}
1539
1540#[cargo_test]
1541fn update_backtracking_ok_git() {
1542 update_backtracking_ok(cargo_stable);
1543}
1544
1545fn update_backtracking_ok(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1546 let p = project()
1e682848
AC
1547 .file(
1548 "Cargo.toml",
1549 r#"
6f8c7d5a
EH
1550 [project]
1551 name = "foo"
1552 version = "0.5.0"
1553 authors = []
88f5bb5a 1554
6f8c7d5a
EH
1555 [dependencies]
1556 webdriver = "0.1"
1557 "#,
fecb7246
AC
1558 )
1559 .file("src/main.rs", "fn main() {}")
d43ee1dd 1560 .build();
88f5bb5a 1561
1e682848
AC
1562 Package::new("webdriver", "0.1.0")
1563 .dep("hyper", "0.6")
1564 .publish();
1565 Package::new("hyper", "0.6.5")
1566 .dep("openssl", "0.1")
1567 .dep("cookie", "0.1")
1568 .publish();
1569 Package::new("cookie", "0.1.0")
1570 .dep("openssl", "0.1")
1571 .publish();
80d1ba7f 1572 Package::new("openssl", "0.1.0").publish();
88f5bb5a 1573
412b6339 1574 cargo(&p, "generate-lockfile").run();
88f5bb5a 1575
80d1ba7f 1576 Package::new("openssl", "0.1.1").publish();
1e682848
AC
1577 Package::new("hyper", "0.6.6")
1578 .dep("openssl", "0.1.1")
1579 .dep("cookie", "0.1.0")
1580 .publish();
88f5bb5a 1581
412b6339 1582 cargo(&p, "update -p hyper")
85984a87 1583 .with_stderr(
51d23560 1584 "\
41aa6fba 1585[UPDATING] `[..]` index
51d23560
AC
1586[UPDATING] hyper v0.6.5 -> v0.6.6
1587[UPDATING] openssl v0.1.0 -> v0.1.1
1588",
fecb7246
AC
1589 )
1590 .run();
6950bbb0 1591}
f0647ea2 1592
0e0d9688 1593#[cargo_test]
412b6339
AS
1594fn update_multiple_packages_http() {
1595 let _server = setup_http();
1596 update_multiple_packages(cargo_http);
1597}
1598
1599#[cargo_test]
1600fn update_multiple_packages_git() {
1601 update_multiple_packages(cargo_stable);
1602}
1603
1604fn update_multiple_packages(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1605 let p = project()
1e682848
AC
1606 .file(
1607 "Cargo.toml",
1608 r#"
6f8c7d5a
EH
1609 [project]
1610 name = "foo"
1611 version = "0.5.0"
1612 authors = []
f0647ea2 1613
6f8c7d5a
EH
1614 [dependencies]
1615 a = "*"
1616 b = "*"
1617 c = "*"
1618 "#,
fecb7246
AC
1619 )
1620 .file("src/main.rs", "fn main() {}")
d43ee1dd 1621 .build();
f0647ea2 1622
80d1ba7f
AC
1623 Package::new("a", "0.1.0").publish();
1624 Package::new("b", "0.1.0").publish();
1625 Package::new("c", "0.1.0").publish();
f0647ea2 1626
412b6339 1627 cargo(&p, "fetch").run();
f0647ea2 1628
80d1ba7f
AC
1629 Package::new("a", "0.1.1").publish();
1630 Package::new("b", "0.1.1").publish();
1631 Package::new("c", "0.1.1").publish();
f0647ea2 1632
412b6339 1633 cargo(&p, "update -pa -pb")
85984a87 1634 .with_stderr(
1e682848 1635 "\
41aa6fba 1636[UPDATING] `[..]` index
8214bb95
AC
1637[UPDATING] a v0.1.0 -> v0.1.1
1638[UPDATING] b v0.1.0 -> v0.1.1
1e682848 1639",
fecb7246
AC
1640 )
1641 .run();
f0647ea2 1642
412b6339 1643 cargo(&p, "update -pb -pc")
85984a87 1644 .with_stderr(
1e682848 1645 "\
41aa6fba 1646[UPDATING] `[..]` index
8214bb95 1647[UPDATING] c v0.1.0 -> v0.1.1
1e682848 1648",
fecb7246
AC
1649 )
1650 .run();
85984a87 1651
412b6339 1652 cargo(&p, "build")
8c75e2ff
WL
1653 .with_stderr_contains("[DOWNLOADED] a v0.1.1 (registry `dummy-registry`)")
1654 .with_stderr_contains("[DOWNLOADED] b v0.1.1 (registry `dummy-registry`)")
1655 .with_stderr_contains("[DOWNLOADED] c v0.1.1 (registry `dummy-registry`)")
85984a87
DW
1656 .with_stderr_contains("[COMPILING] a v0.1.1")
1657 .with_stderr_contains("[COMPILING] b v0.1.1")
1658 .with_stderr_contains("[COMPILING] c v0.1.1")
1659 .with_stderr_contains("[COMPILING] foo v0.5.0 ([..])")
1660 .run();
6950bbb0 1661}
542355d8 1662
0e0d9688 1663#[cargo_test]
412b6339
AS
1664fn bundled_crate_in_registry_http() {
1665 let _server = setup_http();
1666 bundled_crate_in_registry(cargo_http);
1667}
1668
1669#[cargo_test]
1670fn bundled_crate_in_registry_git() {
1671 bundled_crate_in_registry(cargo_stable);
1672}
1673
1674fn bundled_crate_in_registry(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1675 let p = project()
1e682848
AC
1676 .file(
1677 "Cargo.toml",
1678 r#"
6f8c7d5a
EH
1679 [project]
1680 name = "foo"
1681 version = "0.5.0"
1682 authors = []
542355d8 1683
6f8c7d5a
EH
1684 [dependencies]
1685 bar = "0.1"
1686 baz = "0.1"
1687 "#,
fecb7246
AC
1688 )
1689 .file("src/main.rs", "fn main() {}")
d43ee1dd 1690 .build();
542355d8
AC
1691
1692 Package::new("bar", "0.1.0").publish();
1693 Package::new("baz", "0.1.0")
1694 .dep("bar", "0.1.0")
1e682848
AC
1695 .file(
1696 "Cargo.toml",
1697 r#"
6f8c7d5a
EH
1698 [package]
1699 name = "baz"
1700 version = "0.1.0"
1701 authors = []
542355d8 1702
6f8c7d5a
EH
1703 [dependencies]
1704 bar = { path = "bar", version = "0.1.0" }
1705 "#,
fecb7246
AC
1706 )
1707 .file("src/lib.rs", "")
ab19c483 1708 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
542355d8
AC
1709 .file("bar/src/lib.rs", "")
1710 .publish();
1711
412b6339
AS
1712 cargo(&p, "run").run();
1713}
1714
1715#[cargo_test]
1716fn update_same_prefix_oh_my_how_was_this_a_bug_http() {
1717 let _server = setup_http();
1718 update_same_prefix_oh_my_how_was_this_a_bug(cargo_http);
6950bbb0 1719}
f7091753 1720
0e0d9688 1721#[cargo_test]
412b6339
AS
1722fn update_same_prefix_oh_my_how_was_this_a_bug_git() {
1723 update_same_prefix_oh_my_how_was_this_a_bug(cargo_stable);
1724}
1725
1726fn update_same_prefix_oh_my_how_was_this_a_bug(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1727 let p = project()
1e682848
AC
1728 .file(
1729 "Cargo.toml",
1730 r#"
6f8c7d5a
EH
1731 [project]
1732 name = "ugh"
1733 version = "0.5.0"
1734 authors = []
f7091753 1735
6f8c7d5a
EH
1736 [dependencies]
1737 foo = "0.1"
1738 "#,
fecb7246
AC
1739 )
1740 .file("src/main.rs", "fn main() {}")
d43ee1dd 1741 .build();
f7091753
AC
1742
1743 Package::new("foobar", "0.2.0").publish();
1744 Package::new("foo", "0.1.0")
1745 .dep("foobar", "0.2.0")
1746 .publish();
1747
412b6339
AS
1748 cargo(&p, "generate-lockfile").run();
1749 cargo(&p, "update -pfoobar --precise=0.2.0").run();
1750}
1751
1752#[cargo_test]
1753fn use_semver_http() {
1754 let _server = setup_http();
1755 use_semver(cargo_http);
6950bbb0 1756}
8d5fbd17 1757
0e0d9688 1758#[cargo_test]
412b6339
AS
1759fn use_semver_git() {
1760 use_semver(cargo_stable);
1761}
1762
1763fn use_semver(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1764 let p = project()
1e682848
AC
1765 .file(
1766 "Cargo.toml",
1767 r#"
6f8c7d5a
EH
1768 [project]
1769 name = "bar"
1770 version = "0.5.0"
1771 authors = []
8d5fbd17 1772
6f8c7d5a
EH
1773 [dependencies]
1774 foo = "1.2.3-alpha.0"
1775 "#,
fecb7246
AC
1776 )
1777 .file("src/main.rs", "fn main() {}")
d43ee1dd 1778 .build();
8d5fbd17 1779
f9945926 1780 Package::new("foo", "1.2.3-alpha.0").publish();
8d5fbd17 1781
412b6339 1782 cargo(&p, "build").run();
6950bbb0 1783}
f9945926 1784
1e9bd724 1785#[cargo_test]
412b6339
AS
1786fn use_semver_package_incorrectly_http() {
1787 let _server = setup_http();
1788 use_semver_package_incorrectly(cargo_http);
1789}
1790
1791#[cargo_test]
1792fn use_semver_package_incorrectly_git() {
1793 use_semver_package_incorrectly(cargo_stable);
1794}
1795
1796fn use_semver_package_incorrectly(cargo: fn(&Project, &str) -> Execs) {
1e9bd724 1797 let p = project()
1798 .file(
1799 "Cargo.toml",
1800 r#"
1801 [workspace]
1802 members = ["a", "b"]
1803 "#,
1804 )
1805 .file(
1806 "a/Cargo.toml",
1807 r#"
1808 [project]
1809 name = "a"
1810 version = "0.1.1-alpha.0"
1811 authors = []
1812 "#,
1813 )
1814 .file(
1815 "b/Cargo.toml",
1816 r#"
1817 [project]
1818 name = "b"
1819 version = "0.1.0"
1820 authors = []
1821
1822 [dependencies]
1823 a = { version = "^0.1", path = "../a" }
1824 "#,
1825 )
1826 .file("a/src/main.rs", "fn main() {}")
1827 .file("b/src/main.rs", "fn main() {}")
1828 .build();
1829
412b6339 1830 cargo(&p, "build")
1e9bd724 1831 .with_status(101)
1832 .with_stderr(
1833 "\
e94199cb 1834error: no matching package found
1835searched package name: `a`
1e9bd724 1836prerelease package needs to be specified explicitly
1837a = { version = \"0.1.1-alpha.0\" }
dc0e53b7 1838location searched: [..]
1e9bd724 1839required by package `b v0.1.0 ([..])`
1840",
1841 )
1842 .run();
1843}
1844
0e0d9688 1845#[cargo_test]
412b6339
AS
1846fn only_download_relevant_http() {
1847 let _server = setup_http();
1848 only_download_relevant(cargo_http);
1849}
1850
1851#[cargo_test]
1852fn only_download_relevant_git() {
1853 only_download_relevant(cargo_stable);
1854}
1855
1856fn only_download_relevant(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1857 let p = project()
1e682848
AC
1858 .file(
1859 "Cargo.toml",
1860 r#"
6f8c7d5a
EH
1861 [project]
1862 name = "bar"
1863 version = "0.5.0"
1864 authors = []
f9945926 1865
6f8c7d5a
EH
1866 [target.foo.dependencies]
1867 foo = "*"
1868 [dev-dependencies]
1869 bar = "*"
1870 [dependencies]
1871 baz = "*"
1872 "#,
fecb7246
AC
1873 )
1874 .file("src/main.rs", "fn main() {}")
d43ee1dd 1875 .build();
f9945926
AC
1876
1877 Package::new("foo", "0.1.0").publish();
1878 Package::new("bar", "0.1.0").publish();
1879 Package::new("baz", "0.1.0").publish();
1880
412b6339 1881 cargo(&p, "build")
85984a87 1882 .with_stderr(
1e682848 1883 "\
41aa6fba 1884[UPDATING] `[..]` index
e2637b65
AC
1885[DOWNLOADING] crates ...
1886[DOWNLOADED] baz v0.1.0 ([..])
8214bb95 1887[COMPILING] baz v0.1.0
29cdad4f 1888[COMPILING] bar v0.5.0 ([..])
35728137 1889[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
1e682848 1890",
fecb7246
AC
1891 )
1892 .run();
6950bbb0 1893}
e3b7f2f5 1894
0e0d9688 1895#[cargo_test]
412b6339
AS
1896fn resolve_and_backtracking_http() {
1897 let _server = setup_http();
1898 resolve_and_backtracking(cargo_http);
1899}
1900
1901#[cargo_test]
1902fn resolve_and_backtracking_git() {
1903 resolve_and_backtracking(cargo_stable);
1904}
1905
1906fn resolve_and_backtracking(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1907 let p = project()
1e682848
AC
1908 .file(
1909 "Cargo.toml",
1910 r#"
6f8c7d5a
EH
1911 [project]
1912 name = "bar"
1913 version = "0.5.0"
1914 authors = []
e3b7f2f5 1915
6f8c7d5a
EH
1916 [dependencies]
1917 foo = "*"
1918 "#,
fecb7246
AC
1919 )
1920 .file("src/main.rs", "fn main() {}")
d43ee1dd 1921 .build();
e3b7f2f5
AC
1922
1923 Package::new("foo", "0.1.1")
1e682848
AC
1924 .feature_dep("bar", "0.1", &["a", "b"])
1925 .publish();
e3b7f2f5
AC
1926 Package::new("foo", "0.1.0").publish();
1927
412b6339
AS
1928 cargo(&p, "build").run();
1929}
1930
1931#[cargo_test]
1932fn upstream_warnings_on_extra_verbose_http() {
1933 let _server = setup_http();
1934 upstream_warnings_on_extra_verbose(cargo_http);
6950bbb0 1935}
805dfe4e 1936
0e0d9688 1937#[cargo_test]
412b6339
AS
1938fn upstream_warnings_on_extra_verbose_git() {
1939 upstream_warnings_on_extra_verbose(cargo_stable);
1940}
1941
1942fn upstream_warnings_on_extra_verbose(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 1943 let p = project()
1e682848
AC
1944 .file(
1945 "Cargo.toml",
1946 r#"
6f8c7d5a
EH
1947 [project]
1948 name = "bar"
1949 version = "0.5.0"
1950 authors = []
805dfe4e 1951
6f8c7d5a
EH
1952 [dependencies]
1953 foo = "*"
1954 "#,
fecb7246
AC
1955 )
1956 .file("src/main.rs", "fn main() {}")
d43ee1dd 1957 .build();
805dfe4e
AC
1958
1959 Package::new("foo", "0.1.0")
1e682848
AC
1960 .file("src/lib.rs", "fn unused() {}")
1961 .publish();
805dfe4e 1962
412b6339 1963 cargo(&p, "build -vv")
85984a87
DW
1964 .with_stderr_contains("[..]warning: function is never used[..]")
1965 .run();
805dfe4e 1966}
a504f480 1967
0e0d9688 1968#[cargo_test]
412b6339
AS
1969fn disallow_network_http() {
1970 let _server = setup_http();
1971 let p = project()
1972 .file(
1973 "Cargo.toml",
1974 r#"
1975 [project]
1976 name = "bar"
1977 version = "0.5.0"
1978 authors = []
1979
1980 [dependencies]
1981 foo = "*"
1982 "#,
1983 )
1984 .file("src/main.rs", "fn main() {}")
1985 .build();
1986
1987 cargo_http(&p, "build --frozen")
1988 .with_status(101)
1989 .with_stderr(
1990 "\
1991[UPDATING] [..]
1992[ERROR] failed to get `foo` as a dependency of package `bar v0.5.0 ([..])`
1993
1994Caused by:
1995 failed to query replaced source registry `crates-io`
1996
1997Caused by:
1998 attempting to make an HTTP request, but --frozen was specified
1999",
2000 )
2001 .run();
2002}
2003
2004#[cargo_test]
2005fn disallow_network_git() {
7fe2fbc8 2006 let p = project()
1e682848
AC
2007 .file(
2008 "Cargo.toml",
2009 r#"
6f8c7d5a
EH
2010 [project]
2011 name = "bar"
2012 version = "0.5.0"
2013 authors = []
a504f480 2014
6f8c7d5a
EH
2015 [dependencies]
2016 foo = "*"
2017 "#,
fecb7246
AC
2018 )
2019 .file("src/main.rs", "fn main() {}")
d43ee1dd 2020 .build();
a504f480 2021
412b6339 2022 cargo_stable(&p, "build --frozen")
85984a87
DW
2023 .with_status(101)
2024 .with_stderr(
1e682848 2025 "\
1eca786d 2026[ERROR] failed to get `foo` as a dependency of package `bar v0.5.0 [..]`
a07fec1b
EH
2027
2028Caused by:
2029 failed to load source for dependency `foo`
a504f480
AC
2030
2031Caused by:
2032 Unable to update registry [..]
2033
2034Caused by:
c3a95990 2035 attempting to make an HTTP request, but --frozen was specified
1e682848 2036",
fecb7246
AC
2037 )
2038 .run();
a504f480 2039}
c0306a8a 2040
0e0d9688 2041#[cargo_test]
412b6339
AS
2042fn add_dep_dont_update_registry_http() {
2043 let _server = setup_http();
2044 add_dep_dont_update_registry(cargo_http);
2045}
2046
2047#[cargo_test]
2048fn add_dep_dont_update_registry_git() {
2049 add_dep_dont_update_registry(cargo_stable);
2050}
2051
2052fn add_dep_dont_update_registry(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 2053 let p = project()
1e682848
AC
2054 .file(
2055 "Cargo.toml",
2056 r#"
6f8c7d5a
EH
2057 [project]
2058 name = "bar"
2059 version = "0.5.0"
2060 authors = []
c0306a8a 2061
6f8c7d5a
EH
2062 [dependencies]
2063 baz = { path = "baz" }
2064 "#,
fecb7246
AC
2065 )
2066 .file("src/main.rs", "fn main() {}")
1e682848
AC
2067 .file(
2068 "baz/Cargo.toml",
2069 r#"
6f8c7d5a
EH
2070 [project]
2071 name = "baz"
2072 version = "0.5.0"
2073 authors = []
c0306a8a 2074
6f8c7d5a
EH
2075 [dependencies]
2076 remote = "0.3"
2077 "#,
fecb7246
AC
2078 )
2079 .file("baz/src/lib.rs", "")
d43ee1dd 2080 .build();
c0306a8a
AC
2081
2082 Package::new("remote", "0.3.4").publish();
2083
412b6339 2084 cargo(&p, "build").run();
c0306a8a 2085
4ae79d2f
EH
2086 p.change_file(
2087 "Cargo.toml",
2088 r#"
c0306a8a
AC
2089 [project]
2090 name = "bar"
2091 version = "0.5.0"
2092 authors = []
2093
2094 [dependencies]
2095 baz = { path = "baz" }
2096 remote = "0.3"
4ae79d2f
EH
2097 "#,
2098 );
c0306a8a 2099
412b6339 2100 cargo(&p, "build")
85984a87 2101 .with_stderr(
1e682848 2102 "\
c0306a8a
AC
2103[COMPILING] bar v0.5.0 ([..])
2104[FINISHED] [..]
1e682848 2105",
fecb7246
AC
2106 )
2107 .run();
c0306a8a
AC
2108}
2109
0e0d9688 2110#[cargo_test]
412b6339
AS
2111fn bump_version_dont_update_registry_http() {
2112 let _server = setup_http();
2113 bump_version_dont_update_registry(cargo_http);
2114}
2115
2116#[cargo_test]
2117fn bump_version_dont_update_registry_git() {
2118 bump_version_dont_update_registry(cargo_stable);
2119}
2120
2121fn bump_version_dont_update_registry(cargo: fn(&Project, &str) -> Execs) {
7fe2fbc8 2122 let p = project()
1e682848
AC
2123 .file(
2124 "Cargo.toml",
2125 r#"
6f8c7d5a
EH
2126 [project]
2127 name = "bar"
2128 version = "0.5.0"
2129 authors = []
c0306a8a 2130
6f8c7d5a
EH
2131 [dependencies]
2132 baz = { path = "baz" }
2133 "#,
fecb7246
AC
2134 )
2135 .file("src/main.rs", "fn main() {}")
1e682848
AC
2136 .file(
2137 "baz/Cargo.toml",
2138 r#"
6f8c7d5a
EH
2139 [project]
2140 name = "baz"
2141 version = "0.5.0"
2142 authors = []
c0306a8a 2143
6f8c7d5a
EH
2144 [dependencies]
2145 remote = "0.3"
2146 "#,
fecb7246
AC
2147 )
2148 .file("baz/src/lib.rs", "")
d43ee1dd 2149 .build();
c0306a8a
AC
2150
2151 Package::new("remote", "0.3.4").publish();
2152
412b6339 2153 cargo(&p, "build").run();
c0306a8a 2154
4ae79d2f
EH
2155 p.change_file(
2156 "Cargo.toml",
2157 r#"
c0306a8a
AC
2158 [project]
2159 name = "bar"
2160 version = "0.6.0"
2161 authors = []
2162
2163 [dependencies]
2164 baz = { path = "baz" }
4ae79d2f
EH
2165 "#,
2166 );
c0306a8a 2167
412b6339 2168 cargo(&p, "build")
85984a87 2169 .with_stderr(
1e682848 2170 "\
c0306a8a
AC
2171[COMPILING] bar v0.6.0 ([..])
2172[FINISHED] [..]
1e682848 2173",
fecb7246
AC
2174 )
2175 .run();
c0306a8a 2176}
f40f8c66 2177
0e0d9688 2178#[cargo_test]
412b6339
AS
2179fn toml_lies_but_index_is_truth_http() {
2180 let _server = setup_http();
2181 toml_lies_but_index_is_truth(cargo_http);
2182}
2183
2184#[cargo_test]
2185fn toml_lies_but_index_is_truth_git() {
2186 toml_lies_but_index_is_truth(cargo_stable);
2187}
2188
2189fn toml_lies_but_index_is_truth(cargo: fn(&Project, &str) -> Execs) {
c8a5dcd2
AC
2190 Package::new("foo", "0.2.0").publish();
2191 Package::new("bar", "0.3.0")
1e682848
AC
2192 .dep("foo", "0.2.0")
2193 .file(
2194 "Cargo.toml",
2195 r#"
a5a298f1 2196 [project]
c8a5dcd2
AC
2197 name = "bar"
2198 version = "0.3.0"
2199 authors = []
2200
2201 [dependencies]
2202 foo = "0.1.0"
1e682848 2203 "#,
fecb7246
AC
2204 )
2205 .file("src/lib.rs", "extern crate foo;")
1e682848 2206 .publish();
c8a5dcd2 2207
7fe2fbc8 2208 let p = project()
1e682848
AC
2209 .file(
2210 "Cargo.toml",
2211 r#"
6f8c7d5a
EH
2212 [project]
2213 name = "bar"
2214 version = "0.5.0"
2215 authors = []
c8a5dcd2 2216
6f8c7d5a
EH
2217 [dependencies]
2218 bar = "0.3"
2219 "#,
fecb7246
AC
2220 )
2221 .file("src/main.rs", "fn main() {}")
d43ee1dd 2222 .build();
c8a5dcd2 2223
412b6339
AS
2224 cargo(&p, "build -v").run();
2225}
2226
2227#[cargo_test]
2228fn vv_prints_warnings_http() {
2229 let _server = setup_http();
2230 vv_prints_warnings(cargo_http);
c8a5dcd2 2231}
684790f8 2232
0e0d9688 2233#[cargo_test]
412b6339
AS
2234fn vv_prints_warnings_git() {
2235 vv_prints_warnings(cargo_stable);
2236}
2237
2238fn vv_prints_warnings(cargo: fn(&Project, &str) -> Execs) {
684790f8 2239 Package::new("foo", "0.2.0")
85984a87
DW
2240 .file(
2241 "src/lib.rs",
2242 "#![deny(warnings)] fn foo() {} // unused function",
fecb7246
AC
2243 )
2244 .publish();
684790f8 2245
7fe2fbc8 2246 let p = project()
1e682848
AC
2247 .file(
2248 "Cargo.toml",
2249 r#"
6f8c7d5a
EH
2250 [project]
2251 name = "fo"
2252 version = "0.5.0"
2253 authors = []
684790f8 2254
6f8c7d5a
EH
2255 [dependencies]
2256 foo = "0.2"
2257 "#,
fecb7246
AC
2258 )
2259 .file("src/main.rs", "fn main() {}")
d43ee1dd 2260 .build();
684790f8 2261
412b6339
AS
2262 cargo(&p, "build -vv").run();
2263}
2264
2265#[cargo_test]
2266fn bad_and_or_malicious_packages_rejected_http() {
2267 let _server = setup_http();
2268 bad_and_or_malicious_packages_rejected(cargo_http);
684790f8 2269}
0b9e3822 2270
0e0d9688 2271#[cargo_test]
412b6339
AS
2272fn bad_and_or_malicious_packages_rejected_git() {
2273 bad_and_or_malicious_packages_rejected(cargo_stable);
2274}
2275
2276fn bad_and_or_malicious_packages_rejected(cargo: fn(&Project, &str) -> Execs) {
0b9e3822 2277 Package::new("foo", "0.2.0")
1e682848
AC
2278 .extra_file("foo-0.1.0/src/lib.rs", "")
2279 .publish();
0b9e3822 2280
7fe2fbc8 2281 let p = project()
1e682848
AC
2282 .file(
2283 "Cargo.toml",
2284 r#"
6f8c7d5a
EH
2285 [project]
2286 name = "fo"
2287 version = "0.5.0"
2288 authors = []
0b9e3822 2289
6f8c7d5a
EH
2290 [dependencies]
2291 foo = "0.2"
2292 "#,
fecb7246
AC
2293 )
2294 .file("src/main.rs", "fn main() {}")
d43ee1dd 2295 .build();
0b9e3822 2296
412b6339 2297 cargo(&p, "build -vv")
85984a87
DW
2298 .with_status(101)
2299 .with_stderr(
1e682848 2300 "\
0b9e3822 2301[UPDATING] [..]
e2637b65
AC
2302[DOWNLOADING] crates ...
2303[DOWNLOADED] [..]
c94804bd 2304error: failed to download [..]
0b9e3822
AC
2305
2306Caused by:
2307 failed to unpack [..]
2308
2309Caused by:
2310 [..] contains a file at \"foo-0.1.0/src/lib.rs\" which isn't under \"foo-0.2.0\"
1e682848 2311",
fecb7246
AC
2312 )
2313 .run();
0b9e3822 2314}
1868998b 2315
0e0d9688 2316#[cargo_test]
412b6339
AS
2317fn git_init_templatedir_missing_http() {
2318 let _server = setup_http();
2319 git_init_templatedir_missing(cargo_http);
2320}
2321
2322#[cargo_test]
2323fn git_init_templatedir_missing_git() {
2324 git_init_templatedir_missing(cargo_stable);
2325}
2326
2327fn git_init_templatedir_missing(cargo: fn(&Project, &str) -> Execs) {
1868998b
AC
2328 Package::new("foo", "0.2.0").dep("bar", "*").publish();
2329 Package::new("bar", "0.2.0").publish();
2330
7fe2fbc8 2331 let p = project()
1868998b
AC
2332 .file(
2333 "Cargo.toml",
2334 r#"
2335 [project]
2336 name = "fo"
2337 version = "0.5.0"
2338 authors = []
2339
2340 [dependencies]
2341 foo = "0.2"
2342 "#,
fecb7246
AC
2343 )
2344 .file("src/main.rs", "fn main() {}")
1868998b
AC
2345 .build();
2346
412b6339 2347 cargo(&p, "build").run();
1868998b
AC
2348
2349 remove_dir_all(paths::home().join(".cargo/registry")).unwrap();
4ae79d2f
EH
2350 fs::write(
2351 paths::home().join(".gitconfig"),
2352 r#"
1868998b
AC
2353 [init]
2354 templatedir = nowhere
85984a87 2355 "#,
4ae79d2f
EH
2356 )
2357 .unwrap();
85984a87 2358
412b6339
AS
2359 cargo(&p, "build").run();
2360 cargo(&p, "build").run();
1868998b 2361}
e82443df 2362
0e0d9688 2363#[cargo_test]
412b6339
AS
2364fn rename_deps_and_features_http() {
2365 let _server = setup_http();
2366 rename_deps_and_features(cargo_http);
2367}
2368
2369#[cargo_test]
2370fn rename_deps_and_features_git() {
2371 rename_deps_and_features(cargo_stable);
2372}
2373
2374fn rename_deps_and_features(cargo: fn(&Project, &str) -> Execs) {
e82443df
AC
2375 Package::new("foo", "0.1.0")
2376 .file("src/lib.rs", "pub fn f1() {}")
2377 .publish();
2378 Package::new("foo", "0.2.0")
2379 .file("src/lib.rs", "pub fn f2() {}")
2380 .publish();
2381 Package::new("bar", "0.2.0")
fecb7246
AC
2382 .add_dep(
2383 Dependency::new("foo01", "0.1.0")
2384 .package("foo")
2385 .optional(true),
2386 )
e82443df
AC
2387 .add_dep(Dependency::new("foo02", "0.2.0").package("foo"))
2388 .feature("another", &["foo01"])
2389 .file(
2390 "src/lib.rs",
2391 r#"
2392 extern crate foo02;
2393 #[cfg(feature = "foo01")]
2394 extern crate foo01;
2395
2396 pub fn foo() {
2397 foo02::f2();
2398 #[cfg(feature = "foo01")]
2399 foo01::f1();
2400 }
2401 "#,
2402 )
2403 .publish();
2404
2405 let p = project()
2406 .file(
2407 "Cargo.toml",
2408 r#"
2409 [project]
2410 name = "a"
2411 version = "0.5.0"
2412 authors = []
2413
2414 [dependencies]
2415 bar = "0.2"
2416 "#,
fecb7246
AC
2417 )
2418 .file(
e82443df
AC
2419 "src/main.rs",
2420 "
2421 extern crate bar;
2422 fn main() { bar::foo(); }
2423 ",
2424 )
2425 .build();
2426
412b6339
AS
2427 cargo(&p, "build").run();
2428 cargo(&p, "build --features bar/foo01").run();
2429 cargo(&p, "build --features bar/another").run();
2430}
2431
2432#[cargo_test]
2433fn ignore_invalid_json_lines_http() {
2434 let _server = setup_http();
2435 ignore_invalid_json_lines(cargo_http);
e82443df 2436}
23ee2046 2437
0e0d9688 2438#[cargo_test]
412b6339
AS
2439fn ignore_invalid_json_lines_git() {
2440 ignore_invalid_json_lines(cargo_stable);
2441}
2442
2443fn ignore_invalid_json_lines(cargo: fn(&Project, &str) -> Execs) {
23ee2046 2444 Package::new("foo", "0.1.0").publish();
b48ae60e 2445 Package::new("foo", "0.1.1").invalid_json(true).publish();
23ee2046
AC
2446 Package::new("foo", "0.2.0").publish();
2447
2448 let p = project()
2449 .file(
2450 "Cargo.toml",
2451 r#"
2452 [project]
2453 name = "a"
2454 version = "0.5.0"
2455 authors = []
2456
2457 [dependencies]
2458 foo = '0.1.0'
2459 foo02 = { version = '0.2.0', package = 'foo' }
2460 "#,
2461 )
2462 .file("src/lib.rs", "")
2463 .build();
2464
412b6339
AS
2465 cargo(&p, "build").run();
2466}
2467
2468#[cargo_test]
2469fn readonly_registry_still_works_http() {
2470 let _server = setup_http();
2471 readonly_registry_still_works(cargo_http);
23ee2046 2472}
5d9383ed 2473
0e0d9688 2474#[cargo_test]
412b6339
AS
2475fn readonly_registry_still_works_git() {
2476 readonly_registry_still_works(cargo_stable);
2477}
2478
2479fn readonly_registry_still_works(cargo: fn(&Project, &str) -> Execs) {
5d9383ed
AC
2480 Package::new("foo", "0.1.0").publish();
2481
2482 let p = project()
2483 .file(
2484 "Cargo.toml",
2485 r#"
2486 [project]
2487 name = "a"
2488 version = "0.5.0"
2489 authors = []
2490
2491 [dependencies]
2492 foo = '0.1.0'
2493 "#,
2494 )
2495 .file("src/lib.rs", "")
2496 .build();
2497
412b6339
AS
2498 cargo(&p, "generate-lockfile").run();
2499 cargo(&p, "fetch --locked").run();
235fcbec 2500 chmod_readonly(&paths::home(), true);
412b6339 2501 cargo(&p, "build").run();
235fcbec
MK
2502 // make sure we un-readonly the files afterwards so "cargo clean" can remove them (#6934)
2503 chmod_readonly(&paths::home(), false);
5d9383ed 2504
235fcbec 2505 fn chmod_readonly(path: &Path, readonly: bool) {
5d9383ed
AC
2506 for entry in t!(path.read_dir()) {
2507 let entry = t!(entry);
2508 let path = entry.path();
2509 if t!(entry.file_type()).is_dir() {
235fcbec 2510 chmod_readonly(&path, readonly);
5d9383ed 2511 } else {
235fcbec 2512 set_readonly(&path, readonly);
5d9383ed
AC
2513 }
2514 }
235fcbec 2515 set_readonly(path, readonly);
5d9383ed
AC
2516 }
2517
235fcbec 2518 fn set_readonly(path: &Path, readonly: bool) {
5d9383ed 2519 let mut perms = t!(path.metadata()).permissions();
235fcbec 2520 perms.set_readonly(readonly);
5d9383ed
AC
2521 t!(fs::set_permissions(path, perms));
2522 }
2523}
9d00f9f0
EH
2524
2525#[cargo_test]
412b6339
AS
2526fn registry_index_rejected_http() {
2527 let _server = setup_http();
2528 registry_index_rejected(cargo_http);
2529}
2530
2531#[cargo_test]
2532fn registry_index_rejected_git() {
2533 registry_index_rejected(cargo_stable);
2534}
2535
2536fn registry_index_rejected(cargo: fn(&Project, &str) -> Execs) {
9d00f9f0
EH
2537 Package::new("dep", "0.1.0").publish();
2538
2539 let p = project()
2540 .file(
2541 ".cargo/config",
2542 r#"
2543 [registry]
2544 index = "https://example.com/"
2545 "#,
2546 )
2547 .file(
2548 "Cargo.toml",
2549 r#"
2550 [package]
2551 name = "foo"
2552 version = "0.1.0"
2553
2554 [dependencies]
2555 dep = "0.1"
2556 "#,
2557 )
2558 .file("src/lib.rs", "")
2559 .build();
2560
412b6339 2561 cargo(&p, "check")
9d00f9f0
EH
2562 .with_status(101)
2563 .with_stderr(
2564 "\
2565[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
2566
2567Caused by:
2568 the `registry.index` config value is no longer supported
6514c289 2569 Use `[source]` replacement to alter the default index for crates.io.
9d00f9f0
EH
2570",
2571 )
2572 .run();
2573
412b6339 2574 cargo(&p, "login")
9d00f9f0
EH
2575 .with_status(101)
2576 .with_stderr(
2577 "\
2578[ERROR] the `registry.index` config value is no longer supported
2579Use `[source]` replacement to alter the default index for crates.io.
2580",
2581 )
2582 .run();
2583}
05a8127c
SJ
2584
2585#[cargo_test]
2586fn package_lock_inside_package_is_overwritten() {
2587 let p = project()
2588 .file(
2589 "Cargo.toml",
2590 r#"
2591 [project]
2592 name = "foo"
2593 version = "0.0.1"
2594 authors = []
2595
2596 [dependencies]
2597 bar = ">= 0.0.0"
2598 "#,
2599 )
2600 .file("src/main.rs", "fn main() {}")
2601 .build();
2602
2603 Package::new("bar", "0.0.1")
2604 .file("src/lib.rs", "")
2605 .file(".cargo-ok", "")
2606 .publish();
2607
2608 p.cargo("build").run();
2609
2610 let id = SourceId::for_registry(&registry_url()).unwrap();
2611 let hash = cargo::util::hex::short_hash(&id);
2612 let ok = cargo_home()
2613 .join("registry")
2614 .join("src")
2615 .join(format!("-{}", hash))
2616 .join("bar-0.0.1")
2617 .join(".cargo-ok");
2618
2619 assert_eq!(ok.metadata().unwrap().len(), 2);
2620}
196673bb
EH
2621
2622#[cargo_test]
412b6339
AS
2623fn ignores_unknown_index_version_http() {
2624 let _server = setup_http();
2625 ignores_unknown_index_version(cargo_http);
2626}
2627
2628#[cargo_test]
2629fn ignores_unknown_index_version_git() {
2630 ignores_unknown_index_version(cargo_stable);
2631}
2632
2633fn ignores_unknown_index_version(cargo: fn(&Project, &str) -> Execs) {
196673bb
EH
2634 // If the version field is not understood, it is ignored.
2635 Package::new("bar", "1.0.0").publish();
2636 Package::new("bar", "1.0.1").schema_version(9999).publish();
2637
2638 let p = project()
2639 .file(
2640 "Cargo.toml",
2641 r#"
2642 [package]
2643 name = "foo"
2644 version = "0.1.0"
2645
2646 [dependencies]
2647 bar = "1.0"
2648 "#,
2649 )
2650 .file("src/lib.rs", "")
2651 .build();
2652
412b6339 2653 cargo(&p, "tree")
196673bb
EH
2654 .with_stdout(
2655 "foo v0.1.0 [..]\n\
2656 └── bar v1.0.0\n\
2657 ",
2658 )
2659 .run();
2660}
412b6339
AS
2661
2662#[cargo_test]
2663fn http_requires_z_flag() {
2664 let _server = setup_http();
2665 let p = project()
2666 .file(
2667 "Cargo.toml",
2668 r#"
2669 [project]
2670 name = "foo"
2671 version = "0.0.1"
2672 authors = []
2673
2674 [dependencies]
2675 bar = ">= 0.0.0"
2676 "#,
2677 )
2678 .file("src/main.rs", "fn main() {}")
2679 .build();
2680
2681 p.cargo("build")
2682 .with_status(101)
2622074d 2683 .with_stderr_contains(" usage of HTTP-based registries requires `-Z http-registry`")
412b6339
AS
2684 .run();
2685}
2622074d
AS
2686
2687#[cargo_test]
2688fn http_requires_trailing_slash() {
2689 cargo_process("-Z http-registry install bar --index sparse+https://index.crates.io")
2690 .masquerade_as_nightly_cargo()
2691 .with_status(101)
2692 .with_stderr("[ERROR] registry url must end in a slash `/`: sparse+https://index.crates.io")
2693 .run()
2694}