Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle renamed dependencies correctly #60

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
48 changes: 46 additions & 2 deletions src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,20 @@ struct Dep {

impl From<Dep> for crate::index::Dep {
fn from(source: Dep) -> Self {
let (name, package) = match &source.explicit_name_in_toml {
Some(explicit) => (explicit.to_string(), Some(source.name.to_string())),
None => (source.name.to_string(), None),
};
Self {
name: source.name,
name,
req: source.version_req,
features: source.features,
optional: source.optional,
default_features: source.default_features,
target: source.target,
kind: source.kind.to_string(),
registry: source.registry,
package: source.explicit_name_in_toml,
package,
}
}
}
Expand Down Expand Up @@ -353,4 +357,44 @@ mod tests {
assert_eq!(&crate_path("abcd"), Path::new("ab/cd"));
assert_eq!(&crate_path("ydasdayusiy"), Path::new("yd/as"));
}

#[test]
fn convert_simple_dependency() {
// rand = { version = "0.8.5" }
let dep = Dep {
name: "rand".into(),
version_req: "0.8.5".into(),
features: vec![],
optional: false,
default_features: true,
target: None,
kind: Kind::Normal,
registry: None,
explicit_name_in_toml: None,
};

let index_dep = crate::index::Dep::from(dep);
assert_eq!(index_dep.name.as_str(), "rand"); // name of dependency
assert_eq!(index_dep.package, None); // null if dependency is not renamed
}

#[test]
fn convert_renamed_dependency() {
// renamed-rand = { version = "0.8.5", package = "rand" }
let dep = Dep {
name: "rand".into(),
version_req: "0.8.5".into(),
features: vec![],
optional: false,
default_features: true,
target: None,
kind: Kind::Normal,
registry: None,
explicit_name_in_toml: Some("renamed-rand".into()),
};

let index_dep = crate::index::Dep::from(dep);
assert_eq!(index_dep.name.as_str(), "renamed-rand"); // new name dependency was renamed to
assert_eq!(index_dep.package, Some("rand".into())); // name of dependency package
}
}