]> git.proxmox.com Git - cargo.git/commitdiff
Add tests
authorTarun Verghis <tarun.verghis@gmail.com>
Mon, 25 May 2020 07:07:16 +0000 (00:07 -0700)
committerTarun Verghis <tarun.verghis@gmail.com>
Mon, 25 May 2020 07:07:16 +0000 (00:07 -0700)
crates/cargo-test-support/src/lib.rs
tests/testsuite/read_manifest.rs

index c99259fb29edd2424a5c46b4fa08a9578a801414..b3c1ae640f554f3d49c3f386b10d66b1a0f3dd4c 100644 (file)
@@ -1622,6 +1622,24 @@ pub fn basic_lib_manifest(name: &str) -> String {
     )
 }
 
+pub fn basic_bin_manifest_with_readme(name: &str, readme_filename: &str) -> String {
+    format!(
+        r#"
+        [package]
+
+        name = "{}"
+        version = "0.5.0"
+        authors = ["wycats@example.com"]
+        readme = "{}"
+
+        [[bin]]
+
+        name = "{}"
+    "#,
+        name, readme_filename, name
+    )
+}
+
 pub fn path2url<P: AsRef<Path>>(p: P) -> Url {
     Url::from_file_path(p).ok().unwrap()
 }
index 7ca0c6f9bd4756f6bc30728a93196911ec07711d..85246793644a9e52c6f33dbc957502e4229ece2c 100644 (file)
@@ -1,15 +1,17 @@
 //! Tests for the `cargo read-manifest` command.
 
-use cargo_test_support::{basic_bin_manifest, main_file, project};
+use cargo_test_support::{basic_bin_manifest, basic_bin_manifest_with_readme, main_file, project};
 
-static MANIFEST_OUTPUT: &str = r#"
-{
+fn manifest_output(readme_value: &str) -> String {
+    format!(
+        r#"
+{{
     "authors": [
         "wycats@example.com"
     ],
     "categories": [],
     "name":"foo",
-    "readme": null,
+    "readme": {},
     "repository": null,
     "version":"0.5.0",
     "id":"foo[..]0.5.0[..](path+file://[..]/foo)",
@@ -21,19 +23,25 @@ static MANIFEST_OUTPUT: &str = r#"
     "edition": "2015",
     "source":null,
     "dependencies":[],
-    "targets":[{
+    "targets":[{{
         "kind":["bin"],
         "crate_types":["bin"],
         "doctest": false,
         "edition": "2015",
         "name":"foo",
         "src_path":"[..]/foo/src/foo.rs"
-    }],
-    "features":{},
+    }}],
+    "features":{{}},
     "manifest_path":"[..]Cargo.toml",
     "metadata": null,
     "publish": null
-}"#;
+}}"#, readme_value
+    )
+}
+
+fn manifest_output_no_readme() -> String {
+    manifest_output("null")
+}
 
 #[cargo_test]
 fn cargo_read_manifest_path_to_cargo_toml_relative() {
@@ -44,7 +52,7 @@ fn cargo_read_manifest_path_to_cargo_toml_relative() {
 
     p.cargo("read-manifest --manifest-path foo/Cargo.toml")
         .cwd(p.root().parent().unwrap())
-        .with_json(MANIFEST_OUTPUT)
+        .with_json(&manifest_output_no_readme())
         .run();
 }
 
@@ -58,7 +66,7 @@ fn cargo_read_manifest_path_to_cargo_toml_absolute() {
     p.cargo("read-manifest --manifest-path")
         .arg(p.root().join("Cargo.toml"))
         .cwd(p.root().parent().unwrap())
-        .with_json(MANIFEST_OUTPUT)
+        .with_json(&manifest_output_no_readme())
         .run();
 }
 
@@ -104,5 +112,32 @@ fn cargo_read_manifest_cwd() {
         .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
         .build();
 
-    p.cargo("read-manifest").with_json(MANIFEST_OUTPUT).run();
+    p.cargo("read-manifest").with_json(&manifest_output_no_readme()).run();
+}
+
+#[cargo_test]
+fn cargo_read_manifest_default_readme() {
+    let readme_filenames = ["README.md", "README.txt", "README"];
+
+    for readme in readme_filenames.iter() {
+        let p = project()
+            .file("Cargo.toml", &basic_bin_manifest("foo"))
+            .file(readme, "Sample project")
+            .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
+            .build();
+
+        p.cargo("read-manifest").with_json(&manifest_output(&format!(r#""{}""#, readme))).run();
+    }
+}
+
+#[cargo_test]
+fn cargo_read_manifest_suppress_default_readme() {
+    let p = project()
+        .file("Cargo.toml", &basic_bin_manifest_with_readme("foo", "false"))
+        .file("README.txt", "Sample project")
+        .file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
+        .build();
+
+    p.cargo("read-manifest").with_json(&manifest_output_no_readme()).run();
 }
+