Skip to content

Commit

Permalink
Add metadata test to make sure we can get the features
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Nov 19, 2023
1 parent 584ef5b commit ecf8671
Showing 1 changed file with 188 additions and 9 deletions.
197 changes: 188 additions & 9 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use cargo_test_support::install::cargo_home;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
use cargo_test_support::registry::{self, Package};
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, main_file, project, rustc_host};
use serde_json::json;

Expand Down Expand Up @@ -86,6 +86,185 @@ fn cargo_metadata_simple() {
.run();
}

#[cargo_test]
fn cargo_metadata_with_registered_dep() {
registry::init();
registry::Package::new("my-package", "0.1.1+my-package")
.feature("default", &["feature1", "feature2"])
.feature("feature1", &[])
.feature("feature2", &[])
.publish();
let p = project()
.file("src/foo.rs", "")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.5.0"
[[bin]]
name = "foo"
[dependencies]
my-package = "0.1.1+my-package"
"#,
)
.build();

p.cargo("metadata")
.with_json(
r#"
{
"packages": [
{
"authors": [],
"categories": [],
"default_run": null,
"dependencies": [
{
"features": [],
"kind": null,
"name": "my-package",
"optional": false,
"registry": null,
"rename": null,
"req": "^0.1.1",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"target": null,
"uses_default_features": true
}
],
"description": null,
"documentation": null,
"edition": "2015",
"features": {},
"homepage": null,
"id": "foo 0.5.0 (path+file:[..]foo)",
"keywords": [],
"license": null,
"license_file": null,
"links": null,
"manifest_path": "[..]foo/Cargo.toml",
"metadata": null,
"name": "foo",
"publish": null,
"readme": null,
"repository": null,
"rust_version": null,
"source": null,
"targets": [
{
"crate_types": [
"bin"
],
"doc": true,
"doctest": false,
"edition": "2015",
"kind": [
"bin"
],
"name": "foo",
"src_path": "[..]foo/src/foo.rs",
"test": true
}
],
"version": "0.5.0"
},
{
"authors": [],
"categories": [],
"default_run": null,
"dependencies": [],
"description": null,
"documentation": null,
"edition": "2015",
"features": {
"default": [
"feature1",
"feature2"
],
"feature1": [],
"feature2": []
},
"homepage": null,
"id": "my-package 0.1.1+my-package (registry+https://github.com/rust-lang/crates.io-index)",
"keywords": [],
"license": null,
"license_file": null,
"links": null,
"manifest_path": "[..]my-package-0.1.1+my-package/Cargo.toml",
"metadata": null,
"name": "my-package",
"publish": null,
"readme": null,
"repository": null,
"rust_version": null,
"source": "registry+https://github.com/rust-lang/crates.io-index",
"targets": [
{
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"edition": "2015",
"kind": [
"lib"
],
"name": "my-package",
"src_path": "[..]my-package-0.1.1+my-package/src/lib.rs",
"test": true
}
],
"version": "0.1.1+my-package"
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
"workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
"resolve": {
"nodes": [
{
"dependencies": [
"my-package 0.1.1+my-package (registry+https://github.com/rust-lang/crates.io-index)"
],
"deps": [
{
"dep_kinds": [
{
"kind": null,
"target": null
}
],
"name": "my_package",
"pkg": "my-package 0.1.1+my-package (registry+https://github.com/rust-lang/crates.io-index)"
}
],
"features": [],
"id": "foo 0.5.0 (path+file:[..]foo)"
},
{
"dependencies": [],
"deps": [],
"features": [
"default",
"feature1",
"feature2"
],
"id": "my-package 0.1.1+my-package (registry+https://github.com/rust-lang/crates.io-index)"
}
],
"root": "foo 0.5.0 (path+file:[..]foo)"
},
"target_directory": "[..]foo/target",
"version": 1,
"workspace_root": "[..]/foo",
"metadata": null
}"#,
)
.run();
}

#[cargo_test]
fn cargo_metadata_warns_on_implicit_version() {
let p = project()
Expand Down Expand Up @@ -956,7 +1135,7 @@ fn workspace_metadata_with_dependencies_no_deps() {
name = "bar"
version = "0.5.0"
authors = ["wycats@example.com"]
[dependencies]
baz = { path = "../baz/" }
artifact = { path = "../artifact/", artifact = "bin" }
Expand Down Expand Up @@ -1012,7 +1191,7 @@ fn workspace_metadata_with_dependencies_no_deps() {
"lib": false,
"target": null
}
},
},
{
"features": [],
"kind": null,
Expand Down Expand Up @@ -1196,13 +1375,13 @@ fn workspace_metadata_with_dependencies_and_resolve() {
name = "artifact"
version = "0.5.0"
authors = []
[lib]
crate-type = ["staticlib", "cdylib", "rlib"]
[[bin]]
name = "bar-name"
[[bin]]
name = "baz-name"
"#,
Expand All @@ -1216,10 +1395,10 @@ fn workspace_metadata_with_dependencies_and_resolve() {
name = "bin-only-artifact"
version = "0.5.0"
authors = []
[[bin]]
name = "a-name"
[[bin]]
name = "b-name"
"#,
Expand Down Expand Up @@ -4040,7 +4219,7 @@ fn workspace_metadata_with_dependencies_no_deps_artifact() {
name = "bar"
version = "0.5.0"
authors = ["wycats@example.com"]
[dependencies]
baz = { path = "../baz/" }
baz-renamed = { path = "../baz/" }
Expand Down

0 comments on commit ecf8671

Please sign in to comment.