Skip to content

Commit 3135dd5

Browse files
committed
Add metadata test to make sure we can get the features
Signed-off-by: hi-rustin <[email protected]>
1 parent 7b970c2 commit 3135dd5

File tree

1 file changed

+188
-9
lines changed

1 file changed

+188
-9
lines changed

tests/testsuite/metadata.rs

Lines changed: 188 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use cargo_test_support::install::cargo_home;
44
use cargo_test_support::paths::CargoPathExt;
5-
use cargo_test_support::registry::Package;
5+
use cargo_test_support::registry::{self, Package};
66
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, main_file, project, rustc_host};
77
use serde_json::json;
88

@@ -86,6 +86,185 @@ fn cargo_metadata_simple() {
8686
.run();
8787
}
8888

89+
#[cargo_test]
90+
fn cargo_metadata_with_registered_dep() {
91+
registry::init();
92+
registry::Package::new("my-package", "0.1.1+my-package")
93+
.feature("default", &["feature1", "feature2"])
94+
.feature("feature1", &[])
95+
.feature("feature2", &[])
96+
.publish();
97+
let p = project()
98+
.file("src/foo.rs", "")
99+
.file(
100+
"Cargo.toml",
101+
r#"
102+
[package]
103+
name = "foo"
104+
version = "0.5.0"
105+
106+
[[bin]]
107+
name = "foo"
108+
109+
[dependencies]
110+
my-package = "0.1.1+my-package"
111+
"#,
112+
)
113+
.build();
114+
115+
p.cargo("metadata")
116+
.with_json(
117+
r#"
118+
{
119+
"packages": [
120+
{
121+
"authors": [],
122+
"categories": [],
123+
"default_run": null,
124+
"dependencies": [
125+
{
126+
"features": [],
127+
"kind": null,
128+
"name": "my-package",
129+
"optional": false,
130+
"registry": null,
131+
"rename": null,
132+
"req": "^0.1.1",
133+
"source": "registry+https://github.com/rust-lang/crates.io-index",
134+
"target": null,
135+
"uses_default_features": true
136+
}
137+
],
138+
"description": null,
139+
"documentation": null,
140+
"edition": "2015",
141+
"features": {},
142+
"homepage": null,
143+
"id": "foo 0.5.0 (path+file:[..]foo)",
144+
"keywords": [],
145+
"license": null,
146+
"license_file": null,
147+
"links": null,
148+
"manifest_path": "[..]foo/Cargo.toml",
149+
"metadata": null,
150+
"name": "foo",
151+
"publish": null,
152+
"readme": null,
153+
"repository": null,
154+
"rust_version": null,
155+
"source": null,
156+
"targets": [
157+
{
158+
"crate_types": [
159+
"bin"
160+
],
161+
"doc": true,
162+
"doctest": false,
163+
"edition": "2015",
164+
"kind": [
165+
"bin"
166+
],
167+
"name": "foo",
168+
"src_path": "[..]foo/src/foo.rs",
169+
"test": true
170+
}
171+
],
172+
"version": "0.5.0"
173+
},
174+
{
175+
"authors": [],
176+
"categories": [],
177+
"default_run": null,
178+
"dependencies": [],
179+
"description": null,
180+
"documentation": null,
181+
"edition": "2015",
182+
"features": {
183+
"default": [
184+
"feature1",
185+
"feature2"
186+
],
187+
"feature1": [],
188+
"feature2": []
189+
},
190+
"homepage": null,
191+
"id": "my-package 0.1.1+my-package (registry+https://github.com/rust-lang/crates.io-index)",
192+
"keywords": [],
193+
"license": null,
194+
"license_file": null,
195+
"links": null,
196+
"manifest_path": "[..]my-package-0.1.1+my-package/Cargo.toml",
197+
"metadata": null,
198+
"name": "my-package",
199+
"publish": null,
200+
"readme": null,
201+
"repository": null,
202+
"rust_version": null,
203+
"source": "registry+https://github.com/rust-lang/crates.io-index",
204+
"targets": [
205+
{
206+
"crate_types": [
207+
"lib"
208+
],
209+
"doc": true,
210+
"doctest": true,
211+
"edition": "2015",
212+
"kind": [
213+
"lib"
214+
],
215+
"name": "my-package",
216+
"src_path": "[..]my-package-0.1.1+my-package/src/lib.rs",
217+
"test": true
218+
}
219+
],
220+
"version": "0.1.1+my-package"
221+
}
222+
],
223+
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
224+
"workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
225+
"resolve": {
226+
"nodes": [
227+
{
228+
"dependencies": [
229+
"my-package 0.1.1+my-package (registry+https://github.com/rust-lang/crates.io-index)"
230+
],
231+
"deps": [
232+
{
233+
"dep_kinds": [
234+
{
235+
"kind": null,
236+
"target": null
237+
}
238+
],
239+
"name": "my_package",
240+
"pkg": "my-package 0.1.1+my-package (registry+https://github.com/rust-lang/crates.io-index)"
241+
}
242+
],
243+
"features": [],
244+
"id": "foo 0.5.0 (path+file:[..]foo)"
245+
},
246+
{
247+
"dependencies": [],
248+
"deps": [],
249+
"features": [
250+
"default",
251+
"feature1",
252+
"feature2"
253+
],
254+
"id": "my-package 0.1.1+my-package (registry+https://github.com/rust-lang/crates.io-index)"
255+
}
256+
],
257+
"root": "foo 0.5.0 (path+file:[..]foo)"
258+
},
259+
"target_directory": "[..]foo/target",
260+
"version": 1,
261+
"workspace_root": "[..]/foo",
262+
"metadata": null
263+
}"#,
264+
)
265+
.run();
266+
}
267+
89268
#[cargo_test]
90269
fn cargo_metadata_warns_on_implicit_version() {
91270
let p = project()
@@ -956,7 +1135,7 @@ fn workspace_metadata_with_dependencies_no_deps() {
9561135
name = "bar"
9571136
version = "0.5.0"
9581137
authors = ["[email protected]"]
959-
1138+
9601139
[dependencies]
9611140
baz = { path = "../baz/" }
9621141
artifact = { path = "../artifact/", artifact = "bin" }
@@ -1012,7 +1191,7 @@ fn workspace_metadata_with_dependencies_no_deps() {
10121191
"lib": false,
10131192
"target": null
10141193
}
1015-
},
1194+
},
10161195
{
10171196
"features": [],
10181197
"kind": null,
@@ -1196,13 +1375,13 @@ fn workspace_metadata_with_dependencies_and_resolve() {
11961375
name = "artifact"
11971376
version = "0.5.0"
11981377
authors = []
1199-
1378+
12001379
[lib]
12011380
crate-type = ["staticlib", "cdylib", "rlib"]
1202-
1381+
12031382
[[bin]]
12041383
name = "bar-name"
1205-
1384+
12061385
[[bin]]
12071386
name = "baz-name"
12081387
"#,
@@ -1216,10 +1395,10 @@ fn workspace_metadata_with_dependencies_and_resolve() {
12161395
name = "bin-only-artifact"
12171396
version = "0.5.0"
12181397
authors = []
1219-
1398+
12201399
[[bin]]
12211400
name = "a-name"
1222-
1401+
12231402
[[bin]]
12241403
name = "b-name"
12251404
"#,
@@ -4040,7 +4219,7 @@ fn workspace_metadata_with_dependencies_no_deps_artifact() {
40404219
name = "bar"
40414220
version = "0.5.0"
40424221
authors = ["[email protected]"]
4043-
4222+
40444223
[dependencies]
40454224
baz = { path = "../baz/" }
40464225
baz-renamed = { path = "../baz/" }

0 commit comments

Comments
 (0)