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

Add support for new path dep field #149

Merged
merged 4 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use semver::VersionReq;
use serde::{Deserialize, Deserializer, Serialize};
use std::path::PathBuf;

#[derive(Eq, PartialEq, Clone, Debug, Copy, Hash, Serialize, Deserialize)]
/// Dependencies can come in three kinds
Expand Down Expand Up @@ -65,6 +66,10 @@ pub struct Dependency {
///
/// If None, the dependency is from crates.io.
pub registry: Option<String>,
/// The file system path for a local path dependency.
///
/// Only produced on cargo 1.51+
pub path: Option<PathBuf>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
Expand Down
10 changes: 9 additions & 1 deletion tests/test_samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate semver;
extern crate serde_json;

use cargo_metadata::{CargoOpt, DependencyKind, Metadata, MetadataCommand};
use std::path::PathBuf;
use std::path::{Path, PathBuf};

#[test]
fn old_minimal() {
Expand Down Expand Up @@ -169,6 +169,7 @@ fn all_the_fields() {
// test added in 1.47
// homepage added in 1.49
// documentation added in 1.49
// path added in 1.51
eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver);
return;
}
Expand Down Expand Up @@ -224,6 +225,13 @@ fn all_the_fields() {
assert_eq!(path_dep.source, None);
assert_eq!(path_dep.kind, DependencyKind::Normal);
assert_eq!(path_dep.req, semver::VersionReq::parse("*").unwrap());
assert_eq!(
path_dep
.path
.as_deref()
jonhoo marked this conversation as resolved.
Show resolved Hide resolved
.map(|p| p.ends_with("path-dep/Cargo.toml")),
Some(true),
);

all.dependencies
.iter()
Expand Down