/tests/testsuite/metadata.rs

https://gitlab.com/frewsxcv/cargo · Rust · 1533 lines · 1502 code · 30 blank · 1 comment · 0 complexity · 54dbe2b6f42c3077e82ffddb847d2570 MD5 · raw file

  1. //! Tests for the `cargo metadata` command.
  2. use cargo_test_support::install::cargo_home;
  3. use cargo_test_support::paths::CargoPathExt;
  4. use cargo_test_support::registry::Package;
  5. use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, main_file, project, rustc_host};
  6. use serde_json::json;
  7. #[cargo_test]
  8. fn cargo_metadata_simple() {
  9. let p = project()
  10. .file("src/foo.rs", "")
  11. .file("Cargo.toml", &basic_bin_manifest("foo"))
  12. .build();
  13. p.cargo("metadata")
  14. .with_json(
  15. r#"
  16. {
  17. "packages": [
  18. {
  19. "authors": [
  20. "wycats@example.com"
  21. ],
  22. "categories": [],
  23. "default_run": null,
  24. "name": "foo",
  25. "version": "0.5.0",
  26. "id": "foo[..]",
  27. "keywords": [],
  28. "source": null,
  29. "dependencies": [],
  30. "edition": "2015",
  31. "license": null,
  32. "license_file": null,
  33. "links": null,
  34. "description": null,
  35. "readme": null,
  36. "repository": null,
  37. "rust_version": null,
  38. "homepage": null,
  39. "documentation": null,
  40. "homepage": null,
  41. "documentation": null,
  42. "targets": [
  43. {
  44. "kind": [
  45. "bin"
  46. ],
  47. "crate_types": [
  48. "bin"
  49. ],
  50. "doc": true,
  51. "doctest": false,
  52. "test": true,
  53. "edition": "2015",
  54. "name": "foo",
  55. "src_path": "[..]/foo/src/foo.rs"
  56. }
  57. ],
  58. "features": {},
  59. "manifest_path": "[..]Cargo.toml",
  60. "metadata": null,
  61. "publish": null
  62. }
  63. ],
  64. "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
  65. "resolve": {
  66. "nodes": [
  67. {
  68. "dependencies": [],
  69. "deps": [],
  70. "features": [],
  71. "id": "foo 0.5.0 (path+file:[..]foo)"
  72. }
  73. ],
  74. "root": "foo 0.5.0 (path+file:[..]foo)"
  75. },
  76. "target_directory": "[..]foo/target",
  77. "version": 1,
  78. "workspace_root": "[..]/foo",
  79. "metadata": null
  80. }"#,
  81. )
  82. .run();
  83. }
  84. #[cargo_test]
  85. fn cargo_metadata_warns_on_implicit_version() {
  86. let p = project()
  87. .file("src/foo.rs", "")
  88. .file("Cargo.toml", &basic_bin_manifest("foo"))
  89. .build();
  90. p.cargo("metadata").with_stderr("[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems").run();
  91. p.cargo("metadata --format-version 1").with_stderr("").run();
  92. }
  93. #[cargo_test]
  94. fn library_with_several_crate_types() {
  95. let p = project()
  96. .file("src/lib.rs", "")
  97. .file(
  98. "Cargo.toml",
  99. r#"
  100. [package]
  101. name = "foo"
  102. version = "0.5.0"
  103. [lib]
  104. crate-type = ["lib", "staticlib"]
  105. "#,
  106. )
  107. .build();
  108. p.cargo("metadata")
  109. .with_json(
  110. r#"
  111. {
  112. "packages": [
  113. {
  114. "authors": [],
  115. "categories": [],
  116. "default_run": null,
  117. "name": "foo",
  118. "readme": null,
  119. "repository": null,
  120. "homepage": null,
  121. "documentation": null,
  122. "version": "0.5.0",
  123. "rust_version": null,
  124. "id": "foo[..]",
  125. "keywords": [],
  126. "source": null,
  127. "dependencies": [],
  128. "edition": "2015",
  129. "license": null,
  130. "license_file": null,
  131. "links": null,
  132. "description": null,
  133. "targets": [
  134. {
  135. "kind": [
  136. "lib",
  137. "staticlib"
  138. ],
  139. "crate_types": [
  140. "lib",
  141. "staticlib"
  142. ],
  143. "doc": true,
  144. "doctest": true,
  145. "test": true,
  146. "edition": "2015",
  147. "name": "foo",
  148. "src_path": "[..]/foo/src/lib.rs"
  149. }
  150. ],
  151. "features": {},
  152. "manifest_path": "[..]Cargo.toml",
  153. "metadata": null,
  154. "publish": null
  155. }
  156. ],
  157. "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
  158. "resolve": {
  159. "nodes": [
  160. {
  161. "dependencies": [],
  162. "deps": [],
  163. "features": [],
  164. "id": "foo 0.5.0 (path+file:[..]foo)"
  165. }
  166. ],
  167. "root": "foo 0.5.0 (path+file:[..]foo)"
  168. },
  169. "target_directory": "[..]foo/target",
  170. "version": 1,
  171. "workspace_root": "[..]/foo",
  172. "metadata": null
  173. }"#,
  174. )
  175. .run();
  176. }
  177. #[cargo_test]
  178. fn library_with_features() {
  179. let p = project()
  180. .file("src/lib.rs", "")
  181. .file(
  182. "Cargo.toml",
  183. r#"
  184. [package]
  185. name = "foo"
  186. version = "0.5.0"
  187. [features]
  188. default = ["default_feat"]
  189. default_feat = []
  190. optional_feat = []
  191. "#,
  192. )
  193. .build();
  194. p.cargo("metadata")
  195. .with_json(
  196. r#"
  197. {
  198. "packages": [
  199. {
  200. "authors": [],
  201. "categories": [],
  202. "default_run": null,
  203. "name": "foo",
  204. "readme": null,
  205. "repository": null,
  206. "rust_version": null,
  207. "homepage": null,
  208. "documentation": null,
  209. "version": "0.5.0",
  210. "id": "foo[..]",
  211. "keywords": [],
  212. "source": null,
  213. "dependencies": [],
  214. "edition": "2015",
  215. "license": null,
  216. "license_file": null,
  217. "links": null,
  218. "description": null,
  219. "targets": [
  220. {
  221. "kind": [
  222. "lib"
  223. ],
  224. "crate_types": [
  225. "lib"
  226. ],
  227. "doc": true,
  228. "doctest": true,
  229. "test": true,
  230. "edition": "2015",
  231. "name": "foo",
  232. "src_path": "[..]/foo/src/lib.rs"
  233. }
  234. ],
  235. "features": {
  236. "default": [
  237. "default_feat"
  238. ],
  239. "default_feat": [],
  240. "optional_feat": []
  241. },
  242. "manifest_path": "[..]Cargo.toml",
  243. "metadata": null,
  244. "publish": null
  245. }
  246. ],
  247. "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
  248. "resolve": {
  249. "nodes": [
  250. {
  251. "dependencies": [],
  252. "deps": [],
  253. "features": [
  254. "default",
  255. "default_feat"
  256. ],
  257. "id": "foo 0.5.0 (path+file:[..]foo)"
  258. }
  259. ],
  260. "root": "foo 0.5.0 (path+file:[..]foo)"
  261. },
  262. "target_directory": "[..]foo/target",
  263. "version": 1,
  264. "workspace_root": "[..]/foo",
  265. "metadata": null
  266. }"#,
  267. )
  268. .run();
  269. }
  270. #[cargo_test]
  271. fn cargo_metadata_with_deps_and_version() {
  272. let p = project()
  273. .file("src/foo.rs", "")
  274. .file(
  275. "Cargo.toml",
  276. r#"
  277. [project]
  278. name = "foo"
  279. version = "0.5.0"
  280. authors = []
  281. license = "MIT"
  282. description = "foo"
  283. [[bin]]
  284. name = "foo"
  285. [dependencies]
  286. bar = "*"
  287. [dev-dependencies]
  288. foobar = "*"
  289. "#,
  290. )
  291. .build();
  292. Package::new("baz", "0.0.1").publish();
  293. Package::new("foobar", "0.0.1").publish();
  294. Package::new("bar", "0.0.1").dep("baz", "0.0.1").publish();
  295. p.cargo("metadata -q --format-version 1")
  296. .with_json(
  297. r#"
  298. {
  299. "packages": [
  300. {
  301. "authors": [],
  302. "categories": [],
  303. "default_run": null,
  304. "dependencies": [
  305. {
  306. "features": [],
  307. "kind": null,
  308. "name": "baz",
  309. "optional": false,
  310. "registry": null,
  311. "rename": null,
  312. "req": "^0.0.1",
  313. "source": "registry+https://github.com/rust-lang/crates.io-index",
  314. "target": null,
  315. "uses_default_features": true
  316. }
  317. ],
  318. "description": null,
  319. "edition": "2015",
  320. "features": {},
  321. "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  322. "keywords": [],
  323. "license": null,
  324. "license_file": null,
  325. "links": null,
  326. "manifest_path": "[..]Cargo.toml",
  327. "metadata": null,
  328. "publish": null,
  329. "name": "bar",
  330. "readme": null,
  331. "repository": null,
  332. "rust_version": null,
  333. "homepage": null,
  334. "documentation": null,
  335. "source": "registry+https://github.com/rust-lang/crates.io-index",
  336. "targets": [
  337. {
  338. "crate_types": [
  339. "lib"
  340. ],
  341. "doc": true,
  342. "doctest": true,
  343. "test": true,
  344. "edition": "2015",
  345. "kind": [
  346. "lib"
  347. ],
  348. "name": "bar",
  349. "src_path": "[..]src/lib.rs"
  350. }
  351. ],
  352. "version": "0.0.1"
  353. },
  354. {
  355. "authors": [],
  356. "categories": [],
  357. "default_run": null,
  358. "dependencies": [],
  359. "description": null,
  360. "edition": "2015",
  361. "features": {},
  362. "id": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  363. "keywords": [],
  364. "license": null,
  365. "license_file": null,
  366. "links": null,
  367. "manifest_path": "[..]Cargo.toml",
  368. "metadata": null,
  369. "publish": null,
  370. "name": "baz",
  371. "readme": null,
  372. "repository": null,
  373. "rust_version": null,
  374. "homepage": null,
  375. "documentation": null,
  376. "source": "registry+https://github.com/rust-lang/crates.io-index",
  377. "targets": [
  378. {
  379. "crate_types": [
  380. "lib"
  381. ],
  382. "doc": true,
  383. "doctest": true,
  384. "test": true,
  385. "edition": "2015",
  386. "kind": [
  387. "lib"
  388. ],
  389. "name": "baz",
  390. "src_path": "[..]src/lib.rs"
  391. }
  392. ],
  393. "version": "0.0.1"
  394. },
  395. {
  396. "authors": [],
  397. "categories": [],
  398. "default_run": null,
  399. "dependencies": [
  400. {
  401. "features": [],
  402. "kind": null,
  403. "name": "bar",
  404. "optional": false,
  405. "registry": null,
  406. "rename": null,
  407. "req": "*",
  408. "source": "registry+https://github.com/rust-lang/crates.io-index",
  409. "target": null,
  410. "uses_default_features": true
  411. },
  412. {
  413. "features": [],
  414. "kind": "dev",
  415. "name": "foobar",
  416. "optional": false,
  417. "registry": null,
  418. "rename": null,
  419. "req": "*",
  420. "source": "registry+https://github.com/rust-lang/crates.io-index",
  421. "target": null,
  422. "uses_default_features": true
  423. }
  424. ],
  425. "description": "foo",
  426. "edition": "2015",
  427. "features": {},
  428. "id": "foo 0.5.0 (path+file:[..]foo)",
  429. "keywords": [],
  430. "license": "MIT",
  431. "license_file": null,
  432. "links": null,
  433. "manifest_path": "[..]Cargo.toml",
  434. "metadata": null,
  435. "publish": null,
  436. "name": "foo",
  437. "readme": null,
  438. "repository": null,
  439. "rust_version": null,
  440. "homepage": null,
  441. "documentation": null,
  442. "source": null,
  443. "targets": [
  444. {
  445. "crate_types": [
  446. "bin"
  447. ],
  448. "doc": true,
  449. "doctest": false,
  450. "test": true,
  451. "edition": "2015",
  452. "kind": [
  453. "bin"
  454. ],
  455. "name": "foo",
  456. "src_path": "[..]src/foo.rs"
  457. }
  458. ],
  459. "version": "0.5.0"
  460. },
  461. {
  462. "authors": [],
  463. "categories": [],
  464. "default_run": null,
  465. "dependencies": [],
  466. "description": null,
  467. "edition": "2015",
  468. "features": {},
  469. "id": "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  470. "keywords": [],
  471. "license": null,
  472. "license_file": null,
  473. "links": null,
  474. "manifest_path": "[..]Cargo.toml",
  475. "metadata": null,
  476. "publish": null,
  477. "name": "foobar",
  478. "readme": null,
  479. "repository": null,
  480. "rust_version": null,
  481. "homepage": null,
  482. "documentation": null,
  483. "source": "registry+https://github.com/rust-lang/crates.io-index",
  484. "targets": [
  485. {
  486. "crate_types": [
  487. "lib"
  488. ],
  489. "doc": true,
  490. "doctest": true,
  491. "test": true,
  492. "edition": "2015",
  493. "kind": [
  494. "lib"
  495. ],
  496. "name": "foobar",
  497. "src_path": "[..]src/lib.rs"
  498. }
  499. ],
  500. "version": "0.0.1"
  501. }
  502. ],
  503. "resolve": {
  504. "nodes": [
  505. {
  506. "dependencies": [
  507. "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
  508. ],
  509. "deps": [
  510. {
  511. "dep_kinds": [
  512. {
  513. "kind": null,
  514. "target": null
  515. }
  516. ],
  517. "name": "baz",
  518. "pkg": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
  519. }
  520. ],
  521. "features": [],
  522. "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
  523. },
  524. {
  525. "dependencies": [],
  526. "deps": [],
  527. "features": [],
  528. "id": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
  529. },
  530. {
  531. "dependencies": [
  532. "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  533. "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
  534. ],
  535. "deps": [
  536. {
  537. "dep_kinds": [
  538. {
  539. "kind": null,
  540. "target": null
  541. }
  542. ],
  543. "name": "bar",
  544. "pkg": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
  545. },
  546. {
  547. "dep_kinds": [
  548. {
  549. "kind": "dev",
  550. "target": null
  551. }
  552. ],
  553. "name": "foobar",
  554. "pkg": "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
  555. }
  556. ],
  557. "features": [],
  558. "id": "foo 0.5.0 (path+file:[..]foo)"
  559. },
  560. {
  561. "dependencies": [],
  562. "deps": [],
  563. "features": [],
  564. "id": "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)"
  565. }
  566. ],
  567. "root": "foo 0.5.0 (path+file:[..]foo)"
  568. },
  569. "target_directory": "[..]foo/target",
  570. "version": 1,
  571. "workspace_members": [
  572. "foo 0.5.0 (path+file:[..]foo)"
  573. ],
  574. "workspace_root": "[..]/foo",
  575. "metadata": null
  576. }"#,
  577. )
  578. .run();
  579. }
  580. #[cargo_test]
  581. fn example() {
  582. let p = project()
  583. .file("src/lib.rs", "")
  584. .file("examples/ex.rs", "")
  585. .file(
  586. "Cargo.toml",
  587. r#"
  588. [package]
  589. name = "foo"
  590. version = "0.1.0"
  591. [[example]]
  592. name = "ex"
  593. "#,
  594. )
  595. .build();
  596. p.cargo("metadata")
  597. .with_json(
  598. r#"
  599. {
  600. "packages": [
  601. {
  602. "authors": [],
  603. "categories": [],
  604. "default_run": null,
  605. "name": "foo",
  606. "readme": null,
  607. "repository": null,
  608. "rust_version": null,
  609. "homepage": null,
  610. "documentation": null,
  611. "version": "0.1.0",
  612. "id": "foo[..]",
  613. "keywords": [],
  614. "license": null,
  615. "license_file": null,
  616. "links": null,
  617. "description": null,
  618. "edition": "2015",
  619. "source": null,
  620. "dependencies": [],
  621. "targets": [
  622. {
  623. "kind": [ "lib" ],
  624. "crate_types": [ "lib" ],
  625. "doc": true,
  626. "doctest": true,
  627. "test": true,
  628. "edition": "2015",
  629. "name": "foo",
  630. "src_path": "[..]/foo/src/lib.rs"
  631. },
  632. {
  633. "kind": [ "example" ],
  634. "crate_types": [ "bin" ],
  635. "doc": false,
  636. "doctest": false,
  637. "test": false,
  638. "edition": "2015",
  639. "name": "ex",
  640. "src_path": "[..]/foo/examples/ex.rs"
  641. }
  642. ],
  643. "features": {},
  644. "manifest_path": "[..]Cargo.toml",
  645. "metadata": null,
  646. "publish": null
  647. }
  648. ],
  649. "workspace_members": [
  650. "foo 0.1.0 (path+file:[..]foo)"
  651. ],
  652. "resolve": {
  653. "root": "foo 0.1.0 (path+file://[..]foo)",
  654. "nodes": [
  655. {
  656. "id": "foo 0.1.0 (path+file:[..]foo)",
  657. "features": [],
  658. "dependencies": [],
  659. "deps": []
  660. }
  661. ]
  662. },
  663. "target_directory": "[..]foo/target",
  664. "version": 1,
  665. "workspace_root": "[..]/foo",
  666. "metadata": null
  667. }"#,
  668. )
  669. .run();
  670. }
  671. #[cargo_test]
  672. fn example_lib() {
  673. let p = project()
  674. .file("src/lib.rs", "")
  675. .file("examples/ex.rs", "")
  676. .file(
  677. "Cargo.toml",
  678. r#"
  679. [package]
  680. name = "foo"
  681. version = "0.1.0"
  682. [[example]]
  683. name = "ex"
  684. crate-type = ["rlib", "dylib"]
  685. "#,
  686. )
  687. .build();
  688. p.cargo("metadata")
  689. .with_json(
  690. r#"
  691. {
  692. "packages": [
  693. {
  694. "authors": [],
  695. "categories": [],
  696. "default_run": null,
  697. "name": "foo",
  698. "readme": null,
  699. "repository": null,
  700. "rust_version": null,
  701. "homepage": null,
  702. "documentation": null,
  703. "version": "0.1.0",
  704. "id": "foo[..]",
  705. "keywords": [],
  706. "license": null,
  707. "license_file": null,
  708. "links": null,
  709. "description": null,
  710. "edition": "2015",
  711. "source": null,
  712. "dependencies": [],
  713. "targets": [
  714. {
  715. "kind": [ "lib" ],
  716. "crate_types": [ "lib" ],
  717. "doc": true,
  718. "doctest": true,
  719. "test": true,
  720. "edition": "2015",
  721. "name": "foo",
  722. "src_path": "[..]/foo/src/lib.rs"
  723. },
  724. {
  725. "kind": [ "example" ],
  726. "crate_types": [ "rlib", "dylib" ],
  727. "doc": false,
  728. "doctest": false,
  729. "test": false,
  730. "edition": "2015",
  731. "name": "ex",
  732. "src_path": "[..]/foo/examples/ex.rs"
  733. }
  734. ],
  735. "features": {},
  736. "manifest_path": "[..]Cargo.toml",
  737. "metadata": null,
  738. "publish": null
  739. }
  740. ],
  741. "workspace_members": [
  742. "foo 0.1.0 (path+file:[..]foo)"
  743. ],
  744. "resolve": {
  745. "root": "foo 0.1.0 (path+file://[..]foo)",
  746. "nodes": [
  747. {
  748. "id": "foo 0.1.0 (path+file:[..]foo)",
  749. "features": [],
  750. "dependencies": [],
  751. "deps": []
  752. }
  753. ]
  754. },
  755. "target_directory": "[..]foo/target",
  756. "version": 1,
  757. "workspace_root": "[..]/foo",
  758. "metadata": null
  759. }"#,
  760. )
  761. .run();
  762. }
  763. #[cargo_test]
  764. fn workspace_metadata() {
  765. let p = project()
  766. .file(
  767. "Cargo.toml",
  768. r#"
  769. [workspace]
  770. members = ["bar", "baz"]
  771. [workspace.metadata]
  772. tool1 = "hello"
  773. tool2 = [1, 2, 3]
  774. [workspace.metadata.foo]
  775. bar = 3
  776. "#,
  777. )
  778. .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
  779. .file("bar/src/lib.rs", "")
  780. .file("baz/Cargo.toml", &basic_lib_manifest("baz"))
  781. .file("baz/src/lib.rs", "")
  782. .build();
  783. p.cargo("metadata")
  784. .with_json(
  785. r#"
  786. {
  787. "packages": [
  788. {
  789. "authors": [
  790. "wycats@example.com"
  791. ],
  792. "categories": [],
  793. "default_run": null,
  794. "name": "bar",
  795. "version": "0.5.0",
  796. "id": "bar[..]",
  797. "readme": null,
  798. "repository": null,
  799. "rust_version": null,
  800. "homepage": null,
  801. "documentation": null,
  802. "keywords": [],
  803. "source": null,
  804. "dependencies": [],
  805. "license": null,
  806. "license_file": null,
  807. "links": null,
  808. "description": null,
  809. "edition": "2015",
  810. "targets": [
  811. {
  812. "kind": [ "lib" ],
  813. "crate_types": [ "lib" ],
  814. "doc": true,
  815. "doctest": true,
  816. "test": true,
  817. "edition": "2015",
  818. "name": "bar",
  819. "src_path": "[..]bar/src/lib.rs"
  820. }
  821. ],
  822. "features": {},
  823. "manifest_path": "[..]bar/Cargo.toml",
  824. "metadata": null,
  825. "publish": null
  826. },
  827. {
  828. "authors": [
  829. "wycats@example.com"
  830. ],
  831. "categories": [],
  832. "default_run": null,
  833. "name": "baz",
  834. "readme": null,
  835. "repository": null,
  836. "rust_version": null,
  837. "homepage": null,
  838. "documentation": null,
  839. "version": "0.5.0",
  840. "id": "baz[..]",
  841. "keywords": [],
  842. "source": null,
  843. "dependencies": [],
  844. "license": null,
  845. "license_file": null,
  846. "links": null,
  847. "description": null,
  848. "edition": "2015",
  849. "targets": [
  850. {
  851. "kind": [ "lib" ],
  852. "crate_types": [ "lib" ],
  853. "doc": true,
  854. "doctest": true,
  855. "test": true,
  856. "edition": "2015",
  857. "name": "baz",
  858. "src_path": "[..]baz/src/lib.rs"
  859. }
  860. ],
  861. "features": {},
  862. "manifest_path": "[..]baz/Cargo.toml",
  863. "metadata": null,
  864. "publish": null
  865. }
  866. ],
  867. "workspace_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
  868. "resolve": {
  869. "nodes": [
  870. {
  871. "dependencies": [],
  872. "deps": [],
  873. "features": [],
  874. "id": "bar 0.5.0 (path+file:[..]bar)"
  875. },
  876. {
  877. "dependencies": [],
  878. "deps": [],
  879. "features": [],
  880. "id": "baz 0.5.0 (path+file:[..]baz)"
  881. }
  882. ],
  883. "root": null
  884. },
  885. "target_directory": "[..]foo/target",
  886. "version": 1,
  887. "workspace_root": "[..]/foo",
  888. "metadata": {
  889. "tool1": "hello",
  890. "tool2": [1, 2, 3],
  891. "foo": {
  892. "bar": 3
  893. }
  894. }
  895. }"#,
  896. )
  897. .run();
  898. }
  899. #[cargo_test]
  900. fn workspace_metadata_with_dependencies_no_deps() {
  901. let p = project()
  902. // NOTE that 'artifact' isn't mentioned in the workspace here, yet it shows up as member.
  903. .file(
  904. "Cargo.toml",
  905. r#"
  906. [workspace]
  907. members = ["bar", "baz"]
  908. "#,
  909. )
  910. .file(
  911. "bar/Cargo.toml",
  912. r#"
  913. [package]
  914. name = "bar"
  915. version = "0.5.0"
  916. authors = ["wycats@example.com"]
  917. [dependencies]
  918. baz = { path = "../baz/" }
  919. artifact = { path = "../artifact/", artifact = "bin" }
  920. "#,
  921. )
  922. .file("bar/src/lib.rs", "")
  923. .file("baz/Cargo.toml", &basic_lib_manifest("baz"))
  924. .file("baz/src/lib.rs", "")
  925. .file("artifact/Cargo.toml", &basic_bin_manifest("artifact"))
  926. .file("artifact/src/main.rs", "fn main() {}")
  927. .build();
  928. p.cargo("metadata --no-deps -Z bindeps")
  929. .masquerade_as_nightly_cargo()
  930. .with_json(
  931. r#"
  932. {
  933. "packages": [
  934. {
  935. "authors": [
  936. "wycats@example.com"
  937. ],
  938. "categories": [],
  939. "default_run": null,
  940. "name": "bar",
  941. "readme": null,
  942. "repository": null,
  943. "rust_version": null,
  944. "homepage": null,
  945. "documentation": null,
  946. "version": "0.5.0",
  947. "id": "bar[..]",
  948. "keywords": [],
  949. "source": null,
  950. "license": null,
  951. "dependencies": [
  952. {
  953. "features": [],
  954. "kind": null,
  955. "name": "artifact",
  956. "optional": false,
  957. "path": "[..]/foo/artifact",
  958. "registry": null,
  959. "rename": null,
  960. "req": "*",
  961. "source": null,
  962. "target": null,
  963. "uses_default_features": true,
  964. "artifact": {
  965. "kinds": [
  966. "bin"
  967. ],
  968. "lib": false,
  969. "target": null
  970. }
  971. },
  972. {
  973. "features": [],
  974. "kind": null,
  975. "name": "baz",
  976. "optional": false,
  977. "path": "[..]/foo/baz",
  978. "registry": null,
  979. "rename": null,
  980. "req": "*",
  981. "source": null,
  982. "target": null,
  983. "uses_default_features": true
  984. }
  985. ],
  986. "license_file": null,
  987. "links": null,
  988. "description": null,
  989. "edition": "2015",
  990. "targets": [
  991. {
  992. "kind": [ "lib" ],
  993. "crate_types": [ "lib" ],
  994. "doc": true,
  995. "doctest": true,
  996. "test": true,
  997. "edition": "2015",
  998. "name": "bar",
  999. "src_path": "[..]bar/src/lib.rs"
  1000. }
  1001. ],
  1002. "features": {},
  1003. "manifest_path": "[..]bar/Cargo.toml",
  1004. "metadata": null,
  1005. "publish": null
  1006. },
  1007. {
  1008. "authors": [
  1009. "wycats@example.com"
  1010. ],
  1011. "categories": [],
  1012. "default_run": null,
  1013. "dependencies": [],
  1014. "description": null,
  1015. "documentation": null,
  1016. "edition": "2015",
  1017. "features": {},
  1018. "homepage": null,
  1019. "id": "artifact 0.5.0 (path+file:[..]/foo/artifact)",
  1020. "keywords": [],
  1021. "license": null,
  1022. "license_file": null,
  1023. "links": null,
  1024. "manifest_path": "[..]/foo/artifact/Cargo.toml",
  1025. "metadata": null,
  1026. "name": "artifact",
  1027. "publish": null,
  1028. "readme": null,
  1029. "repository": null,
  1030. "rust_version": null,
  1031. "source": null,
  1032. "targets": [
  1033. {
  1034. "crate_types": [
  1035. "bin"
  1036. ],
  1037. "doc": true,
  1038. "doctest": false,
  1039. "edition": "2015",
  1040. "kind": [
  1041. "bin"
  1042. ],
  1043. "name": "artifact",
  1044. "src_path": "[..]/foo/artifact/src/main.rs",
  1045. "test": true
  1046. }
  1047. ],
  1048. "version": "0.5.0"
  1049. },
  1050. {
  1051. "authors": [
  1052. "wycats@example.com"
  1053. ],
  1054. "categories": [],
  1055. "default_run": null,
  1056. "name": "baz",
  1057. "readme": null,
  1058. "repository": null,
  1059. "rust_version": null,
  1060. "homepage": null,
  1061. "documentation": null,
  1062. "version": "0.5.0",
  1063. "id": "baz[..]",
  1064. "keywords": [],
  1065. "source": null,
  1066. "dependencies": [],
  1067. "license": null,
  1068. "license_file": null,
  1069. "links": null,
  1070. "description": null,
  1071. "edition": "2015",
  1072. "targets": [
  1073. {
  1074. "kind": [ "lib" ],
  1075. "crate_types": ["lib"],
  1076. "doc": true,
  1077. "doctest": true,
  1078. "test": true,
  1079. "edition": "2015",
  1080. "name": "baz",
  1081. "src_path": "[..]baz/src/lib.rs"
  1082. }
  1083. ],
  1084. "features": {},
  1085. "manifest_path": "[..]baz/Cargo.toml",
  1086. "metadata": null,
  1087. "publish": null
  1088. }
  1089. ],
  1090. "workspace_members": [
  1091. "bar 0.5.0 (path+file:[..]bar)",
  1092. "artifact 0.5.0 (path+file:[..]/foo/artifact)",
  1093. "baz 0.5.0 (path+file:[..]baz)"
  1094. ],
  1095. "resolve": null,
  1096. "target_directory": "[..]foo/target",
  1097. "version": 1,
  1098. "workspace_root": "[..]/foo",
  1099. "metadata": null
  1100. }"#,
  1101. )
  1102. .run();
  1103. }
  1104. #[cargo_test]
  1105. fn workspace_metadata_with_dependencies_and_resolve() {
  1106. let alt_target = "wasm32-unknown-unknown";
  1107. let p = project()
  1108. .file(
  1109. "Cargo.toml",
  1110. r#"
  1111. [workspace]
  1112. members = ["bar", "artifact", "non-artifact", "bin-only-artifact"]
  1113. "#,
  1114. )
  1115. .file(
  1116. "bar/Cargo.toml",
  1117. &r#"
  1118. [package]
  1119. name = "bar"
  1120. version = "0.5.0"
  1121. authors = []
  1122. [build-dependencies]
  1123. artifact = { path = "../artifact/", artifact = "bin", target = "target" }
  1124. bin-only-artifact = { path = "../bin-only-artifact/", artifact = "bin", target = "$ALT_TARGET" }
  1125. non-artifact = { path = "../non-artifact" }
  1126. [dependencies]
  1127. artifact = { path = "../artifact/", artifact = ["cdylib", "staticlib", "bin:baz-name"], lib = true, target = "$ALT_TARGET" }
  1128. bin-only-artifact = { path = "../bin-only-artifact/", artifact = "bin:a-name" }
  1129. non-artifact = { path = "../non-artifact" }
  1130. [dev-dependencies]
  1131. artifact = { path = "../artifact/" }
  1132. non-artifact = { path = "../non-artifact" }
  1133. bin-only-artifact = { path = "../bin-only-artifact/", artifact = "bin:b-name" }
  1134. "#.replace("$ALT_TARGET", alt_target),
  1135. )
  1136. .file("bar/src/lib.rs", "")
  1137. .file("bar/build.rs", "fn main() {}")
  1138. .file(
  1139. "artifact/Cargo.toml",
  1140. r#"
  1141. [package]
  1142. name = "artifact"
  1143. version = "0.5.0"
  1144. authors = []
  1145. [lib]
  1146. crate-type = ["staticlib", "cdylib", "rlib"]
  1147. [[bin]]
  1148. name = "bar-name"
  1149. [[bin]]
  1150. name = "baz-name"
  1151. "#,
  1152. )
  1153. .file("artifact/src/main.rs", "fn main() {}")
  1154. .file("artifact/src/lib.rs", "")
  1155. .file(
  1156. "bin-only-artifact/Cargo.toml",
  1157. r#"
  1158. [package]
  1159. name = "bin-only-artifact"
  1160. version = "0.5.0"
  1161. authors = []
  1162. [[bin]]
  1163. name = "a-name"
  1164. [[bin]]
  1165. name = "b-name"
  1166. "#,
  1167. )
  1168. .file("bin-only-artifact/src/main.rs", "fn main() {}")
  1169. .file("non-artifact/Cargo.toml",
  1170. r#"
  1171. [package]
  1172. name = "non-artifact"
  1173. version = "0.5.0"
  1174. authors = []
  1175. "#,
  1176. )
  1177. .file("non-artifact/src/lib.rs", "")
  1178. .build();
  1179. p.cargo("metadata -Z bindeps")
  1180. .masquerade_as_nightly_cargo()
  1181. .with_json(
  1182. r#"
  1183. {
  1184. "metadata": null,
  1185. "packages": [
  1186. {
  1187. "authors": [],
  1188. "categories": [],
  1189. "default_run": null,
  1190. "dependencies": [],
  1191. "description": null,
  1192. "documentation": null,
  1193. "edition": "2015",
  1194. "features": {},
  1195. "homepage": null,
  1196. "id": "artifact 0.5.0 (path+file://[..]/foo/artifact)",
  1197. "keywords": [],
  1198. "license": null,
  1199. "license_file": null,
  1200. "links": null,
  1201. "manifest_path": "[..]/foo/artifact/Cargo.toml",
  1202. "metadata": null,
  1203. "name": "artifact",
  1204. "publish": null,
  1205. "readme": null,
  1206. "repository": null,
  1207. "rust_version": null,
  1208. "source": null,
  1209. "targets": [
  1210. {
  1211. "crate_types": [
  1212. "staticlib",
  1213. "cdylib",
  1214. "rlib"
  1215. ],
  1216. "doc": true,
  1217. "doctest": true,
  1218. "edition": "2015",
  1219. "kind": [
  1220. "staticlib",
  1221. "cdylib",
  1222. "rlib"
  1223. ],
  1224. "name": "artifact",
  1225. "src_path": "[..]/foo/artifact/src/lib.rs",
  1226. "test": true
  1227. },
  1228. {
  1229. "crate_types": [
  1230. "bin"
  1231. ],
  1232. "doc": true,
  1233. "doctest": false,
  1234. "edition": "2015",
  1235. "kind": [
  1236. "bin"
  1237. ],
  1238. "name": "bar-name",
  1239. "src_path": "[..]/foo/artifact/src/main.rs",
  1240. "test": true
  1241. },
  1242. {
  1243. "crate_types": [
  1244. "bin"
  1245. ],
  1246. "doc": true,
  1247. "doctest": false,
  1248. "edition": "2015",
  1249. "kind": [
  1250. "bin"
  1251. ],
  1252. "name": "baz-name",
  1253. "src_path": "[..]/foo/artifact/src/main.rs",
  1254. "test": true
  1255. }
  1256. ],
  1257. "version": "0.5.0"
  1258. },
  1259. {
  1260. "authors": [],
  1261. "categories": [],
  1262. "default_run": null,
  1263. "dependencies": [
  1264. {
  1265. "artifact": {
  1266. "kinds": [
  1267. "cdylib",
  1268. "staticlib",
  1269. "bin:baz-name"
  1270. ],
  1271. "lib": true,
  1272. "target": "wasm32-unknown-unknown"
  1273. },
  1274. "features": [],
  1275. "kind": null,
  1276. "name": "artifact",
  1277. "optional": false,
  1278. "path": "[..]/foo/artifact",
  1279. "registry": null,
  1280. "rename": null,
  1281. "req": "*",
  1282. "source": null,
  1283. "target": null,
  1284. "uses_default_features": true
  1285. },
  1286. {
  1287. "artifact": {
  1288. "kinds": [
  1289. "bin:a-name"
  1290. ],
  1291. "lib": false,
  1292. "target": null
  1293. },
  1294. "features": [],
  1295. "kind": null,
  1296. "name": "bin-only-artifact",
  1297. "optional": false,
  1298. "path": "[..]/foo/bin-only-artifact",
  1299. "registry": null,
  1300. "rename": null,
  1301. "req": "*",
  1302. "source": null,
  1303. "target": null,
  1304. "uses_default_features": true
  1305. },
  1306. {
  1307. "features": [],
  1308. "kind": null,
  1309. "name": "non-artifact",
  1310. "optional": false,
  1311. "path": "[..]/foo/non-artifact",
  1312. "registry": null,
  1313. "rename": null,
  1314. "req": "*",
  1315. "source": null,
  1316. "target": null,
  1317. "uses_default_features": true
  1318. },
  1319. {
  1320. "features": [],
  1321. "kind": "dev",
  1322. "name": "artifact",
  1323. "optional": false,
  1324. "path": "[..]/foo/artifact",
  1325. "registry": null,
  1326. "rename": null,
  1327. "req": "*",
  1328. "source": null,
  1329. "target": null,
  1330. "uses_default_features": true
  1331. },
  1332. {
  1333. "artifact": {
  1334. "kinds": [
  1335. "bin:b-name"
  1336. ],
  1337. "lib": false,
  1338. "target": null
  1339. },
  1340. "features": [],
  1341. "kind": "dev",
  1342. "name": "bin-only-artifact",
  1343. "optional": false,
  1344. "path": "[..]/foo/bin-only-artifact",
  1345. "registry": null,
  1346. "rename": null,
  1347. "req": "*",
  1348. "source": null,
  1349. "target": null,
  1350. "uses_default_features": true
  1351. },
  1352. {
  1353. "features": [],
  1354. "kind": "dev",
  1355. "name": "non-artifact",
  1356. "optional": false,
  1357. "path": "[..]/foo/non-artifact",
  1358. "registry": null,
  1359. "rename": null,
  1360. "req": "*",
  1361. "source": null,
  1362. "target": null,
  1363. "uses_default_features": true
  1364. },
  1365. {
  1366. "artifact": {
  1367. "kinds": [
  1368. "bin"
  1369. ],
  1370. "lib": false,
  1371. "target": "target"
  1372. },
  1373. "features": [],
  1374. "kind": "build",
  1375. "name": "artifact",
  1376. "optional": false,
  1377. "path": "[..]/foo/artifact",
  1378. "registry": null,
  1379. "rename": null,
  1380. "req": "*",
  1381. "source": null,
  1382. "target": null,
  1383. "uses_default_features": true
  1384. },
  1385. {
  1386. "artifact": {
  1387. "kinds": [
  1388. "bin"
  1389. ],
  1390. "lib": false,
  1391. "target": "wasm32-unknown-unknown"
  1392. },
  1393. "features": [],
  1394. "kind": "build",
  1395. "name": "bin-only-artifact",
  1396. "optional": false,
  1397. "path": "[..]/foo/bin-only-artifact",
  1398. "registry": null,
  1399. "rename": null,
  1400. "req": "*",
  1401. "source": null,
  1402. "target": null,
  1403. "uses_default_features": true
  1404. },
  1405. {
  1406. "features": [],
  1407. "kind": "build",
  1408. "name": "non-artifact",
  1409. "optional": false,
  1410. "path": "[..]/foo/non-artifact",
  1411. "registry": null,
  1412. "rename": null,
  1413. "req": "*",
  1414. "source": null,
  1415. "target": null,
  1416. "uses_default_features": true
  1417. }
  1418. ],
  1419. "description": null,
  1420. "documentation": null,
  1421. "edition": "2015",
  1422. "features": {},
  1423. "homepage": null,
  1424. "id": "bar 0.5.0 (path+file://[..]/foo/bar)",
  1425. "keywords": [],
  1426. "license": null,
  1427. "license_file": null,
  1428. "links": null,
  1429. "manifest_path": "[..]/foo/bar/Cargo.toml",
  1430. "metadata": null,
  1431. "name": "bar",
  1432. "publish": null,
  1433. "readme": null,
  1434. "repository": null,
  1435. "rust_version": null,
  1436. "source": null,
  1437. "targets": [
  1438. {
  1439. "crate_types": [
  1440. "lib"
  1441. ],
  1442. "doc": true,
  1443. "doctest": true,
  1444. "edition": "2015",
  1445. "kind": [
  1446. "lib"
  1447. ],
  1448. "name": "bar",
  1449. "src_path": "[..]/foo/bar/src/lib.rs",
  1450. "test": true
  1451. },
  1452. {
  1453. "crate_types": [
  1454. "bin"
  1455. ],
  1456. "doc": false,
  1457. "doctest": false,
  1458. "edition": "2015",
  1459. "kind": [
  1460. "custom-build"
  1461. ],
  1462. "name": "build-script-build",
  1463. "src_path": "[..]/foo/bar/build.rs",
  1464. "test": false
  1465. }
  1466. ],
  1467. "version": "0.5.0"
  1468. },
  1469. {
  1470. "authors": [],
  1471. "categories": [],
  1472. "default_run": null,
  1473. "dependencies": [],
  1474. "description": null,
  1475. "documentation": null,
  1476. "edition": "2015",
  1477. "features": {},
  1478. "homepage": null,
  1479. "id": "bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)",
  1480. "keywords": [],
  1481. "license": null,
  1482. "license_file": null,
  1483. "links": null,
  1484. "manifest_path": "[..]/foo/bin-only-artifact/Cargo.toml",
  1485. "metadata": null,
  1486. "name": "bin-only-artifact",
  1487. "publish": null,
  1488. "readme": null,
  1489. "repository": null,