]> git.proxmox.com Git - cargo.git/blame - tests/testsuite/metadata.rs
Document lib before bin.
[cargo.git] / tests / testsuite / metadata.rs
CommitLineData
83571aee
EH
1//! Tests for the `cargo metadata` command.
2
ee286bce
JG
3use cargo_test_support::install::cargo_home;
4use cargo_test_support::paths::CargoPathExt;
9115b2c3 5use cargo_test_support::registry::Package;
5b521f65 6use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, main_file, project, rustc_host};
2492bf53 7use serde_json::json;
fec3ce92 8
0e0d9688 9#[cargo_test]
6950bbb0 10fn cargo_metadata_simple() {
7fe2fbc8 11 let p = project()
d43ee1dd
NK
12 .file("src/foo.rs", "")
13 .file("Cargo.toml", &basic_bin_manifest("foo"))
14 .build();
fec3ce92 15
85984a87
DW
16 p.cargo("metadata")
17 .with_json(
1e682848 18 r#"
b24bf7e6
AK
19 {
20 "packages": [
21 {
d1cacfed
YS
22 "authors": [
23 "wycats@example.com"
24 ],
25 "categories": [],
f9a56257 26 "default_run": null,
b24bf7e6
AK
27 "name": "foo",
28 "version": "0.5.0",
29 "id": "foo[..]",
d1cacfed 30 "keywords": [],
b24bf7e6
AK
31 "source": null,
32 "dependencies": [],
62cd0dbe 33 "edition": "2015",
85d09d08
JF
34 "license": null,
35 "license_file": null,
53de08a5 36 "links": null,
ab493a17 37 "description": null,
d1cacfed
YS
38 "readme": null,
39 "repository": null,
390af271 40 "rust_version": null,
72694e80 41 "homepage": null,
42 "documentation": null,
43 "homepage": null,
44 "documentation": null,
b24bf7e6
AK
45 "targets": [
46 {
47 "kind": [
48 "bin"
49 ],
2268d57b
KA
50 "crate_types": [
51 "bin"
52 ],
e831dd12 53 "doc": true,
e1d433d3 54 "doctest": false,
95b22d28 55 "test": true,
5dcc4f17 56 "edition": "2015",
b24bf7e6 57 "name": "foo",
05400b80 58 "src_path": "[..]/foo/src/foo.rs"
b24bf7e6
AK
59 }
60 ],
61 "features": {},
2efeeda1 62 "manifest_path": "[..]Cargo.toml",
7d41d454
SF
63 "metadata": null,
64 "publish": null
b24bf7e6
AK
65 }
66 ],
578c1a11 67 "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
b24bf7e6 68 "resolve": {
8456d2ae
AK
69 "nodes": [
70 {
71 "dependencies": [],
39b1f752 72 "deps": [],
6a2b6468 73 "features": [],
8456d2ae
AK
74 "id": "foo 0.5.0 (path+file:[..]foo)"
75 }
76 ],
77 "root": "foo 0.5.0 (path+file:[..]foo)"
b24bf7e6 78 },
05400b80 79 "target_directory": "[..]foo/target",
fef215d3 80 "version": 1,
866d4316
BC
81 "workspace_root": "[..]/foo",
82 "metadata": null
1e682848 83 }"#,
fecb7246
AC
84 )
85 .run();
6950bbb0 86}
fec3ce92 87
0e0d9688 88#[cargo_test]
624493c7 89fn cargo_metadata_warns_on_implicit_version() {
7fe2fbc8 90 let p = project()
624493c7 91 .file("src/foo.rs", "")
d43ee1dd
NK
92 .file("Cargo.toml", &basic_bin_manifest("foo"))
93 .build();
624493c7 94
85984a87 95 p.cargo("metadata").with_stderr("[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems").run();
624493c7 96
85984a87 97 p.cargo("metadata --format-version 1").with_stderr("").run();
624493c7
AK
98}
99
0e0d9688 100#[cargo_test]
2c1274f6 101fn library_with_several_crate_types() {
7fe2fbc8 102 let p = project()
d43ee1dd 103 .file("src/lib.rs", "")
1e682848
AC
104 .file(
105 "Cargo.toml",
106 r#"
2c1274f6
KA
107[package]
108name = "foo"
109version = "0.5.0"
110
111[lib]
112crate-type = ["lib", "staticlib"]
1e682848 113 "#,
fecb7246
AC
114 )
115 .build();
2c1274f6 116
85984a87
DW
117 p.cargo("metadata")
118 .with_json(
1e682848 119 r#"
2c1274f6
KA
120 {
121 "packages": [
122 {
d1cacfed
YS
123 "authors": [],
124 "categories": [],
f9a56257 125 "default_run": null,
2c1274f6 126 "name": "foo",
d1cacfed
YS
127 "readme": null,
128 "repository": null,
72694e80 129 "homepage": null,
130 "documentation": null,
2c1274f6 131 "version": "0.5.0",
390af271 132 "rust_version": null,
2c1274f6 133 "id": "foo[..]",
d1cacfed 134 "keywords": [],
2c1274f6
KA
135 "source": null,
136 "dependencies": [],
62cd0dbe 137 "edition": "2015",
2c1274f6
KA
138 "license": null,
139 "license_file": null,
53de08a5 140 "links": null,
2c1274f6
KA
141 "description": null,
142 "targets": [
143 {
144 "kind": [
145 "lib",
146 "staticlib"
147 ],
148 "crate_types": [
149 "lib",
150 "staticlib"
151 ],
e831dd12 152 "doc": true,
e1d433d3 153 "doctest": true,
95b22d28 154 "test": true,
5dcc4f17 155 "edition": "2015",
2c1274f6 156 "name": "foo",
05400b80 157 "src_path": "[..]/foo/src/lib.rs"
2c1274f6
KA
158 }
159 ],
160 "features": {},
2efeeda1 161 "manifest_path": "[..]Cargo.toml",
7d41d454
SF
162 "metadata": null,
163 "publish": null
2c1274f6
KA
164 }
165 ],
166 "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
167 "resolve": {
168 "nodes": [
169 {
170 "dependencies": [],
39b1f752 171 "deps": [],
6a2b6468 172 "features": [],
2c1274f6
KA
173 "id": "foo 0.5.0 (path+file:[..]foo)"
174 }
175 ],
176 "root": "foo 0.5.0 (path+file:[..]foo)"
177 },
05400b80 178 "target_directory": "[..]foo/target",
fef215d3 179 "version": 1,
866d4316
BC
180 "workspace_root": "[..]/foo",
181 "metadata": null
1e682848 182 }"#,
fecb7246
AC
183 )
184 .run();
2c1274f6 185}
fe7291ad 186
0e0d9688 187#[cargo_test]
3904562f 188fn library_with_features() {
7fe2fbc8 189 let p = project()
3904562f 190 .file("src/lib.rs", "")
1e682848
AC
191 .file(
192 "Cargo.toml",
193 r#"
3904562f
AM
194[package]
195name = "foo"
196version = "0.5.0"
197
198[features]
199default = ["default_feat"]
200default_feat = []
201optional_feat = []
1e682848 202 "#,
fecb7246
AC
203 )
204 .build();
3904562f 205
85984a87
DW
206 p.cargo("metadata")
207 .with_json(
1e682848 208 r#"
3904562f
AM
209 {
210 "packages": [
211 {
d1cacfed
YS
212 "authors": [],
213 "categories": [],
f9a56257 214 "default_run": null,
3904562f 215 "name": "foo",
d1cacfed
YS
216 "readme": null,
217 "repository": null,
390af271 218 "rust_version": null,
72694e80 219 "homepage": null,
220 "documentation": null,
3904562f
AM
221 "version": "0.5.0",
222 "id": "foo[..]",
d1cacfed 223 "keywords": [],
3904562f
AM
224 "source": null,
225 "dependencies": [],
62cd0dbe 226 "edition": "2015",
3904562f
AM
227 "license": null,
228 "license_file": null,
53de08a5 229 "links": null,
3904562f
AM
230 "description": null,
231 "targets": [
232 {
233 "kind": [
234 "lib"
235 ],
236 "crate_types": [
237 "lib"
238 ],
e831dd12 239 "doc": true,
e1d433d3 240 "doctest": true,
95b22d28 241 "test": true,
5dcc4f17 242 "edition": "2015",
3904562f 243 "name": "foo",
05400b80 244 "src_path": "[..]/foo/src/lib.rs"
3904562f
AM
245 }
246 ],
247 "features": {
248 "default": [
540bd458 249 "default_feat"
3904562f
AM
250 ],
251 "default_feat": [],
252 "optional_feat": []
253 },
2efeeda1 254 "manifest_path": "[..]Cargo.toml",
7d41d454
SF
255 "metadata": null,
256 "publish": null
3904562f
AM
257 }
258 ],
259 "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
260 "resolve": {
261 "nodes": [
262 {
263 "dependencies": [],
39b1f752 264 "deps": [],
3904562f
AM
265 "features": [
266 "default",
267 "default_feat"
268 ],
269 "id": "foo 0.5.0 (path+file:[..]foo)"
270 }
271 ],
272 "root": "foo 0.5.0 (path+file:[..]foo)"
273 },
05400b80 274 "target_directory": "[..]foo/target",
3904562f 275 "version": 1,
866d4316
BC
276 "workspace_root": "[..]/foo",
277 "metadata": null
1e682848 278 }"#,
fecb7246
AC
279 )
280 .run();
3904562f
AM
281}
282
0e0d9688 283#[cargo_test]
6950bbb0 284fn cargo_metadata_with_deps_and_version() {
7fe2fbc8 285 let p = project()
d95983fd 286 .file("src/foo.rs", "")
1e682848
AC
287 .file(
288 "Cargo.toml",
289 r#"
6f8c7d5a
EH
290 [project]
291 name = "foo"
292 version = "0.5.0"
293 authors = []
294 license = "MIT"
295 description = "foo"
fe7291ad 296
6f8c7d5a
EH
297 [[bin]]
298 name = "foo"
fe7291ad 299
6f8c7d5a
EH
300 [dependencies]
301 bar = "*"
302 [dev-dependencies]
303 foobar = "*"
304 "#,
fecb7246
AC
305 )
306 .build();
fe7291ad 307 Package::new("baz", "0.0.1").publish();
1d68c7fb 308 Package::new("foobar", "0.0.1").publish();
fe7291ad
AK
309 Package::new("bar", "0.0.1").dep("baz", "0.0.1").publish();
310
85984a87
DW
311 p.cargo("metadata -q --format-version 1")
312 .with_json(
1e682848 313 r#"
b24bf7e6
AK
314 {
315 "packages": [
58869e5c
AS
316 {
317 "authors": [],
318 "categories": [],
f9a56257 319 "default_run": null,
58869e5c
AS
320 "dependencies": [
321 {
322 "features": [],
323 "kind": null,
324 "name": "baz",
325 "optional": false,
326 "registry": null,
327 "rename": null,
328 "req": "^0.0.1",
329 "source": "registry+https://github.com/rust-lang/crates.io-index",
330 "target": null,
331 "uses_default_features": true
332 }
333 ],
334 "description": null,
335 "edition": "2015",
336 "features": {},
337 "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
338 "keywords": [],
339 "license": null,
340 "license_file": null,
341 "links": null,
342 "manifest_path": "[..]Cargo.toml",
343 "metadata": null,
344 "publish": null,
345 "name": "bar",
346 "readme": null,
347 "repository": null,
390af271 348 "rust_version": null,
72694e80 349 "homepage": null,
350 "documentation": null,
58869e5c
AS
351 "source": "registry+https://github.com/rust-lang/crates.io-index",
352 "targets": [
353 {
354 "crate_types": [
355 "lib"
356 ],
e831dd12 357 "doc": true,
58869e5c 358 "doctest": true,
95b22d28 359 "test": true,
58869e5c
AS
360 "edition": "2015",
361 "kind": [
362 "lib"
363 ],
364 "name": "bar",
365 "src_path": "[..]src/lib.rs"
366 }
367 ],
368 "version": "0.0.1"
369 },
b24bf7e6 370 {
d1cacfed
YS
371 "authors": [],
372 "categories": [],
f9a56257 373 "default_run": null,
b24bf7e6 374 "dependencies": [],
d1cacfed 375 "description": null,
1d68c7fb 376 "edition": "2015",
b24bf7e6 377 "features": {},
db1940b0 378 "id": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
d1cacfed 379 "keywords": [],
1d68c7fb
LA
380 "license": null,
381 "license_file": null,
53de08a5 382 "links": null,
b24bf7e6 383 "manifest_path": "[..]Cargo.toml",
1d68c7fb 384 "metadata": null,
7d41d454 385 "publish": null,
b24bf7e6 386 "name": "baz",
d1cacfed
YS
387 "readme": null,
388 "repository": null,
390af271 389 "rust_version": null,
72694e80 390 "homepage": null,
391 "documentation": null,
db1940b0 392 "source": "registry+https://github.com/rust-lang/crates.io-index",
b24bf7e6
AK
393 "targets": [
394 {
2268d57b
KA
395 "crate_types": [
396 "lib"
397 ],
e831dd12 398 "doc": true,
e1d433d3 399 "doctest": true,
95b22d28 400 "test": true,
5dcc4f17 401 "edition": "2015",
1d68c7fb
LA
402 "kind": [
403 "lib"
404 ],
b24bf7e6 405 "name": "baz",
1d68c7fb 406 "src_path": "[..]src/lib.rs"
b24bf7e6
AK
407 }
408 ],
1d68c7fb 409 "version": "0.0.1"
b24bf7e6
AK
410 },
411 {
d1cacfed
YS
412 "authors": [],
413 "categories": [],
f9a56257 414 "default_run": null,
b24bf7e6
AK
415 "dependencies": [
416 {
417 "features": [],
418 "kind": null,
1d68c7fb 419 "name": "bar",
b24bf7e6 420 "optional": false,
3d84d0ad 421 "registry": null,
1d68c7fb
LA
422 "rename": null,
423 "req": "*",
db1940b0 424 "source": "registry+https://github.com/rust-lang/crates.io-index",
1d68c7fb
LA
425 "target": null,
426 "uses_default_features": true
427 },
428 {
429 "features": [],
430 "kind": "dev",
431 "name": "foobar",
432 "optional": false,
3d84d0ad 433 "registry": null,
1d68c7fb
LA
434 "rename": null,
435 "req": "*",
db1940b0 436 "source": "registry+https://github.com/rust-lang/crates.io-index",
b24bf7e6 437 "target": null,
1d68c7fb 438 "uses_default_features": true
b24bf7e6
AK
439 }
440 ],
1d68c7fb
LA
441 "description": "foo",
442 "edition": "2015",
b24bf7e6 443 "features": {},
1d68c7fb 444 "id": "foo 0.5.0 (path+file:[..]foo)",
d1cacfed 445 "keywords": [],
1d68c7fb
LA
446 "license": "MIT",
447 "license_file": null,
53de08a5 448 "links": null,
b24bf7e6 449 "manifest_path": "[..]Cargo.toml",
1d68c7fb 450 "metadata": null,
7d41d454 451 "publish": null,
1d68c7fb 452 "name": "foo",
d1cacfed
YS
453 "readme": null,
454 "repository": null,
390af271 455 "rust_version": null,
72694e80 456 "homepage": null,
457 "documentation": null,
1d68c7fb 458 "source": null,
b24bf7e6
AK
459 "targets": [
460 {
1d68c7fb
LA
461 "crate_types": [
462 "bin"
463 ],
e831dd12 464 "doc": true,
e1d433d3 465 "doctest": false,
95b22d28 466 "test": true,
1d68c7fb 467 "edition": "2015",
b24bf7e6 468 "kind": [
1d68c7fb 469 "bin"
b24bf7e6 470 ],
1d68c7fb
LA
471 "name": "foo",
472 "src_path": "[..]src/foo.rs"
473 }
474 ],
475 "version": "0.5.0"
476 },
477 {
478 "authors": [],
479 "categories": [],
f9a56257 480 "default_run": null,
1d68c7fb
LA
481 "dependencies": [],
482 "description": null,
483 "edition": "2015",
484 "features": {},
db1940b0 485 "id": "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1d68c7fb
LA
486 "keywords": [],
487 "license": null,
488 "license_file": null,
53de08a5 489 "links": null,
1d68c7fb
LA
490 "manifest_path": "[..]Cargo.toml",
491 "metadata": null,
7d41d454 492 "publish": null,
1d68c7fb
LA
493 "name": "foobar",
494 "readme": null,
495 "repository": null,
390af271 496 "rust_version": null,
72694e80 497 "homepage": null,
498 "documentation": null,
db1940b0 499 "source": "registry+https://github.com/rust-lang/crates.io-index",
1d68c7fb
LA
500 "targets": [
501 {
2268d57b
KA
502 "crate_types": [
503 "lib"
504 ],
e831dd12 505 "doc": true,
e1d433d3 506 "doctest": true,
95b22d28 507 "test": true,
5dcc4f17 508 "edition": "2015",
1d68c7fb
LA
509 "kind": [
510 "lib"
511 ],
512 "name": "foobar",
513 "src_path": "[..]src/lib.rs"
b24bf7e6
AK
514 }
515 ],
1d68c7fb 516 "version": "0.0.1"
b24bf7e6
AK
517 }
518 ],
519 "resolve": {
8456d2ae 520 "nodes": [
1d68c7fb 521 {
58869e5c
AS
522 "dependencies": [
523 "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
524 ],
525 "deps": [
526 {
527 "dep_kinds": [
528 {
529 "kind": null,
530 "target": null
531 }
532 ],
533 "name": "baz",
534 "pkg": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
535 }
536 ],
1d68c7fb 537 "features": [],
58869e5c 538 "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
1d68c7fb
LA
539 },
540 {
541 "dependencies": [],
542 "deps": [],
543 "features": [],
58869e5c 544 "id": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
1d68c7fb 545 },
8456d2ae
AK
546 {
547 "dependencies": [
db1940b0
LA
548 "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
549 "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
8456d2ae 550 ],
39b1f752 551 "deps": [
1d68c7fb 552 {
a7faecc3
EH
553 "dep_kinds": [
554 {
555 "kind": null,
556 "target": null
557 }
558 ],
1d68c7fb 559 "name": "bar",
db1940b0 560 "pkg": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
1d68c7fb
LA
561 },
562 {
a7faecc3
EH
563 "dep_kinds": [
564 {
565 "kind": "dev",
566 "target": null
567 }
568 ],
1d68c7fb 569 "name": "foobar",
db1940b0 570 "pkg": "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
1d68c7fb 571 }
39b1f752 572 ],
6a2b6468 573 "features": [],
8456d2ae
AK
574 "id": "foo 0.5.0 (path+file:[..]foo)"
575 },
b24bf7e6 576 {
58869e5c
AS
577 "dependencies": [],
578 "deps": [],
6a2b6468 579 "features": [],
58869e5c 580 "id": "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
b24bf7e6
AK
581 }
582 ],
8456d2ae 583 "root": "foo 0.5.0 (path+file:[..]foo)"
b24bf7e6 584 },
05400b80 585 "target_directory": "[..]foo/target",
fef215d3 586 "version": 1,
1d68c7fb
LA
587 "workspace_members": [
588 "foo 0.5.0 (path+file:[..]foo)"
589 ],
866d4316
BC
590 "workspace_root": "[..]/foo",
591 "metadata": null
1e682848 592 }"#,
fecb7246
AC
593 )
594 .run();
6950bbb0 595}
fe7291ad 596
0e0d9688 597#[cargo_test]
f7fe59d7 598fn example() {
7fe2fbc8 599 let p = project()
d43ee1dd
NK
600 .file("src/lib.rs", "")
601 .file("examples/ex.rs", "")
1e682848
AC
602 .file(
603 "Cargo.toml",
604 r#"
f7fe59d7
KA
605[package]
606name = "foo"
607version = "0.1.0"
608
609[[example]]
610name = "ex"
1e682848 611 "#,
fecb7246
AC
612 )
613 .build();
f7fe59d7 614
85984a87
DW
615 p.cargo("metadata")
616 .with_json(
1e682848 617 r#"
f7fe59d7
KA
618 {
619 "packages": [
620 {
d1cacfed
YS
621 "authors": [],
622 "categories": [],
f9a56257 623 "default_run": null,
f7fe59d7 624 "name": "foo",
d1cacfed
YS
625 "readme": null,
626 "repository": null,
390af271 627 "rust_version": null,
72694e80 628 "homepage": null,
629 "documentation": null,
f7fe59d7
KA
630 "version": "0.1.0",
631 "id": "foo[..]",
d1cacfed 632 "keywords": [],
f7fe59d7
KA
633 "license": null,
634 "license_file": null,
53de08a5 635 "links": null,
f7fe59d7 636 "description": null,
62cd0dbe 637 "edition": "2015",
f7fe59d7
KA
638 "source": null,
639 "dependencies": [],
640 "targets": [
641 {
642 "kind": [ "lib" ],
643 "crate_types": [ "lib" ],
e831dd12 644 "doc": true,
e1d433d3 645 "doctest": true,
95b22d28 646 "test": true,
5dcc4f17 647 "edition": "2015",
f7fe59d7 648 "name": "foo",
05400b80 649 "src_path": "[..]/foo/src/lib.rs"
f7fe59d7
KA
650 },
651 {
652 "kind": [ "example" ],
90bcf5c8 653 "crate_types": [ "bin" ],
e831dd12 654 "doc": false,
e1d433d3 655 "doctest": false,
95b22d28 656 "test": false,
5dcc4f17 657 "edition": "2015",
f7fe59d7 658 "name": "ex",
05400b80 659 "src_path": "[..]/foo/examples/ex.rs"
f7fe59d7
KA
660 }
661 ],
662 "features": {},
2efeeda1 663 "manifest_path": "[..]Cargo.toml",
7d41d454
SF
664 "metadata": null,
665 "publish": null
f7fe59d7
KA
666 }
667 ],
668 "workspace_members": [
669 "foo 0.1.0 (path+file:[..]foo)"
670 ],
671 "resolve": {
672 "root": "foo 0.1.0 (path+file://[..]foo)",
673 "nodes": [
674 {
675 "id": "foo 0.1.0 (path+file:[..]foo)",
6a2b6468 676 "features": [],
39b1f752
AK
677 "dependencies": [],
678 "deps": []
f7fe59d7
KA
679 }
680 ]
681 },
05400b80 682 "target_directory": "[..]foo/target",
fef215d3 683 "version": 1,
866d4316
BC
684 "workspace_root": "[..]/foo",
685 "metadata": null
1e682848 686 }"#,
fecb7246
AC
687 )
688 .run();
f7fe59d7
KA
689}
690
0e0d9688 691#[cargo_test]
f7fe59d7 692fn example_lib() {
7fe2fbc8 693 let p = project()
d43ee1dd
NK
694 .file("src/lib.rs", "")
695 .file("examples/ex.rs", "")
1e682848
AC
696 .file(
697 "Cargo.toml",
698 r#"
f7fe59d7
KA
699[package]
700name = "foo"
701version = "0.1.0"
702
703[[example]]
704name = "ex"
de92912a 705crate-type = ["rlib", "dylib"]
1e682848 706 "#,
fecb7246
AC
707 )
708 .build();
f7fe59d7 709
85984a87
DW
710 p.cargo("metadata")
711 .with_json(
1e682848 712 r#"
f7fe59d7
KA
713 {
714 "packages": [
715 {
d1cacfed
YS
716 "authors": [],
717 "categories": [],
f9a56257 718 "default_run": null,
f7fe59d7 719 "name": "foo",
d1cacfed
YS
720 "readme": null,
721 "repository": null,
390af271 722 "rust_version": null,
72694e80 723 "homepage": null,
724 "documentation": null,
f7fe59d7
KA
725 "version": "0.1.0",
726 "id": "foo[..]",
d1cacfed 727 "keywords": [],
f7fe59d7
KA
728 "license": null,
729 "license_file": null,
53de08a5 730 "links": null,
f7fe59d7 731 "description": null,
62cd0dbe 732 "edition": "2015",
f7fe59d7
KA
733 "source": null,
734 "dependencies": [],
735 "targets": [
736 {
737 "kind": [ "lib" ],
738 "crate_types": [ "lib" ],
e831dd12 739 "doc": true,
e1d433d3 740 "doctest": true,
95b22d28 741 "test": true,
5dcc4f17 742 "edition": "2015",
f7fe59d7 743 "name": "foo",
05400b80 744 "src_path": "[..]/foo/src/lib.rs"
f7fe59d7
KA
745 },
746 {
747 "kind": [ "example" ],
de92912a 748 "crate_types": [ "rlib", "dylib" ],
e831dd12 749 "doc": false,
e1d433d3 750 "doctest": false,
95b22d28 751 "test": false,
5dcc4f17 752 "edition": "2015",
f7fe59d7 753 "name": "ex",
05400b80 754 "src_path": "[..]/foo/examples/ex.rs"
f7fe59d7
KA
755 }
756 ],
757 "features": {},
2efeeda1 758 "manifest_path": "[..]Cargo.toml",
7d41d454
SF
759 "metadata": null,
760 "publish": null
f7fe59d7
KA
761 }
762 ],
763 "workspace_members": [
764 "foo 0.1.0 (path+file:[..]foo)"
765 ],
766 "resolve": {
767 "root": "foo 0.1.0 (path+file://[..]foo)",
768 "nodes": [
769 {
770 "id": "foo 0.1.0 (path+file:[..]foo)",
6a2b6468 771 "features": [],
39b1f752
AK
772 "dependencies": [],
773 "deps": []
f7fe59d7
KA
774 }
775 ]
776 },
05400b80 777 "target_directory": "[..]foo/target",
fef215d3 778 "version": 1,
866d4316
BC
779 "workspace_root": "[..]/foo",
780 "metadata": null
1e682848 781 }"#,
fecb7246
AC
782 )
783 .run();
f7fe59d7
KA
784}
785
0e0d9688 786#[cargo_test]
578c1a11 787fn workspace_metadata() {
7fe2fbc8 788 let p = project()
1e682848
AC
789 .file(
790 "Cargo.toml",
791 r#"
6f8c7d5a
EH
792 [workspace]
793 members = ["bar", "baz"]
866d4316 794
6f8c7d5a
EH
795 [workspace.metadata]
796 tool1 = "hello"
797 tool2 = [1, 2, 3]
866d4316 798
6f8c7d5a
EH
799 [workspace.metadata.foo]
800 bar = 3
866d4316 801
6f8c7d5a 802 "#,
fecb7246
AC
803 )
804 .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
578c1a11
AK
805 .file("bar/src/lib.rs", "")
806 .file("baz/Cargo.toml", &basic_lib_manifest("baz"))
d43ee1dd
NK
807 .file("baz/src/lib.rs", "")
808 .build();
578c1a11 809
85984a87
DW
810 p.cargo("metadata")
811 .with_json(
1e682848 812 r#"
578c1a11
AK
813 {
814 "packages": [
815 {
d1cacfed
YS
816 "authors": [
817 "wycats@example.com"
818 ],
819 "categories": [],
f9a56257 820 "default_run": null,
578c1a11
AK
821 "name": "bar",
822 "version": "0.5.0",
823 "id": "bar[..]",
d1cacfed
YS
824 "readme": null,
825 "repository": null,
390af271 826 "rust_version": null,
72694e80 827 "homepage": null,
828 "documentation": null,
d1cacfed 829 "keywords": [],
578c1a11
AK
830 "source": null,
831 "dependencies": [],
85d09d08
JF
832 "license": null,
833 "license_file": null,
53de08a5 834 "links": null,
ab493a17 835 "description": null,
62cd0dbe 836 "edition": "2015",
578c1a11
AK
837 "targets": [
838 {
839 "kind": [ "lib" ],
2268d57b 840 "crate_types": [ "lib" ],
e831dd12 841 "doc": true,
e1d433d3 842 "doctest": true,
95b22d28 843 "test": true,
5dcc4f17 844 "edition": "2015",
578c1a11 845 "name": "bar",
05400b80 846 "src_path": "[..]bar/src/lib.rs"
578c1a11
AK
847 }
848 ],
849 "features": {},
05400b80 850 "manifest_path": "[..]bar/Cargo.toml",
7d41d454
SF
851 "metadata": null,
852 "publish": null
578c1a11
AK
853 },
854 {
d1cacfed
YS
855 "authors": [
856 "wycats@example.com"
857 ],
858 "categories": [],
f9a56257 859 "default_run": null,
578c1a11 860 "name": "baz",
d1cacfed
YS
861 "readme": null,
862 "repository": null,
390af271 863 "rust_version": null,
72694e80 864 "homepage": null,
865 "documentation": null,
578c1a11
AK
866 "version": "0.5.0",
867 "id": "baz[..]",
d1cacfed 868 "keywords": [],
578c1a11
AK
869 "source": null,
870 "dependencies": [],
85d09d08
JF
871 "license": null,
872 "license_file": null,
53de08a5 873 "links": null,
ab493a17 874 "description": null,
62cd0dbe 875 "edition": "2015",
578c1a11
AK
876 "targets": [
877 {
878 "kind": [ "lib" ],
2268d57b 879 "crate_types": [ "lib" ],
e831dd12 880 "doc": true,
e1d433d3 881 "doctest": true,
95b22d28 882 "test": true,
5dcc4f17 883 "edition": "2015",
578c1a11 884 "name": "baz",
05400b80 885 "src_path": "[..]baz/src/lib.rs"
578c1a11
AK
886 }
887 ],
888 "features": {},
05400b80 889 "manifest_path": "[..]baz/Cargo.toml",
7d41d454
SF
890 "metadata": null,
891 "publish": null
578c1a11
AK
892 }
893 ],
58869e5c 894 "workspace_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
578c1a11
AK
895 "resolve": {
896 "nodes": [
897 {
898 "dependencies": [],
39b1f752 899 "deps": [],
6a2b6468 900 "features": [],
58869e5c 901 "id": "bar 0.5.0 (path+file:[..]bar)"
578c1a11
AK
902 },
903 {
904 "dependencies": [],
39b1f752 905 "deps": [],
6a2b6468 906 "features": [],
58869e5c 907 "id": "baz 0.5.0 (path+file:[..]baz)"
578c1a11
AK
908 }
909 ],
910 "root": null
911 },
05400b80 912 "target_directory": "[..]foo/target",
fef215d3 913 "version": 1,
866d4316
BC
914 "workspace_root": "[..]/foo",
915 "metadata": {
916 "tool1": "hello",
917 "tool2": [1, 2, 3],
918 "foo": {
919 "bar": 3
920 }
921 }
1e682848 922 }"#,
fecb7246
AC
923 )
924 .run();
578c1a11
AK
925}
926
0e0d9688 927#[cargo_test]
578c1a11 928fn workspace_metadata_no_deps() {
7fe2fbc8 929 let p = project()
1e682848
AC
930 .file(
931 "Cargo.toml",
932 r#"
6f8c7d5a
EH
933 [workspace]
934 members = ["bar", "baz"]
935 "#,
fecb7246
AC
936 )
937 .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
578c1a11
AK
938 .file("bar/src/lib.rs", "")
939 .file("baz/Cargo.toml", &basic_lib_manifest("baz"))
d43ee1dd
NK
940 .file("baz/src/lib.rs", "")
941 .build();
578c1a11 942
85984a87
DW
943 p.cargo("metadata --no-deps")
944 .with_json(
1e682848 945 r#"
578c1a11
AK
946 {
947 "packages": [
948 {
d1cacfed
YS
949 "authors": [
950 "wycats@example.com"
951 ],
952 "categories": [],
f9a56257 953 "default_run": null,
578c1a11 954 "name": "bar",
d1cacfed
YS
955 "readme": null,
956 "repository": null,
390af271 957 "rust_version": null,
72694e80 958 "homepage": null,
959 "documentation": null,
578c1a11
AK
960 "version": "0.5.0",
961 "id": "bar[..]",
d1cacfed 962 "keywords": [],
578c1a11
AK
963 "source": null,
964 "dependencies": [],
85d09d08
JF
965 "license": null,
966 "license_file": null,
53de08a5 967 "links": null,
ab493a17 968 "description": null,
62cd0dbe 969 "edition": "2015",
578c1a11
AK
970 "targets": [
971 {
972 "kind": [ "lib" ],
2268d57b 973 "crate_types": [ "lib" ],
e831dd12 974 "doc": true,
e1d433d3 975 "doctest": true,
95b22d28 976 "test": true,
5dcc4f17 977 "edition": "2015",
578c1a11 978 "name": "bar",
05400b80 979 "src_path": "[..]bar/src/lib.rs"
578c1a11
AK
980 }
981 ],
982 "features": {},
05400b80 983 "manifest_path": "[..]bar/Cargo.toml",
7d41d454
SF
984 "metadata": null,
985 "publish": null
578c1a11
AK
986 },
987 {
d1cacfed
YS
988 "authors": [
989 "wycats@example.com"
990 ],
991 "categories": [],
f9a56257 992 "default_run": null,
578c1a11 993 "name": "baz",
d1cacfed
YS
994 "readme": null,
995 "repository": null,
390af271 996 "rust_version": null,
72694e80 997 "homepage": null,
998 "documentation": null,
578c1a11
AK
999 "version": "0.5.0",
1000 "id": "baz[..]",
d1cacfed 1001 "keywords": [],
578c1a11
AK
1002 "source": null,
1003 "dependencies": [],
85d09d08
JF
1004 "license": null,
1005 "license_file": null,
53de08a5 1006 "links": null,
ab493a17 1007 "description": null,
62cd0dbe 1008 "edition": "2015",
578c1a11
AK
1009 "targets": [
1010 {
1011 "kind": [ "lib" ],
2268d57b 1012 "crate_types": ["lib"],
e831dd12 1013 "doc": true,
e1d433d3 1014 "doctest": true,
95b22d28 1015 "test": true,
5dcc4f17 1016 "edition": "2015",
578c1a11 1017 "name": "baz",
05400b80 1018 "src_path": "[..]baz/src/lib.rs"
578c1a11
AK
1019 }
1020 ],
1021 "features": {},
05400b80 1022 "manifest_path": "[..]baz/Cargo.toml",
7d41d454
SF
1023 "metadata": null,
1024 "publish": null
578c1a11
AK
1025 }
1026 ],
58869e5c 1027 "workspace_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
578c1a11 1028 "resolve": null,
05400b80 1029 "target_directory": "[..]foo/target",
fef215d3 1030 "version": 1,
866d4316
BC
1031 "workspace_root": "[..]/foo",
1032 "metadata": null
1e682848 1033 }"#,
fecb7246
AC
1034 )
1035 .run();
578c1a11
AK
1036}
1037
0e0d9688 1038#[cargo_test]
6950bbb0 1039fn cargo_metadata_with_invalid_manifest() {
7fe2fbc8 1040 let p = project().file("Cargo.toml", "").build();
fec3ce92 1041
85984a87
DW
1042 p.cargo("metadata --format-version 1")
1043 .with_status(101)
1044 .with_stderr(
1e682848 1045 "\
29cdad4f 1046[ERROR] failed to parse manifest at `[..]`
fec3ce92
AK
1047
1048Caused by:
1e682848 1049 virtual manifests must be configured with [workspace]",
fecb7246
AC
1050 )
1051 .run();
6950bbb0 1052}
80e3c05b 1053
2efeeda1 1054const MANIFEST_OUTPUT: &str = r#"
80e3c05b
AK
1055{
1056 "packages": [{
d1cacfed
YS
1057 "authors": [
1058 "wycats@example.com"
1059 ],
1060 "categories": [],
f9a56257 1061 "default_run": null,
80e3c05b
AK
1062 "name":"foo",
1063 "version":"0.5.0",
1064 "id":"foo[..]0.5.0[..](path+file://[..]/foo)",
1065 "source":null,
1066 "dependencies":[],
d1cacfed 1067 "keywords": [],
85d09d08
JF
1068 "license": null,
1069 "license_file": null,
53de08a5 1070 "links": null,
ab493a17 1071 "description": null,
62cd0dbe 1072 "edition": "2015",
80e3c05b
AK
1073 "targets":[{
1074 "kind":["bin"],
2268d57b 1075 "crate_types":["bin"],
e831dd12 1076 "doc": true,
e1d433d3 1077 "doctest": false,
95b22d28 1078 "test": true,
5dcc4f17 1079 "edition": "2015",
80e3c05b 1080 "name":"foo",
05400b80 1081 "src_path":"[..]/foo/src/foo.rs"
80e3c05b
AK
1082 }],
1083 "features":{},
2efeeda1 1084 "manifest_path":"[..]Cargo.toml",
d1cacfed 1085 "metadata": null,
7d41d454 1086 "publish": null,
d1cacfed 1087 "readme": null,
72694e80 1088 "repository": null,
390af271 1089 "rust_version": null,
72694e80 1090 "homepage": null,
1091 "documentation": null
80e3c05b 1092 }],
578c1a11 1093 "workspace_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
80e3c05b 1094 "resolve": null,
05400b80 1095 "target_directory": "[..]foo/target",
fef215d3 1096 "version": 1,
866d4316
BC
1097 "workspace_root": "[..]/foo",
1098 "metadata": null
80e3c05b
AK
1099}"#;
1100
0e0d9688 1101#[cargo_test]
6950bbb0 1102fn cargo_metadata_no_deps_path_to_cargo_toml_relative() {
7fe2fbc8 1103 let p = project()
80e3c05b 1104 .file("Cargo.toml", &basic_bin_manifest("foo"))
d43ee1dd
NK
1105 .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1106 .build();
80e3c05b 1107
85984a87
DW
1108 p.cargo("metadata --no-deps --manifest-path foo/Cargo.toml")
1109 .cwd(p.root().parent().unwrap())
1110 .with_json(MANIFEST_OUTPUT)
1111 .run();
6950bbb0 1112}
80e3c05b 1113
0e0d9688 1114#[cargo_test]
6950bbb0 1115fn cargo_metadata_no_deps_path_to_cargo_toml_absolute() {
7fe2fbc8 1116 let p = project()
80e3c05b 1117 .file("Cargo.toml", &basic_bin_manifest("foo"))
d43ee1dd
NK
1118 .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1119 .build();
80e3c05b 1120
85984a87
DW
1121 p.cargo("metadata --no-deps --manifest-path")
1122 .arg(p.root().join("Cargo.toml"))
1123 .cwd(p.root().parent().unwrap())
1124 .with_json(MANIFEST_OUTPUT)
1125 .run();
6950bbb0 1126}
80e3c05b 1127
0e0d9688 1128#[cargo_test]
6950bbb0 1129fn cargo_metadata_no_deps_path_to_cargo_toml_parent_relative() {
7fe2fbc8 1130 let p = project()
80e3c05b 1131 .file("Cargo.toml", &basic_bin_manifest("foo"))
d43ee1dd
NK
1132 .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1133 .build();
80e3c05b 1134
85984a87
DW
1135 p.cargo("metadata --no-deps --manifest-path foo")
1136 .cwd(p.root().parent().unwrap())
1137 .with_status(101)
1138 .with_stderr(
1e682848
AC
1139 "[ERROR] the manifest-path must be \
1140 a path to a Cargo.toml file",
fecb7246
AC
1141 )
1142 .run();
6950bbb0 1143}
80e3c05b 1144
0e0d9688 1145#[cargo_test]
6950bbb0 1146fn cargo_metadata_no_deps_path_to_cargo_toml_parent_absolute() {
7fe2fbc8 1147 let p = project()
80e3c05b 1148 .file("Cargo.toml", &basic_bin_manifest("foo"))
d43ee1dd
NK
1149 .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1150 .build();
80e3c05b 1151
85984a87
DW
1152 p.cargo("metadata --no-deps --manifest-path")
1153 .arg(p.root())
1154 .cwd(p.root().parent().unwrap())
1155 .with_status(101)
1156 .with_stderr(
1e682848
AC
1157 "[ERROR] the manifest-path must be \
1158 a path to a Cargo.toml file",
fecb7246
AC
1159 )
1160 .run();
6950bbb0 1161}
80e3c05b 1162
0e0d9688 1163#[cargo_test]
6950bbb0 1164fn cargo_metadata_no_deps_cwd() {
7fe2fbc8 1165 let p = project()
80e3c05b 1166 .file("Cargo.toml", &basic_bin_manifest("foo"))
d43ee1dd
NK
1167 .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1168 .build();
80e3c05b 1169
85984a87 1170 p.cargo("metadata --no-deps")
85984a87
DW
1171 .with_json(MANIFEST_OUTPUT)
1172 .run();
6950bbb0 1173}
80e3c05b 1174
0e0d9688 1175#[cargo_test]
2c1274f6 1176fn cargo_metadata_bad_version() {
7fe2fbc8 1177 let p = project()
80e3c05b 1178 .file("Cargo.toml", &basic_bin_manifest("foo"))
d43ee1dd
NK
1179 .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1180 .build();
80e3c05b 1181
85984a87 1182 p.cargo("metadata --no-deps --format-version 2")
85984a87
DW
1183 .with_status(1)
1184 .with_stderr_contains(
1e682848 1185 "\
4d3ca921
AK
1186error: '2' isn't a valid value for '--format-version <VERSION>'
1187<tab>[possible values: 1]
1e682848 1188",
fecb7246
AC
1189 )
1190 .run();
6950bbb0 1191}
49fe6500 1192
0e0d9688 1193#[cargo_test]
49fe6500 1194fn multiple_features() {
7fe2fbc8 1195 let p = project()
1e682848
AC
1196 .file(
1197 "Cargo.toml",
1198 r#"
6f8c7d5a
EH
1199 [package]
1200 name = "foo"
1201 version = "0.1.0"
1202 authors = []
49fe6500 1203
6f8c7d5a
EH
1204 [features]
1205 a = []
1206 b = []
1207 "#,
fecb7246
AC
1208 )
1209 .file("src/lib.rs", "")
d43ee1dd 1210 .build();
49fe6500 1211
85984a87 1212 p.cargo("metadata --features").arg("a b").run();
49fe6500 1213}
2efeeda1 1214
0e0d9688 1215#[cargo_test]
2efeeda1 1216fn package_metadata() {
7fe2fbc8 1217 let p = project()
2efeeda1
AR
1218 .file(
1219 "Cargo.toml",
1220 r#"
6f8c7d5a
EH
1221 [package]
1222 name = "foo"
1223 version = "0.1.0"
1224 authors = ["wycats@example.com"]
1225 categories = ["database"]
1226 keywords = ["database"]
1227 readme = "README.md"
1228 repository = "https://github.com/rust-lang/cargo"
435117a8 1229 homepage = "https://rust-lang.org"
1230 documentation = "https://doc.rust-lang.org/stable/std/"
6f8c7d5a
EH
1231
1232 [package.metadata.bar]
1233 baz = "quux"
1234 "#,
fecb7246 1235 )
58ee013f 1236 .file("README.md", "")
fecb7246 1237 .file("src/lib.rs", "")
2efeeda1
AR
1238 .build();
1239
85984a87
DW
1240 p.cargo("metadata --no-deps")
1241 .with_json(
2efeeda1
AR
1242 r#"
1243 {
1244 "packages": [
1245 {
d4162ed1
YS
1246 "authors": ["wycats@example.com"],
1247 "categories": ["database"],
f9a56257 1248 "default_run": null,
2efeeda1 1249 "name": "foo",
d4162ed1
YS
1250 "readme": "README.md",
1251 "repository": "https://github.com/rust-lang/cargo",
390af271 1252 "rust_version": null,
435117a8 1253 "homepage": "https://rust-lang.org",
1254 "documentation": "https://doc.rust-lang.org/stable/std/",
2efeeda1
AR
1255 "version": "0.1.0",
1256 "id": "foo[..]",
d4162ed1 1257 "keywords": ["database"],
2efeeda1
AR
1258 "source": null,
1259 "dependencies": [],
62cd0dbe 1260 "edition": "2015",
2efeeda1
AR
1261 "license": null,
1262 "license_file": null,
53de08a5 1263 "links": null,
2efeeda1
AR
1264 "description": null,
1265 "targets": [
1266 {
1267 "kind": [ "lib" ],
1268 "crate_types": [ "lib" ],
e831dd12 1269 "doc": true,
e1d433d3 1270 "doctest": true,
95b22d28 1271 "test": true,
5dcc4f17 1272 "edition": "2015",
2efeeda1 1273 "name": "foo",
05400b80 1274 "src_path": "[..]foo/src/lib.rs"
2efeeda1
AR
1275 }
1276 ],
1277 "features": {},
05400b80 1278 "manifest_path": "[..]foo/Cargo.toml",
2efeeda1
AR
1279 "metadata": {
1280 "bar": {
1281 "baz": "quux"
1282 }
7d41d454
SF
1283 },
1284 "publish": null
1285 }
1286 ],
1287 "workspace_members": ["foo[..]"],
1288 "resolve": null,
1289 "target_directory": "[..]foo/target",
1290 "version": 1,
866d4316
BC
1291 "workspace_root": "[..]/foo",
1292 "metadata": null
7d41d454
SF
1293 }"#,
1294 )
1295 .run();
1296}
1297
1298#[cargo_test]
1299fn package_publish() {
1300 let p = project()
1301 .file(
1302 "Cargo.toml",
1303 r#"
6f8c7d5a
EH
1304 [package]
1305 name = "foo"
1306 version = "0.1.0"
1307 authors = ["wycats@example.com"]
1308 categories = ["database"]
1309 keywords = ["database"]
1310 readme = "README.md"
1311 repository = "https://github.com/rust-lang/cargo"
1312 publish = ["my-registry"]
1313 "#,
7d41d454 1314 )
58ee013f 1315 .file("README.md", "")
7d41d454
SF
1316 .file("src/lib.rs", "")
1317 .build();
1318
1319 p.cargo("metadata --no-deps")
1320 .with_json(
1321 r#"
1322 {
1323 "packages": [
1324 {
1325 "authors": ["wycats@example.com"],
1326 "categories": ["database"],
f9a56257 1327 "default_run": null,
7d41d454
SF
1328 "name": "foo",
1329 "readme": "README.md",
1330 "repository": "https://github.com/rust-lang/cargo",
390af271 1331 "rust_version": null,
72694e80 1332 "homepage": null,
1333 "documentation": null,
7d41d454
SF
1334 "version": "0.1.0",
1335 "id": "foo[..]",
1336 "keywords": ["database"],
1337 "source": null,
1338 "dependencies": [],
1339 "edition": "2015",
1340 "license": null,
1341 "license_file": null,
1342 "links": null,
1343 "description": null,
1344 "targets": [
1345 {
1346 "kind": [ "lib" ],
1347 "crate_types": [ "lib" ],
e831dd12 1348 "doc": true,
7d41d454 1349 "doctest": true,
95b22d28 1350 "test": true,
7d41d454
SF
1351 "edition": "2015",
1352 "name": "foo",
1353 "src_path": "[..]foo/src/lib.rs"
1354 }
1355 ],
1356 "features": {},
1357 "manifest_path": "[..]foo/Cargo.toml",
1358 "metadata": null,
1359 "publish": ["my-registry"]
2efeeda1
AR
1360 }
1361 ],
1362 "workspace_members": ["foo[..]"],
1363 "resolve": null,
05400b80 1364 "target_directory": "[..]foo/target",
2efeeda1 1365 "version": 1,
866d4316
BC
1366 "workspace_root": "[..]/foo",
1367 "metadata": null
2efeeda1 1368 }"#,
fecb7246
AC
1369 )
1370 .run();
2efeeda1 1371}
4f0e1361 1372
0e0d9688 1373#[cargo_test]
4f0e1361 1374fn cargo_metadata_path_to_cargo_toml_project() {
7fe2fbc8 1375 let p = project()
4f0e1361 1376 .file(
1377 "Cargo.toml",
1378 r#"
6f8c7d5a
EH
1379 [workspace]
1380 members = ["bar"]
1381 "#,
fecb7246
AC
1382 )
1383 .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
4f0e1361 1384 .file("bar/src/lib.rs", "")
1385 .build();
1386
511d4bc5 1387 p.cargo("package --manifest-path")
4f0e1361 1388 .arg(p.root().join("bar/Cargo.toml"))
85984a87
DW
1389 .cwd(p.root().parent().unwrap())
1390 .run();
4f0e1361 1391
85984a87
DW
1392 p.cargo("metadata --manifest-path")
1393 .arg(p.root().join("target/package/bar-0.5.0/Cargo.toml"))
1394 .with_json(
1395 r#"
4f0e1361 1396 {
6f8c7d5a 1397 "packages": [
62cd0dbe
AP
1398 {
1399 "authors": [
1400 "wycats@example.com"
1401 ],
1402 "categories": [],
f9a56257 1403 "default_run": null,
62cd0dbe
AP
1404 "dependencies": [],
1405 "description": null,
6f8c7d5a 1406 "edition": "2015",
62cd0dbe 1407 "features": {},
6f8c7d5a 1408 "id": "bar 0.5.0 ([..])",
62cd0dbe
AP
1409 "keywords": [],
1410 "license": null,
1411 "license_file": null,
53de08a5 1412 "links": null,
62cd0dbe
AP
1413 "manifest_path": "[..]Cargo.toml",
1414 "metadata": null,
7d41d454 1415 "publish": null,
6f8c7d5a 1416 "name": "bar",
62cd0dbe
AP
1417 "readme": null,
1418 "repository": null,
390af271 1419 "rust_version": null,
72694e80 1420 "homepage": null,
1421 "documentation": null,
62cd0dbe
AP
1422 "source": null,
1423 "targets": [
6f8c7d5a
EH
1424 {
1425 "crate_types": [
1426 "lib"
1427 ],
e831dd12 1428 "doc": true,
6f8c7d5a
EH
1429 "doctest": true,
1430 "test": true,
1431 "edition": "2015",
1432 "kind": [
1433 "lib"
1434 ],
1435 "name": "bar",
1436 "src_path": "[..]src/lib.rs"
1437 }
5dcc4f17 1438 ],
6f8c7d5a 1439 "version": "0.5.0"
5dcc4f17 1440 }
6f8c7d5a
EH
1441 ],
1442 "resolve": {
1443 "nodes": [
5dcc4f17
AP
1444 {
1445 "dependencies": [],
39b1f752 1446 "deps": [],
5dcc4f17 1447 "features": [],
6f8c7d5a 1448 "id": "bar 0.5.0 ([..])"
5dcc4f17 1449 }
6f8c7d5a
EH
1450 ],
1451 "root": "bar 0.5.0 (path+file:[..])"
1452 },
1453 "target_directory": "[..]",
1454 "version": 1,
1455 "workspace_members": [
1456 "bar 0.5.0 (path+file:[..])"
5dcc4f17 1457 ],
6f8c7d5a
EH
1458 "workspace_root": "[..]",
1459 "metadata": null
1460 }
1461 "#,
fecb7246
AC
1462 )
1463 .run();
5dcc4f17
AP
1464}
1465
0e0d9688 1466#[cargo_test]
6f8c7d5a 1467fn package_edition_2018() {
5dcc4f17
AP
1468 let p = project()
1469 .file("src/lib.rs", "")
5dcc4f17
AP
1470 .file(
1471 "Cargo.toml",
1472 r#"
6f8c7d5a
EH
1473 [package]
1474 name = "foo"
1475 version = "0.1.0"
1476 authors = ["wycats@example.com"]
1477 edition = "2018"
1478 "#,
fecb7246
AC
1479 )
1480 .build();
85984a87 1481 p.cargo("metadata")
85984a87 1482 .with_json(
5dcc4f17 1483 r#"
6f8c7d5a
EH
1484 {
1485 "packages": [
1486 {
1487 "authors": [
1488 "wycats@example.com"
1489 ],
1490 "categories": [],
f9a56257 1491 "default_run": null,
6f8c7d5a
EH
1492 "dependencies": [],
1493 "description": null,
1494 "edition": "2018",
1495 "features": {},
1496 "id": "foo 0.1.0 (path+file:[..])",
1497 "keywords": [],
1498 "license": null,
1499 "license_file": null,
1500 "links": null,
1501 "manifest_path": "[..]Cargo.toml",
1502 "metadata": null,
1503 "publish": null,
1504 "name": "foo",
1505 "readme": null,
1506 "repository": null,
390af271 1507 "rust_version": null,
72694e80 1508 "homepage": null,
1509 "documentation": null,
6f8c7d5a
EH
1510 "source": null,
1511 "targets": [
1512 {
1513 "crate_types": [
1514 "lib"
1515 ],
e831dd12 1516 "doc": true,
6f8c7d5a
EH
1517 "doctest": true,
1518 "test": true,
1519 "edition": "2018",
1520 "kind": [
1521 "lib"
1522 ],
1523 "name": "foo",
1524 "src_path": "[..]src/lib.rs"
1525 }
1526 ],
1abc4f2e 1527 "version": "0.1.0"
1528 }
1529 ],
1530 "resolve": {
1531 "nodes": [
1532 {
1533 "dependencies": [],
1534 "deps": [],
1535 "features": [],
1536 "id": "foo 0.1.0 (path+file:[..])"
1537 }
1538 ],
1539 "root": "foo 0.1.0 (path+file:[..])"
1540 },
1541 "target_directory": "[..]",
1542 "version": 1,
1543 "workspace_members": [
1544 "foo 0.1.0 (path+file:[..])"
1545 ],
1546 "workspace_root": "[..]",
1547 "metadata": null
1548 }
1549 "#,
1550 )
1551 .run();
1552}
1553
1554#[cargo_test]
1555fn package_default_run() {
1556 let p = project()
1557 .file("src/lib.rs", "")
1558 .file("src/bin/a.rs", r#"fn main() { println!("hello A"); }"#)
1559 .file("src/bin/b.rs", r#"fn main() { println!("hello B"); }"#)
1560 .file(
1561 "Cargo.toml",
1562 r#"
1563 [project]
1564 name = "foo"
1565 version = "0.1.0"
1566 authors = ["wycats@example.com"]
1567 edition = "2018"
1568 default-run = "a"
1569 "#,
1570 )
1571 .build();
2492bf53
EH
1572 let json = p.cargo("metadata").run_json();
1573 assert_eq!(json["packages"][0]["default_run"], json!("a"));
6f8c7d5a
EH
1574}
1575
390af271 1576#[cargo_test]
1577fn package_rust_version() {
1578 let p = project()
1579 .file("src/lib.rs", "")
1580 .file(
1581 "Cargo.toml",
1582 r#"
1583 [project]
1584 name = "foo"
1585 version = "0.1.0"
1586 authors = ["wycats@example.com"]
1587 edition = "2018"
1588 rust-version = "1.56"
1589 "#,
1590 )
1591 .build();
1592 let json = p.cargo("metadata").run_json();
1593 assert_eq!(json["packages"][0]["rust_version"], json!("1.56"));
1594}
1595
6f8c7d5a
EH
1596#[cargo_test]
1597fn target_edition_2018() {
1598 let p = project()
1599 .file("src/lib.rs", "")
1600 .file("src/main.rs", "")
1601 .file(
1602 "Cargo.toml",
1603 r#"
1604 [package]
1605 name = "foo"
1606 version = "0.1.0"
1607 authors = ["wycats@example.com"]
1608 edition = "2015"
1609
1610 [lib]
1611 edition = "2018"
1612 "#,
1613 )
1614 .build();
1615 p.cargo("metadata")
1616 .with_json(
1617 r#"
1618 {
1619 "packages": [
62cd0dbe 1620 {
6f8c7d5a
EH
1621 "authors": [
1622 "wycats@example.com"
1623 ],
1624 "categories": [],
f9a56257 1625 "default_run": null,
62cd0dbe 1626 "dependencies": [],
6f8c7d5a
EH
1627 "description": null,
1628 "edition": "2015",
1629 "features": {},
1630 "id": "foo 0.1.0 (path+file:[..])",
1631 "keywords": [],
1632 "license": null,
1633 "license_file": null,
1634 "links": null,
1635 "manifest_path": "[..]Cargo.toml",
1636 "metadata": null,
1637 "publish": null,
1638 "name": "foo",
1639 "readme": null,
1640 "repository": null,
390af271 1641 "rust_version": null,
72694e80 1642 "homepage": null,
1643 "documentation": null,
6f8c7d5a
EH
1644 "source": null,
1645 "targets": [
1646 {
1647 "crate_types": [
1648 "lib"
1649 ],
e831dd12 1650 "doc": true,
6f8c7d5a
EH
1651 "doctest": true,
1652 "test": true,
1653 "edition": "2018",
1654 "kind": [
1655 "lib"
1656 ],
1657 "name": "foo",
1658 "src_path": "[..]src/lib.rs"
1659 },
1660 {
1661 "crate_types": [
1662 "bin"
1663 ],
e831dd12 1664 "doc": true,
6f8c7d5a
EH
1665 "doctest": false,
1666 "test": true,
1667 "edition": "2015",
1668 "kind": [
1669 "bin"
1670 ],
1671 "name": "foo",
1672 "src_path": "[..]src/main.rs"
1673 }
1674 ],
1675 "version": "0.1.0"
62cd0dbe
AP
1676 }
1677 ],
6f8c7d5a
EH
1678 "resolve": {
1679 "nodes": [
1680 {
1681 "dependencies": [],
1682 "deps": [],
1683 "features": [],
1684 "id": "foo 0.1.0 (path+file:[..])"
1685 }
1686 ],
1687 "root": "foo 0.1.0 (path+file:[..])"
1688 },
1689 "target_directory": "[..]",
1690 "version": 1,
1691 "workspace_members": [
1692 "foo 0.1.0 (path+file:[..])"
1693 ],
1694 "workspace_root": "[..]",
1695 "metadata": null
1696 }
1697 "#,
fecb7246
AC
1698 )
1699 .run();
62cd0dbe 1700}
39b1f752 1701
0e0d9688 1702#[cargo_test]
39b1f752
AK
1703fn rename_dependency() {
1704 Package::new("bar", "0.1.0").publish();
1705 Package::new("bar", "0.2.0").publish();
1706
1707 let p = project()
1708 .file(
1709 "Cargo.toml",
1710 r#"
6f8c7d5a
EH
1711 [project]
1712 name = "foo"
1713 version = "0.0.1"
1714 authors = []
39b1f752 1715
6f8c7d5a
EH
1716 [dependencies]
1717 bar = { version = "0.1.0" }
1718 baz = { version = "0.2.0", package = "bar" }
1719 "#,
fecb7246
AC
1720 )
1721 .file("src/lib.rs", "extern crate bar; extern crate baz;")
39b1f752
AK
1722 .build();
1723
85984a87 1724 p.cargo("metadata")
85984a87
DW
1725 .with_json(
1726 r#"
39b1f752
AK
1727{
1728 "packages": [
1729 {
1730 "authors": [],
1731 "categories": [],
f9a56257 1732 "default_run": null,
58869e5c 1733 "dependencies": [],
39b1f752
AK
1734 "description": null,
1735 "edition": "2015",
1736 "features": {},
58869e5c 1737 "id": "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
39b1f752
AK
1738 "keywords": [],
1739 "license": null,
1740 "license_file": null,
53de08a5 1741 "links": null,
39b1f752
AK
1742 "manifest_path": "[..]",
1743 "metadata": null,
7d41d454 1744 "publish": null,
58869e5c 1745 "name": "bar",
39b1f752
AK
1746 "readme": null,
1747 "repository": null,
390af271 1748 "rust_version": null,
72694e80 1749 "homepage": null,
1750 "documentation": null,
58869e5c 1751 "source": "registry+https://github.com/rust-lang/crates.io-index",
39b1f752
AK
1752 "targets": [
1753 {
1754 "crate_types": [
1755 "lib"
1756 ],
e831dd12 1757 "doc": true,
e1d433d3 1758 "doctest": true,
95b22d28 1759 "test": true,
39b1f752
AK
1760 "edition": "2015",
1761 "kind": [
1762 "lib"
1763 ],
58869e5c 1764 "name": "bar",
39b1f752
AK
1765 "src_path": "[..]"
1766 }
1767 ],
58869e5c 1768 "version": "0.1.0"
39b1f752
AK
1769 },
1770 {
1771 "authors": [],
1772 "categories": [],
f9a56257 1773 "default_run": null,
39b1f752
AK
1774 "dependencies": [],
1775 "description": null,
1776 "edition": "2015",
1777 "features": {},
58869e5c 1778 "id": "bar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
39b1f752
AK
1779 "keywords": [],
1780 "license": null,
1781 "license_file": null,
53de08a5 1782 "links": null,
39b1f752
AK
1783 "manifest_path": "[..]",
1784 "metadata": null,
7d41d454 1785 "publish": null,
39b1f752
AK
1786 "name": "bar",
1787 "readme": null,
1788 "repository": null,
390af271 1789 "rust_version": null,
72694e80 1790 "homepage": null,
1791 "documentation": null,
db1940b0 1792 "source": "registry+https://github.com/rust-lang/crates.io-index",
39b1f752
AK
1793 "targets": [
1794 {
1795 "crate_types": [
1796 "lib"
1797 ],
e831dd12 1798 "doc": true,
e1d433d3 1799 "doctest": true,
95b22d28 1800 "test": true,
39b1f752
AK
1801 "edition": "2015",
1802 "kind": [
1803 "lib"
1804 ],
1805 "name": "bar",
1806 "src_path": "[..]"
1807 }
1808 ],
58869e5c 1809 "version": "0.2.0"
39b1f752
AK
1810 },
1811 {
1812 "authors": [],
1813 "categories": [],
f9a56257 1814 "default_run": null,
58869e5c
AS
1815 "dependencies": [
1816 {
1817 "features": [],
1818 "kind": null,
1819 "name": "bar",
1820 "optional": false,
1821 "rename": null,
1822 "registry": null,
1823 "req": "^0.1.0",
1824 "source": "registry+https://github.com/rust-lang/crates.io-index",
1825 "target": null,
1826 "uses_default_features": true
1827 },
1828 {
1829 "features": [],
1830 "kind": null,
1831 "name": "bar",
1832 "optional": false,
1833 "rename": "baz",
1834 "registry": null,
1835 "req": "^0.2.0",
1836 "source": "registry+https://github.com/rust-lang/crates.io-index",
1837 "target": null,
1838 "uses_default_features": true
1839 }
1840 ],
39b1f752
AK
1841 "description": null,
1842 "edition": "2015",
1843 "features": {},
58869e5c 1844 "id": "foo 0.0.1[..]",
39b1f752
AK
1845 "keywords": [],
1846 "license": null,
1847 "license_file": null,
53de08a5 1848 "links": null,
39b1f752
AK
1849 "manifest_path": "[..]",
1850 "metadata": null,
7d41d454 1851 "publish": null,
58869e5c 1852 "name": "foo",
39b1f752
AK
1853 "readme": null,
1854 "repository": null,
390af271 1855 "rust_version": null,
72694e80 1856 "homepage": null,
1857 "documentation": null,
58869e5c 1858 "source": null,
39b1f752
AK
1859 "targets": [
1860 {
1861 "crate_types": [
1862 "lib"
1863 ],
e831dd12 1864 "doc": true,
e1d433d3 1865 "doctest": true,
95b22d28 1866 "test": true,
39b1f752
AK
1867 "edition": "2015",
1868 "kind": [
1869 "lib"
1870 ],
58869e5c 1871 "name": "foo",
39b1f752
AK
1872 "src_path": "[..]"
1873 }
1874 ],
58869e5c 1875 "version": "0.0.1"
39b1f752
AK
1876 }
1877 ],
1878 "resolve": {
1879 "nodes": [
1880 {
1881 "dependencies": [],
1882 "deps": [],
1883 "features": [],
58869e5c 1884 "id": "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)"
39b1f752
AK
1885 },
1886 {
1887 "dependencies": [],
1888 "deps": [],
1889 "features": [],
58869e5c 1890 "id": "bar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
39b1f752
AK
1891 },
1892 {
1893 "dependencies": [
db1940b0
LA
1894 "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1895 "bar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
39b1f752
AK
1896 ],
1897 "deps": [
1898 {
a7faecc3
EH
1899 "dep_kinds": [
1900 {
1901 "kind": null,
1902 "target": null
1903 }
1904 ],
39b1f752 1905 "name": "bar",
db1940b0 1906 "pkg": "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)"
39b1f752
AK
1907 },
1908 {
a7faecc3
EH
1909 "dep_kinds": [
1910 {
1911 "kind": null,
1912 "target": null
1913 }
1914 ],
39b1f752 1915 "name": "baz",
db1940b0 1916 "pkg": "bar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
39b1f752
AK
1917 }
1918 ],
1919 "features": [],
1920 "id": "foo 0.0.1[..]"
1921 }
1922 ],
1923 "root": "foo 0.0.1[..]"
1924 },
1925 "target_directory": "[..]",
1926 "version": 1,
1927 "workspace_members": [
1928 "foo 0.0.1[..]"
1929 ],
866d4316
BC
1930 "workspace_root": "[..]",
1931 "metadata": null
39b1f752 1932}"#,
fecb7246
AC
1933 )
1934 .run();
39b1f752 1935}
53de08a5 1936
0e0d9688 1937#[cargo_test]
53de08a5
EH
1938fn metadata_links() {
1939 let p = project()
1940 .file(
1941 "Cargo.toml",
1942 r#"
1943 [project]
1944 name = "foo"
1945 version = "0.5.0"
1946 links = "a"
1947 "#,
1948 )
1949 .file("src/lib.rs", "")
1950 .file("build.rs", "fn main() {}")
1951 .build();
1952
1953 p.cargo("metadata")
db09895f 1954 .with_json(
1955 r#"
6f8c7d5a
EH
1956 {
1957 "packages": [
1958 {
1959 "authors": [],
1960 "categories": [],
f9a56257 1961 "default_run": null,
6f8c7d5a
EH
1962 "dependencies": [],
1963 "description": null,
1964 "edition": "2015",
1965 "features": {},
1966 "id": "foo 0.5.0 [..]",
1967 "keywords": [],
1968 "license": null,
1969 "license_file": null,
1970 "links": "a",
1971 "manifest_path": "[..]/foo/Cargo.toml",
1972 "metadata": null,
1973 "publish": null,
1974 "name": "foo",
1975 "readme": null,
1976 "repository": null,
390af271 1977 "rust_version": null,
72694e80 1978 "homepage": null,
1979 "documentation": null,
6f8c7d5a
EH
1980 "source": null,
1981 "targets": [
1982 {
1983 "crate_types": [
1984 "lib"
1985 ],
e831dd12 1986 "doc": true,
6f8c7d5a
EH
1987 "doctest": true,
1988 "test": true,
1989 "edition": "2015",
1990 "kind": [
1991 "lib"
1992 ],
1993 "name": "foo",
1994 "src_path": "[..]/foo/src/lib.rs"
1995 },
1996 {
1997 "crate_types": [
1998 "bin"
1999 ],
e831dd12 2000 "doc": false,
6f8c7d5a
EH
2001 "doctest": false,
2002 "test": false,
2003 "edition": "2015",
2004 "kind": [
2005 "custom-build"
2006 ],
2007 "name": "build-script-build",
2008 "src_path": "[..]/foo/build.rs"
2009 }
2010 ],
2011 "version": "0.5.0"
2012 }
2013 ],
2014 "resolve": {
2015 "nodes": [
2016 {
2017 "dependencies": [],
2018 "deps": [],
2019 "features": [],
2020 "id": "foo 0.5.0 [..]"
2021 }
2022 ],
2023 "root": "foo 0.5.0 [..]"
2024 },
2025 "target_directory": "[..]/foo/target",
2026 "version": 1,
2027 "workspace_members": [
2028 "foo 0.5.0 [..]"
2029 ],
2030 "workspace_root": "[..]/foo",
2031 "metadata": null
2032 }
2033 "#,
db09895f 2034 )
53de08a5
EH
2035 .run()
2036}
c3f4b0db 2037
0e0d9688 2038#[cargo_test]
c3f4b0db
EH
2039fn deps_with_bin_only() {
2040 let p = project()
2041 .file(
2042 "Cargo.toml",
2043 r#"
6f8c7d5a
EH
2044 [package]
2045 name = "foo"
2046 version = "0.1.0"
2047 [dependencies]
2048 bdep = { path = "bdep" }
2049 "#,
c3f4b0db
EH
2050 )
2051 .file("src/lib.rs", "")
2052 .file("bdep/Cargo.toml", &basic_bin_manifest("bdep"))
2053 .file("bdep/src/main.rs", "fn main() {}")
2054 .build();
2055
d6b5a6bc
EH
2056 p.cargo("metadata")
2057 .with_json(
2058 r#"
6f8c7d5a
EH
2059 {
2060 "packages": [
2061 {
2062 "name": "foo",
2063 "version": "0.1.0",
2064 "id": "foo 0.1.0 ([..])",
2065 "license": null,
2066 "license_file": null,
c9714003 2067 "description": null,
6f8c7d5a
EH
2068 "source": null,
2069 "dependencies": [
2070 {
2071 "name": "bdep",
2072 "source": null,
2073 "req": "*",
2074 "kind": null,
2075 "rename": null,
2076 "optional": false,
2077 "uses_default_features": true,
fd25f936 2078 "path": "[..]/foo/bdep",
6f8c7d5a
EH
2079 "features": [],
2080 "target": null,
2081 "registry": null
2082 }
2083 ],
2084 "targets": [
2085 {
2086 "kind": [
2087 "lib"
2088 ],
2089 "crate_types": [
2090 "lib"
2091 ],
2092 "name": "foo",
2093 "src_path": "[..]/foo/src/lib.rs",
2094 "edition": "2015",
e831dd12 2095 "doc": true,
6f8c7d5a
EH
2096 "doctest": true,
2097 "test": true
2098 }
2099 ],
2100 "features": {},
2101 "manifest_path": "[..]/foo/Cargo.toml",
2102 "metadata": null,
2103 "publish": null,
2104 "authors": [],
2105 "categories": [],
f9a56257 2106 "default_run": null,
6f8c7d5a
EH
2107 "keywords": [],
2108 "readme": null,
2109 "repository": null,
390af271 2110 "rust_version": null,
72694e80 2111 "homepage": null,
2112 "documentation": null,
6f8c7d5a
EH
2113 "edition": "2015",
2114 "links": null
2115 }
2116 ],
2117 "workspace_members": [
2118 "foo 0.1.0 ([..])"
2119 ],
2120 "resolve": {
2121 "nodes": [
2122 {
2123 "id": "foo 0.1.0 ([..])",
2124 "dependencies": [],
2125 "deps": [],
2126 "features": []
2127 }
2128 ],
2129 "root": "foo 0.1.0 ([..])"
2130 },
2131 "target_directory": "[..]/foo/target",
2132 "version": 1,
2133 "workspace_root": "[..]foo",
2134 "metadata": null
2135 }
2136 "#,
d6b5a6bc
EH
2137 )
2138 .run();
c3f4b0db 2139}
5b521f65
EH
2140
2141#[cargo_test]
2142fn filter_platform() {
2143 // Testing the --filter-platform flag.
2144 Package::new("normal-dep", "0.0.1").publish();
2145 Package::new("host-dep", "0.0.1").publish();
2146 Package::new("alt-dep", "0.0.1").publish();
2147 Package::new("cfg-dep", "0.0.1").publish();
0a2f6913
EH
2148 // Just needs to be a valid target that is different from host.
2149 // Presumably nobody runs these tests on wasm. 🙃
2150 let alt_target = "wasm32-unknown-unknown";
95827ad3 2151 let host_target = rustc_host();
5b521f65
EH
2152 let p = project()
2153 .file(
2154 "Cargo.toml",
2155 &format!(
2156 r#"
d6b5a6bc
EH
2157 [package]
2158 name = "foo"
2159 version = "0.1.0"
5b521f65 2160
d6b5a6bc
EH
2161 [dependencies]
2162 normal-dep = "0.0.1"
5b521f65 2163
d6b5a6bc
EH
2164 [target.{}.dependencies]
2165 host-dep = "0.0.1"
5b521f65 2166
d6b5a6bc
EH
2167 [target.{}.dependencies]
2168 alt-dep = "0.0.1"
5b521f65 2169
d6b5a6bc
EH
2170 [target.'cfg(foobar)'.dependencies]
2171 cfg-dep = "0.0.1"
2172 "#,
95827ad3 2173 host_target, alt_target
5b521f65
EH
2174 ),
2175 )
2176 .file("src/lib.rs", "")
2177 .build();
2178
d6b5a6bc 2179 let alt_dep = r#"
5b521f65
EH
2180 {
2181 "name": "alt-dep",
2182 "version": "0.0.1",
2183 "id": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2184 "license": null,
2185 "license_file": null,
2186 "description": null,
2187 "source": "registry+https://github.com/rust-lang/crates.io-index",
2188 "dependencies": [],
2189 "targets": [
2190 {
2191 "kind": [
2192 "lib"
2193 ],
2194 "crate_types": [
2195 "lib"
2196 ],
2197 "name": "alt-dep",
2198 "src_path": "[..]/alt-dep-0.0.1/src/lib.rs",
2199 "edition": "2015",
95b22d28 2200 "test": true,
e831dd12 2201 "doc": true,
5b521f65
EH
2202 "doctest": true
2203 }
2204 ],
2205 "features": {},
2206 "manifest_path": "[..]/alt-dep-0.0.1/Cargo.toml",
2207 "metadata": null,
2208 "publish": null,
2209 "authors": [],
2210 "categories": [],
f9a56257 2211 "default_run": null,
5b521f65
EH
2212 "keywords": [],
2213 "readme": null,
2214 "repository": null,
390af271 2215 "rust_version": null,
72694e80 2216 "homepage": null,
2217 "documentation": null,
5b521f65
EH
2218 "edition": "2015",
2219 "links": null
58869e5c 2220 }
d6b5a6bc
EH
2221 "#;
2222
2223 let cfg_dep = r#"
5b521f65
EH
2224 {
2225 "name": "cfg-dep",
2226 "version": "0.0.1",
2227 "id": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2228 "license": null,
2229 "license_file": null,
2230 "description": null,
2231 "source": "registry+https://github.com/rust-lang/crates.io-index",
2232 "dependencies": [],
2233 "targets": [
2234 {
2235 "kind": [
2236 "lib"
2237 ],
2238 "crate_types": [
2239 "lib"
2240 ],
2241 "name": "cfg-dep",
2242 "src_path": "[..]/cfg-dep-0.0.1/src/lib.rs",
2243 "edition": "2015",
95b22d28 2244 "test": true,
e831dd12 2245 "doc": true,
5b521f65
EH
2246 "doctest": true
2247 }
2248 ],
2249 "features": {},
2250 "manifest_path": "[..]/cfg-dep-0.0.1/Cargo.toml",
2251 "metadata": null,
2252 "publish": null,
2253 "authors": [],
2254 "categories": [],
f9a56257 2255 "default_run": null,
5b521f65
EH
2256 "keywords": [],
2257 "readme": null,
2258 "repository": null,
390af271 2259 "rust_version": null,
72694e80 2260 "homepage": null,
2261 "documentation": null,
5b521f65
EH
2262 "edition": "2015",
2263 "links": null
58869e5c 2264 }
d6b5a6bc
EH
2265 "#;
2266
2267 let host_dep = r#"
5b521f65
EH
2268 {
2269 "name": "host-dep",
2270 "version": "0.0.1",
2271 "id": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2272 "license": null,
2273 "license_file": null,
2274 "description": null,
2275 "source": "registry+https://github.com/rust-lang/crates.io-index",
2276 "dependencies": [],
2277 "targets": [
2278 {
2279 "kind": [
2280 "lib"
2281 ],
2282 "crate_types": [
2283 "lib"
2284 ],
2285 "name": "host-dep",
2286 "src_path": "[..]/host-dep-0.0.1/src/lib.rs",
2287 "edition": "2015",
95b22d28 2288 "test": true,
e831dd12 2289 "doc": true,
5b521f65
EH
2290 "doctest": true
2291 }
2292 ],
2293 "features": {},
2294 "manifest_path": "[..]/host-dep-0.0.1/Cargo.toml",
2295 "metadata": null,
2296 "publish": null,
2297 "authors": [],
2298 "categories": [],
f9a56257 2299 "default_run": null,
5b521f65
EH
2300 "keywords": [],
2301 "readme": null,
2302 "repository": null,
390af271 2303 "rust_version": null,
72694e80 2304 "homepage": null,
2305 "documentation": null,
5b521f65
EH
2306 "edition": "2015",
2307 "links": null
58869e5c 2308 }
d6b5a6bc
EH
2309 "#;
2310
2311 let normal_dep = r#"
5b521f65
EH
2312 {
2313 "name": "normal-dep",
2314 "version": "0.0.1",
2315 "id": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2316 "license": null,
2317 "license_file": null,
2318 "description": null,
2319 "source": "registry+https://github.com/rust-lang/crates.io-index",
2320 "dependencies": [],
2321 "targets": [
2322 {
2323 "kind": [
2324 "lib"
2325 ],
2326 "crate_types": [
2327 "lib"
2328 ],
2329 "name": "normal-dep",
2330 "src_path": "[..]/normal-dep-0.0.1/src/lib.rs",
2331 "edition": "2015",
95b22d28 2332 "test": true,
e831dd12 2333 "doc": true,
5b521f65
EH
2334 "doctest": true
2335 }
2336 ],
2337 "features": {},
2338 "manifest_path": "[..]/normal-dep-0.0.1/Cargo.toml",
2339 "metadata": null,
2340 "publish": null,
2341 "authors": [],
2342 "categories": [],
f9a56257 2343 "default_run": null,
5b521f65
EH
2344 "keywords": [],
2345 "readme": null,
2346 "repository": null,
390af271 2347 "rust_version": null,
72694e80 2348 "homepage": null,
2349 "documentation": null,
5b521f65
EH
2350 "edition": "2015",
2351 "links": null
58869e5c 2352 }
d6b5a6bc
EH
2353 "#;
2354
95827ad3
EH
2355 // The dependencies are stored in sorted order by target and then by name.
2356 // Since the testsuite may run on different targets, this needs to be
2357 // sorted before it can be compared.
2358 let mut foo_deps = serde_json::json!([
5b521f65
EH
2359 {
2360 "name": "normal-dep",
2361 "source": "registry+https://github.com/rust-lang/crates.io-index",
2362 "req": "^0.0.1",
2363 "kind": null,
2364 "rename": null,
2365 "optional": false,
2366 "uses_default_features": true,
2367 "features": [],
2368 "target": null,
2369 "registry": null
2370 },
2371 {
2372 "name": "cfg-dep",
2373 "source": "registry+https://github.com/rust-lang/crates.io-index",
2374 "req": "^0.0.1",
2375 "kind": null,
2376 "rename": null,
2377 "optional": false,
2378 "uses_default_features": true,
2379 "features": [],
2380 "target": "cfg(foobar)",
2381 "registry": null
2382 },
2383 {
2384 "name": "alt-dep",
2385 "source": "registry+https://github.com/rust-lang/crates.io-index",
2386 "req": "^0.0.1",
2387 "kind": null,
2388 "rename": null,
2389 "optional": false,
2390 "uses_default_features": true,
2391 "features": [],
95827ad3 2392 "target": alt_target,
5b521f65
EH
2393 "registry": null
2394 },
2395 {
2396 "name": "host-dep",
2397 "source": "registry+https://github.com/rust-lang/crates.io-index",
2398 "req": "^0.0.1",
2399 "kind": null,
2400 "rename": null,
2401 "optional": false,
2402 "uses_default_features": true,
2403 "features": [],
95827ad3 2404 "target": host_target,
5b521f65
EH
2405 "registry": null
2406 }
95827ad3
EH
2407 ]);
2408 foo_deps.as_array_mut().unwrap().sort_by(|a, b| {
2409 // This really should be `rename`, but not needed here.
2410 // Also, sorting on `name` isn't really necessary since this test
2411 // only has one package per target, but leaving it here to be safe.
2412 let a = (a["target"].as_str(), a["name"].as_str());
2413 let b = (b["target"].as_str(), b["name"].as_str());
2414 a.cmp(&b)
2415 });
2416
2417 let foo = r#"
2418 {
2419 "name": "foo",
2420 "version": "0.1.0",
2421 "id": "foo 0.1.0 (path+file:[..]foo)",
2422 "license": null,
2423 "license_file": null,
2424 "description": null,
2425 "source": null,
2426 "dependencies":
2427 $FOO_DEPS,
5b521f65
EH
2428 "targets": [
2429 {
2430 "kind": [
2431 "lib"
2432 ],
2433 "crate_types": [
2434 "lib"
2435 ],
2436 "name": "foo",
2437 "src_path": "[..]/foo/src/lib.rs",
2438 "edition": "2015",
95b22d28 2439 "test": true,
e831dd12 2440 "doc": true,
5b521f65
EH
2441 "doctest": true
2442 }
2443 ],
2444 "features": {},
2445 "manifest_path": "[..]/foo/Cargo.toml",
2446 "metadata": null,
2447 "publish": null,
2448 "authors": [],
2449 "categories": [],
f9a56257 2450 "default_run": null,
5b521f65
EH
2451 "keywords": [],
2452 "readme": null,
2453 "repository": null,
390af271 2454 "rust_version": null,
72694e80 2455 "homepage": null,
2456 "documentation": null,
5b521f65
EH
2457 "edition": "2015",
2458 "links": null
2459 }
d6b5a6bc 2460 "#
0a2f6913 2461 .replace("$ALT_TRIPLE", alt_target)
1b7fa21f 2462 .replace("$HOST_TRIPLE", host_target)
95827ad3 2463 .replace("$FOO_DEPS", &foo_deps.to_string());
d6b5a6bc 2464
ee286bce
JG
2465 // We're going to be checking that we don't download excessively,
2466 // so we need to ensure that downloads will happen.
2467 let clear = || {
2468 cargo_home().join("registry/cache").rm_rf();
2469 cargo_home().join("registry/src").rm_rf();
2470 p.build_dir().rm_rf();
2471 };
2472
d6b5a6bc
EH
2473 // Normal metadata, no filtering, returns *everything*.
2474 p.cargo("metadata")
ee286bce
JG
2475 .with_stderr_unordered(
2476 "\
2477[UPDATING] [..]
2478[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
2479[DOWNLOADING] crates ...
2480[DOWNLOADED] normal-dep v0.0.1 [..]
2481[DOWNLOADED] host-dep v0.0.1 [..]
2482[DOWNLOADED] alt-dep v0.0.1 [..]
2483[DOWNLOADED] cfg-dep v0.0.1 [..]
2484",
2485 )
d6b5a6bc
EH
2486 .with_json(
2487 &r#"
2488{
2489 "packages": [
58869e5c
AS
2490 $ALT_DEP,
2491 $CFG_DEP,
2492 $FOO,
2493 $HOST_DEP,
d6b5a6bc 2494 $NORMAL_DEP
5b521f65
EH
2495 ],
2496 "workspace_members": [
2497 "foo 0.1.0 (path+file:[..]foo)"
2498 ],
2499 "resolve": {
2500 "nodes": [
2501 {
2502 "id": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2503 "dependencies": [],
2504 "deps": [],
2505 "features": []
2506 },
2507 {
2508 "id": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2509 "dependencies": [],
2510 "deps": [],
2511 "features": []
2512 },
2513 {
2514 "id": "foo 0.1.0 (path+file:[..]foo)",
2515 "dependencies": [
2516 "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2517 "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2518 "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2519 "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
2520 ],
2521 "deps": [
2522 {
2523 "name": "alt_dep",
a7faecc3
EH
2524 "pkg": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2525 "dep_kinds": [
2526 {
2527 "kind": null,
2528 "target": "$ALT_TRIPLE"
2529 }
2530 ]
5b521f65
EH
2531 },
2532 {
2533 "name": "cfg_dep",
a7faecc3
EH
2534 "pkg": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2535 "dep_kinds": [
2536 {
2537 "kind": null,
2538 "target": "cfg(foobar)"
2539 }
2540 ]
5b521f65
EH
2541 },
2542 {
2543 "name": "host_dep",
a7faecc3
EH
2544 "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2545 "dep_kinds": [
2546 {
2547 "kind": null,
2548 "target": "$HOST_TRIPLE"
2549 }
2550 ]
5b521f65
EH
2551 },
2552 {
2553 "name": "normal_dep",
a7faecc3
EH
2554 "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2555 "dep_kinds": [
2556 {
2557 "kind": null,
2558 "target": null
2559 }
2560 ]
5b521f65
EH
2561 }
2562 ],
2563 "features": []
2564 },
2565 {
2566 "id": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2567 "dependencies": [],
2568 "deps": [],
2569 "features": []
2570 },
2571 {
2572 "id": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2573 "dependencies": [],
2574 "deps": [],
2575 "features": []
2576 }
2577 ],
2578 "root": "foo 0.1.0 (path+file:[..]foo)"
2579 },
2580 "target_directory": "[..]/foo/target",
2581 "version": 1,
866d4316
BC
2582 "workspace_root": "[..]/foo",
2583 "metadata": null
5b521f65
EH
2584}
2585"#
0a2f6913 2586 .replace("$ALT_TRIPLE", alt_target)
1b7fa21f 2587 .replace("$HOST_TRIPLE", host_target)
d6b5a6bc
EH
2588 .replace("$ALT_DEP", alt_dep)
2589 .replace("$CFG_DEP", cfg_dep)
2590 .replace("$HOST_DEP", host_dep)
2591 .replace("$NORMAL_DEP", normal_dep)
2592 .replace("$FOO", &foo),
5b521f65
EH
2593 )
2594 .run();
ee286bce 2595 clear();
5b521f65 2596
d6b5a6bc 2597 // Filter on alternate, removes cfg and host.
5b521f65 2598 p.cargo("metadata --filter-platform")
0a2f6913 2599 .arg(alt_target)
ee286bce
JG
2600 .with_stderr_unordered(
2601 "\
2602[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
2603[DOWNLOADING] crates ...
2604[DOWNLOADED] normal-dep v0.0.1 [..]
2605[DOWNLOADED] host-dep v0.0.1 [..]
2606[DOWNLOADED] alt-dep v0.0.1 [..]
2607",
2608 )
5b521f65 2609 .with_json(
d6b5a6bc 2610 &r#"
5b521f65 2611{
d6b5a6bc 2612 "packages": [
58869e5c
AS
2613 $ALT_DEP,
2614 $FOO,
d6b5a6bc 2615 $NORMAL_DEP
d6b5a6bc 2616 ],
5b521f65
EH
2617 "workspace_members": "{...}",
2618 "resolve": {
2619 "nodes": [
2620 {
2621 "id": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2622 "dependencies": [],
2623 "deps": [],
2624 "features": []
2625 },
5b521f65
EH
2626 {
2627 "id": "foo 0.1.0 (path+file:[..]foo)",
2628 "dependencies": [
2629 "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2630 "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
2631 ],
2632 "deps": [
2633 {
2634 "name": "alt_dep",
a7faecc3
EH
2635 "pkg": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2636 "dep_kinds": [
2637 {
2638 "kind": null,
2639 "target": "$ALT_TRIPLE"
2640 }
2641 ]
5b521f65
EH
2642 },
2643 {
2644 "name": "normal_dep",
a7faecc3
EH
2645 "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2646 "dep_kinds": [
2647 {
2648 "kind": null,
2649 "target": null
2650 }
2651 ]
5b521f65
EH
2652 }
2653 ],
2654 "features": []
2655 },
5b521f65
EH
2656 {
2657 "id": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2658 "dependencies": [],
2659 "deps": [],
2660 "features": []
2661 }
2662 ],
2663 "root": "foo 0.1.0 (path+file:[..]foo)"
2664 },
2665 "target_directory": "[..]foo/target",
2666 "version": 1,
866d4316
BC
2667 "workspace_root": "[..]foo",
2668 "metadata": null
5b521f65 2669}
d6b5a6bc 2670"#
0a2f6913 2671 .replace("$ALT_TRIPLE", alt_target)
d6b5a6bc
EH
2672 .replace("$ALT_DEP", alt_dep)
2673 .replace("$NORMAL_DEP", normal_dep)
2674 .replace("$FOO", &foo),
5b521f65
EH
2675 )
2676 .run();
ee286bce 2677 clear();
5b521f65 2678
d6b5a6bc
EH
2679 // Filter on host, removes alt and cfg.
2680 p.cargo("metadata --filter-platform")
95827ad3 2681 .arg(&host_target)
ee286bce
JG
2682 .with_stderr_unordered(
2683 "\
2684[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
2685[DOWNLOADING] crates ...
2686[DOWNLOADED] normal-dep v0.0.1 [..]
2687[DOWNLOADED] host-dep v0.0.1 [..]
2688",
2689 )
d6b5a6bc
EH
2690 .with_json(
2691 &r#"
5b521f65 2692{
d6b5a6bc 2693 "packages": [
58869e5c
AS
2694 $FOO,
2695 $HOST_DEP,
d6b5a6bc 2696 $NORMAL_DEP
d6b5a6bc 2697 ],
5b521f65
EH
2698 "workspace_members": "{...}",
2699 "resolve": {
2700 "nodes": [
5b521f65
EH
2701 {
2702 "id": "foo 0.1.0 (path+file:[..]foo)",
2703 "dependencies": [
2704 "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2705 "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
2706 ],
2707 "deps": [
2708 {
2709 "name": "host_dep",
a7faecc3
EH
2710 "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2711 "dep_kinds": [
2712 {
2713 "kind": null,
2714 "target": "$HOST_TRIPLE"
2715 }
2716 ]
5b521f65
EH
2717 },
2718 {
2719 "name": "normal_dep",
a7faecc3
EH
2720 "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2721 "dep_kinds": [
2722 {
2723 "kind": null,
2724 "target": null
2725 }
2726 ]
5b521f65
EH
2727 }
2728 ],
2729 "features": []
2730 },
2731 {
2732 "id": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2733 "dependencies": [],
2734 "deps": [],
2735 "features": []
2736 },
2737 {
2738 "id": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2739 "dependencies": [],
2740 "deps": [],
2741 "features": []
2742 }
2743 ],
2744 "root": "foo 0.1.0 (path+file:[..]foo)"
2745 },
2746 "target_directory": "[..]foo/target",
2747 "version": 1,
866d4316
BC
2748 "workspace_root": "[..]foo",
2749 "metadata": null
5b521f65 2750}
d6b5a6bc 2751"#
1b7fa21f 2752 .replace("$HOST_TRIPLE", host_target)
d6b5a6bc
EH
2753 .replace("$HOST_DEP", host_dep)
2754 .replace("$NORMAL_DEP", normal_dep)
2755 .replace("$FOO", &foo),
2756 )
5b521f65 2757 .run();
ee286bce 2758 clear();
d6b5a6bc
EH
2759
2760 // Filter host with cfg, removes alt only
5b521f65 2761 p.cargo("metadata --filter-platform")
95827ad3 2762 .arg(&host_target)
5b521f65 2763 .env("RUSTFLAGS", "--cfg=foobar")
ee286bce
JG
2764 .with_stderr_unordered(
2765 "\
2766[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
2767[DOWNLOADING] crates ...
2768[DOWNLOADED] normal-dep v0.0.1 [..]
2769[DOWNLOADED] host-dep v0.0.1 [..]
2770[DOWNLOADED] cfg-dep v0.0.1 [..]
2771",
2772 )
5b521f65 2773 .with_json(
d6b5a6bc 2774 &r#"
5b521f65 2775{
d6b5a6bc 2776 "packages": [
58869e5c
AS
2777 $CFG_DEP,
2778 $FOO,
2779 $HOST_DEP,
d6b5a6bc 2780 $NORMAL_DEP
d6b5a6bc 2781 ],
5b521f65
EH
2782 "workspace_members": "{...}",
2783 "resolve": {
2784 "nodes": [
5b521f65
EH
2785 {
2786 "id": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2787 "dependencies": [],
2788 "deps": [],
2789 "features": []
2790 },
2791 {
2792 "id": "foo 0.1.0 (path+file:[..]/foo)",
2793 "dependencies": [
2794 "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2795 "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2796 "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
2797 ],
2798 "deps": [
2799 {
2800 "name": "cfg_dep",
a7faecc3
EH
2801 "pkg": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2802 "dep_kinds": [
2803 {
2804 "kind": null,
2805 "target": "cfg(foobar)"
2806 }
2807 ]
5b521f65
EH
2808 },
2809 {
2810 "name": "host_dep",
a7faecc3
EH
2811 "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2812 "dep_kinds": [
2813 {
2814 "kind": null,
2815 "target": "$HOST_TRIPLE"
2816 }
2817 ]
5b521f65
EH
2818 },
2819 {
2820 "name": "normal_dep",
a7faecc3
EH
2821 "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2822 "dep_kinds": [
2823 {
2824 "kind": null,
2825 "target": null
2826 }
2827 ]
5b521f65
EH
2828 }
2829 ],
2830 "features": []
2831 },
2832 {
2833 "id": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2834 "dependencies": [],
2835 "deps": [],
2836 "features": []
2837 },
2838 {
2839 "id": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2840 "dependencies": [],
2841 "deps": [],
2842 "features": []
2843 }
2844 ],
2845 "root": "foo 0.1.0 (path+file:[..]/foo)"
2846 },
2847 "target_directory": "[..]/foo/target",
2848 "version": 1,
866d4316
BC
2849 "workspace_root": "[..]/foo",
2850 "metadata": null
5b521f65 2851}
d6b5a6bc 2852"#
1b7fa21f 2853 .replace("$HOST_TRIPLE", host_target)
d6b5a6bc
EH
2854 .replace("$CFG_DEP", cfg_dep)
2855 .replace("$HOST_DEP", host_dep)
2856 .replace("$NORMAL_DEP", normal_dep)
2857 .replace("$FOO", &foo),
5b521f65
EH
2858 )
2859 .run();
2860}
a7faecc3
EH
2861
2862#[cargo_test]
2863fn dep_kinds() {
2864 Package::new("bar", "0.1.0").publish();
2865 Package::new("winapi", "0.1.0").publish();
2866
2867 let p = project()
2868 .file(
2869 "Cargo.toml",
2870 r#"
2871 [package]
2872 name = "foo"
2873 version = "0.1.0"
2874
2875 [dependencies]
2876 bar = "0.1"
2877
2878 [dev-dependencies]
2879 bar = "0.1"
2880
2881 [build-dependencies]
2882 bar = "0.1"
2883
2884 [target.'cfg(windows)'.dependencies]
2885 winapi = "0.1"
2886 "#,
2887 )
2888 .file("src/lib.rs", "")
2889 .build();
2890
2891 p.cargo("metadata")
2892 .with_json(
2893 r#"
6f8c7d5a
EH
2894 {
2895 "packages": "{...}",
2896 "workspace_members": "{...}",
2897 "target_directory": "{...}",
2898 "version": 1,
2899 "workspace_root": "{...}",
2900 "metadata": null,
2901 "resolve": {
2902 "nodes": [
2903 {
2904 "id": "bar 0.1.0 [..]",
2905 "dependencies": [],
2906 "deps": [],
2907 "features": []
2908 },
2909 {
2910 "id": "foo 0.1.0 [..]",
2911 "dependencies": [
2912 "bar 0.1.0 [..]",
2913 "winapi 0.1.0 [..]"
2914 ],
2915 "deps": [
2916 {
2917 "name": "bar",
2918 "pkg": "bar 0.1.0 [..]",
2919 "dep_kinds": [
2920 {
2921 "kind": null,
2922 "target": null
2923 },
2924 {
2925 "kind": "dev",
2926 "target": null
2927 },
2928 {
2929 "kind": "build",
2930 "target": null
2931 }
2932 ]
2933 },
2934 {
2935 "name": "winapi",
2936 "pkg": "winapi 0.1.0 [..]",
2937 "dep_kinds": [
2938 {
2939 "kind": null,
2940 "target": "cfg(windows)"
2941 }
2942 ]
2943 }
2944 ],
2945 "features": []
2946 },
2947 {
2948 "id": "winapi 0.1.0 [..]",
2949 "dependencies": [],
2950 "deps": [],
2951 "features": []
2952 }
2953 ],
2954 "root": "foo 0.1.0 [..]"
a7faecc3 2955 }
6f8c7d5a
EH
2956 }
2957 "#,
a7faecc3
EH
2958 )
2959 .run();
2960}
7acf376d
EH
2961
2962#[cargo_test]
2963fn dep_kinds_workspace() {
2964 // Check for bug with duplicate dep kinds in a workspace.
2965 // If different members select different features for the same package,
2966 // they show up multiple times in the resolver `deps`.
2967 //
2968 // Here:
2969 // foo -> dep
2970 // bar -> foo[feat1] -> dep
2971 let p = project()
2972 .file(
2973 "Cargo.toml",
2974 r#"
6f8c7d5a
EH
2975 [package]
2976 name = "foo"
2977 version = "0.1.0"
7acf376d 2978
6f8c7d5a
EH
2979 [features]
2980 feat1 = []
7acf376d 2981
6f8c7d5a
EH
2982 [dependencies]
2983 dep = { path="dep" }
7acf376d 2984
6f8c7d5a
EH
2985 [workspace]
2986 members = ["bar"]
2987 "#,
7acf376d
EH
2988 )
2989 .file("src/lib.rs", "")
2990 .file(
2991 "bar/Cargo.toml",
2992 r#"
2993 [package]
2994 name = "bar"
2995 version = "0.1.0"
2996
2997 [dependencies]
2998 foo = { path="..", features=["feat1"] }
2999 "#,
3000 )
3001 .file("bar/src/lib.rs", "")
3002 .file("dep/Cargo.toml", &basic_lib_manifest("dep"))
3003 .file("dep/src/lib.rs", "")
3004 .build();
3005
3006 p.cargo("metadata")
3007 .with_json(
3008 r#"
6f8c7d5a
EH
3009 {
3010 "packages": "{...}",
3011 "workspace_members": "{...}",
3012 "target_directory": "[..]/foo/target",
3013 "version": 1,
3014 "workspace_root": "[..]/foo",
3015 "metadata": null,
3016 "resolve": {
3017 "nodes": [
3018 {
3019 "id": "bar 0.1.0 (path+file://[..]/foo/bar)",
3020 "dependencies": [
3021 "foo 0.1.0 (path+file://[..]/foo)"
3022 ],
3023 "deps": [
3024 {
3025 "name": "foo",
3026 "pkg": "foo 0.1.0 (path+file://[..]/foo)",
3027 "dep_kinds": [
3028 {
3029 "kind": null,
3030 "target": null
3031 }
3032 ]
3033 }
3034 ],
3035 "features": []
3036 },
3037 {
3038 "id": "dep 0.5.0 (path+file://[..]/foo/dep)",
3039 "dependencies": [],
3040 "deps": [],
3041 "features": []
3042 },
3043 {
3044 "id": "foo 0.1.0 (path+file://[..]/foo)",
3045 "dependencies": [
3046 "dep 0.5.0 (path+file://[..]/foo/dep)"
3047 ],
3048 "deps": [
3049 {
3050 "name": "dep",
3051 "pkg": "dep 0.5.0 (path+file://[..]/foo/dep)",
3052 "dep_kinds": [
3053 {
3054 "kind": null,
3055 "target": null
3056 }
3057 ]
3058 }
3059 ],
3060 "features": [
3061 "feat1"
3062 ]
3063 }
3064 ],
3065 "root": "foo 0.1.0 (path+file://[..]/foo)"
7acf376d 3066 }
6f8c7d5a
EH
3067 }
3068 "#,
7acf376d
EH
3069 )
3070 .run();
3071}
dd5806d1
AK
3072
3073// Creating non-utf8 path is an OS-specific pain, so let's run this only on
3074// linux, where arbitrary bytes work.
3075#[cfg(target_os = "linux")]
3076#[cargo_test]
3077fn cargo_metadata_non_utf8() {
3078 use std::ffi::OsString;
3079 use std::os::unix::ffi::OsStringExt;
3080 use std::path::PathBuf;
3081
3082 let base = PathBuf::from(OsString::from_vec(vec![255]));
3083
3084 let p = project()
3085 .no_manifest()
3086 .file(base.join("./src/lib.rs"), "")
3087 .file(base.join("./Cargo.toml"), &basic_lib_manifest("foo"))
3088 .build();
3089
3090 p.cargo("metadata")
3091 .cwd(p.root().join(base))
3092 .arg("--format-version")
3093 .arg("1")
3094 .with_stderr("error: path contains invalid UTF-8 characters")
3095 .with_status(101)
3096 .run();
3097}