Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Aug 7, 2023
1 parent df15c4c commit 0925c72
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
29 changes: 22 additions & 7 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@ pub struct Dependency {
name: String,
vers: String,
kind: String,
artifact: Option<(String, Option<String>)>,
artifact: Option<String>,
bindep_target: Option<String>,
lib: bool,
target: Option<String>,
features: Vec<String>,
registry: Option<String>,
Expand Down Expand Up @@ -1409,13 +1411,20 @@ impl Package {
(true, Some("alternative")) => None,
_ => panic!("registry_dep currently only supports `alternative`"),
};
let artifact = if let Some(artifact) = &dep.artifact {
serde_json::json!([artifact])
} else {
serde_json::json!(null)
};
serde_json::json!({
"name": dep.name,
"req": dep.vers,
"features": dep.features,
"default_features": true,
"target": dep.target,
"artifact": dep.artifact,
"artifact": artifact,
"bindep_target": dep.bindep_target,
"lib": dep.lib,
"optional": dep.optional,
"kind": dep.kind,
"registry": registry_url,
Expand Down Expand Up @@ -1536,11 +1545,14 @@ impl Package {
"#,
target, kind, dep.name, dep.vers
));
if let Some((artifact, target)) = &dep.artifact {
if let Some(artifact) = &dep.artifact {
manifest.push_str(&format!("artifact = \"{}\"\n", artifact));
if let Some(target) = &target {
manifest.push_str(&format!("target = \"{}\"\n", target))
}
}
if let Some(target) = &dep.bindep_target {
manifest.push_str(&format!("target = \"{}\"\n", target));
}
if dep.lib {
manifest.push_str("lib = true\n");
}
if let Some(registry) = &dep.registry {
assert_eq!(registry, "alternative");
Expand Down Expand Up @@ -1617,6 +1629,8 @@ impl Dependency {
vers: vers.to_string(),
kind: "normal".to_string(),
artifact: None,
bindep_target: None,
lib: false,
target: None,
features: Vec::new(),
package: None,
Expand Down Expand Up @@ -1646,7 +1660,8 @@ impl Dependency {
/// Change the artifact to be of the given kind, like "bin", or "staticlib",
/// along with a specific target triple if provided.
pub fn artifact(&mut self, kind: &str, target: Option<String>) -> &mut Self {
self.artifact = Some((kind.to_string(), target));
self.artifact = Some(kind.to_string());
self.bindep_target = target;
self
}

Expand Down
17 changes: 9 additions & 8 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,13 +1445,7 @@ foo v0.0.0 ([CWD])
)
.run();
}

// TODO: Fix this potentially by reverting 887562bfeb8c540594d7d08e6e9a4ab7eb255865 which adds artifact information to the registry
// followed by 0ff93733626f7cbecaf9dce9ab62b4ced0be088e which picks it up.
// For reference, see comments by ehuss /~https://github.com/rust-lang/cargo/pull/9992#discussion_r801086315 and
// joshtriplett /~https://github.com/rust-lang/cargo/pull/9992#issuecomment-1033394197 .
#[cargo_test]
#[ignore = "broken, need artifact info in index"]
fn targets_are_picked_up_from_non_workspace_artifact_deps() {
if cross_compile::disabled() {
return;
Expand Down Expand Up @@ -1926,15 +1920,23 @@ You may press ctrl-c [..]
"badges": {},
"categories": [],
"deps": [{
"artifact": ["bin"],
"default_features": true,
"features": [],
"kind": "normal",
"lib": true,
"name": "bar",
"optional": false,
"target": null,
"version_req": "^1.0"
},
{
"artifact": [
"bin:a",
"cdylib",
"staticlib"
],
"bindep_target": "target",
"default_features": true,
"features": [],
"kind": "build",
Expand Down Expand Up @@ -2894,8 +2896,7 @@ fn check_transitive_artifact_dependency_with_different_target() {
p.cargo("check -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_contains(
"error: could not find specification for target `custom-target`.\n \
Dependency `baz v0.0.0 [..]` requires to build for target `custom-target`.",
"error: failed to run `rustc` to learn about target-specific information",
)
.with_status(101)
.run();
Expand Down

0 comments on commit 0925c72

Please sign in to comment.