Repository: oli-obk/cargo_metadata
Pull request #141 (2020-11-22 14:14:52)

Add `documentation` and `homepage` to `Package`
Closes https://github.com/oli-obk/cargo_metadata/issues/140


Patch:
diff --git a/src/lib.rs b/src/lib.rs
index eb2e151..532847e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -287,6 +287,14 @@ pub struct Package {
     /// Repository as given in the `Cargo.toml`
     // can't use `url::Url` because that requires a more recent stable compiler
     pub repository: Option<String>,
+    /// Homepage as given in the `Cargo.toml`
+    ///
+    /// On versions of cargo before 1.49, this will always be [`None`].
+    pub homepage: Option<String>,
+    /// Documentation URL as given in the `Cargo.toml`
+    ///
+    /// On versions of cargo before 1.49, this will always be [`None`].
+    pub documentation: Option<String>,
     /// Default Rust edition for the package
     ///
     /// Beware that individual targets may specify their own edition in


Test patch:
diff --git a/tests/all/Cargo.toml b/tests/all/Cargo.toml
index 12832de..6cdd4de 100644
--- a/tests/all/Cargo.toml
+++ b/tests/all/Cargo.toml
@@ -10,6 +10,8 @@ categories = ["command-line-utilities"]
 keywords = ["cli"]
 readme = "README.md"
 repository = "https://github.com/oli-obk/cargo_metadata/"
+homepage = "https://github.com/oli-obk/cargo_metadata/"
+documentation = "https://docs.rs/cargo_metadata/"
 links = "foo"
 publish = false
 
@@ -54,4 +56,4 @@ required-features = ["feat2"]
 exclude = ["bdep", "benches", "devdep", "examples", "featdep", "namedep", "oldname", "path-dep", "windep"]
 
 [workspace.metadata.testobject]
-myvalue = "abc"
\ No newline at end of file
+myvalue = "abc"
diff --git a/tests/test_samples.rs b/tests/test_samples.rs
index ab631d1..b70eb46 100644
--- a/tests/test_samples.rs
+++ b/tests/test_samples.rs
@@ -101,6 +101,8 @@ fn old_minimal() {
     assert_eq!(pkg.keywords.len(), 0);
     assert_eq!(pkg.readme, None);
     assert_eq!(pkg.repository, None);
+    assert_eq!(pkg.homepage, None);
+    assert_eq!(pkg.documentation, None);
     assert_eq!(pkg.edition, "2015");
     assert_eq!(pkg.metadata, serde_json::Value::Null);
     assert_eq!(pkg.links, None);
@@ -153,10 +155,10 @@ struct TestObject {
 
 #[test]
 fn all_the_fields() {
-    // All the fields currently generated as of 1.47. This tries to exercise as
+    // All the fields currently generated as of 1.49. This tries to exercise as
     // much as possible.
     let ver = cargo_version();
-    let minimum = semver::Version::parse("1.47.0").unwrap();
+    let minimum = semver::Version::parse("1.49.0").unwrap();
     if ver < minimum {
         // edition added in 1.30
         // rename added in 1.31
@@ -165,6 +167,8 @@ fn all_the_fields() {
         // publish added in 1.39
         // dep_kinds added in 1.41
         // test added in 1.47
+        // homepage added in 1.49
+        // documentation added in 1.49
         eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver);
         return;
     }
@@ -323,6 +327,14 @@ fn all_the_fields() {
         all.repository,
         Some("https://github.com/oli-obk/cargo_metadata/".to_string())
     );
+    assert_eq!(
+        all.homepage,
+        Some("https://github.com/oli-obk/cargo_metadata/".to_string())
+    );
+    assert_eq!(
+        all.documentation,
+        Some("https://docs.rs/cargo_metadata/".to_string())
+    );
     assert_eq!(all.edition, "2018");
     assert_eq!(
         all.metadata,