Skip to content

Commit 0925c72

Browse files
committed
update tests
1 parent df15c4c commit 0925c72

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

crates/cargo-test-support/src/registry.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,9 @@ pub struct Dependency {
549549
name: String,
550550
vers: String,
551551
kind: String,
552-
artifact: Option<(String, Option<String>)>,
552+
artifact: Option<String>,
553+
bindep_target: Option<String>,
554+
lib: bool,
553555
target: Option<String>,
554556
features: Vec<String>,
555557
registry: Option<String>,
@@ -1409,13 +1411,20 @@ impl Package {
14091411
(true, Some("alternative")) => None,
14101412
_ => panic!("registry_dep currently only supports `alternative`"),
14111413
};
1414+
let artifact = if let Some(artifact) = &dep.artifact {
1415+
serde_json::json!([artifact])
1416+
} else {
1417+
serde_json::json!(null)
1418+
};
14121419
serde_json::json!({
14131420
"name": dep.name,
14141421
"req": dep.vers,
14151422
"features": dep.features,
14161423
"default_features": true,
14171424
"target": dep.target,
1418-
"artifact": dep.artifact,
1425+
"artifact": artifact,
1426+
"bindep_target": dep.bindep_target,
1427+
"lib": dep.lib,
14191428
"optional": dep.optional,
14201429
"kind": dep.kind,
14211430
"registry": registry_url,
@@ -1536,11 +1545,14 @@ impl Package {
15361545
"#,
15371546
target, kind, dep.name, dep.vers
15381547
));
1539-
if let Some((artifact, target)) = &dep.artifact {
1548+
if let Some(artifact) = &dep.artifact {
15401549
manifest.push_str(&format!("artifact = \"{}\"\n", artifact));
1541-
if let Some(target) = &target {
1542-
manifest.push_str(&format!("target = \"{}\"\n", target))
1543-
}
1550+
}
1551+
if let Some(target) = &dep.bindep_target {
1552+
manifest.push_str(&format!("target = \"{}\"\n", target));
1553+
}
1554+
if dep.lib {
1555+
manifest.push_str("lib = true\n");
15441556
}
15451557
if let Some(registry) = &dep.registry {
15461558
assert_eq!(registry, "alternative");
@@ -1617,6 +1629,8 @@ impl Dependency {
16171629
vers: vers.to_string(),
16181630
kind: "normal".to_string(),
16191631
artifact: None,
1632+
bindep_target: None,
1633+
lib: false,
16201634
target: None,
16211635
features: Vec::new(),
16221636
package: None,
@@ -1646,7 +1660,8 @@ impl Dependency {
16461660
/// Change the artifact to be of the given kind, like "bin", or "staticlib",
16471661
/// along with a specific target triple if provided.
16481662
pub fn artifact(&mut self, kind: &str, target: Option<String>) -> &mut Self {
1649-
self.artifact = Some((kind.to_string(), target));
1663+
self.artifact = Some(kind.to_string());
1664+
self.bindep_target = target;
16501665
self
16511666
}
16521667

tests/testsuite/artifact_dep.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,13 +1445,7 @@ foo v0.0.0 ([CWD])
14451445
)
14461446
.run();
14471447
}
1448-
1449-
// TODO: Fix this potentially by reverting 887562bfeb8c540594d7d08e6e9a4ab7eb255865 which adds artifact information to the registry
1450-
// followed by 0ff93733626f7cbecaf9dce9ab62b4ced0be088e which picks it up.
1451-
// For reference, see comments by ehuss https://github.com/rust-lang/cargo/pull/9992#discussion_r801086315 and
1452-
// joshtriplett https://github.com/rust-lang/cargo/pull/9992#issuecomment-1033394197 .
14531448
#[cargo_test]
1454-
#[ignore = "broken, need artifact info in index"]
14551449
fn targets_are_picked_up_from_non_workspace_artifact_deps() {
14561450
if cross_compile::disabled() {
14571451
return;
@@ -1926,15 +1920,23 @@ You may press ctrl-c [..]
19261920
"badges": {},
19271921
"categories": [],
19281922
"deps": [{
1923+
"artifact": ["bin"],
19291924
"default_features": true,
19301925
"features": [],
19311926
"kind": "normal",
1927+
"lib": true,
19321928
"name": "bar",
19331929
"optional": false,
19341930
"target": null,
19351931
"version_req": "^1.0"
19361932
},
19371933
{
1934+
"artifact": [
1935+
"bin:a",
1936+
"cdylib",
1937+
"staticlib"
1938+
],
1939+
"bindep_target": "target",
19381940
"default_features": true,
19391941
"features": [],
19401942
"kind": "build",
@@ -2894,8 +2896,7 @@ fn check_transitive_artifact_dependency_with_different_target() {
28942896
p.cargo("check -Z bindeps")
28952897
.masquerade_as_nightly_cargo(&["bindeps"])
28962898
.with_stderr_contains(
2897-
"error: could not find specification for target `custom-target`.\n \
2898-
Dependency `baz v0.0.0 [..]` requires to build for target `custom-target`.",
2899+
"error: failed to run `rustc` to learn about target-specific information",
28992900
)
29002901
.with_status(101)
29012902
.run();

0 commit comments

Comments
 (0)