2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo read-manifest` command.
|
|
|
|
|
2020-05-30 21:14:50 +00:00
|
|
|
use cargo_test_support::{basic_bin_manifest, main_file, project};
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2020-05-25 07:07:16 +00:00
|
|
|
fn manifest_output(readme_value: &str) -> String {
|
|
|
|
format!(
|
|
|
|
r#"
|
|
|
|
{{
|
2018-04-18 08:08:18 +00:00
|
|
|
"authors": [
|
|
|
|
"wycats@example.com"
|
|
|
|
],
|
|
|
|
"categories": [],
|
2021-06-07 06:17:34 +00:00
|
|
|
"default_run": null,
|
2015-12-16 22:04:19 +00:00
|
|
|
"name":"foo",
|
2020-05-25 07:07:16 +00:00
|
|
|
"readme": {},
|
2020-10-01 09:22:49 +00:00
|
|
|
"homepage": null,
|
|
|
|
"documentation": null,
|
2018-04-18 08:08:18 +00:00
|
|
|
"repository": null,
|
2021-10-08 17:00:39 +00:00
|
|
|
"rust_version": null,
|
2015-12-16 22:04:19 +00:00
|
|
|
"version":"0.5.0",
|
2023-11-02 16:37:14 +00:00
|
|
|
"id":"path+file://[..]/foo#0.5.0",
|
2018-04-18 08:08:18 +00:00
|
|
|
"keywords": [],
|
2016-09-25 21:57:51 +00:00
|
|
|
"license": null,
|
|
|
|
"license_file": null,
|
2018-12-23 19:28:26 +00:00
|
|
|
"links": null,
|
2017-02-02 08:22:49 +00:00
|
|
|
"description": null,
|
2018-07-30 22:08:16 +00:00
|
|
|
"edition": "2015",
|
2015-12-16 22:04:19 +00:00
|
|
|
"source":null,
|
|
|
|
"dependencies":[],
|
2020-05-25 07:07:16 +00:00
|
|
|
"targets":[{{
|
2015-12-16 22:04:19 +00:00
|
|
|
"kind":["bin"],
|
2017-02-09 18:20:56 +00:00
|
|
|
"crate_types":["bin"],
|
2020-11-18 01:54:17 +00:00
|
|
|
"doc": true,
|
2019-05-17 15:33:53 +00:00
|
|
|
"doctest": false,
|
2020-07-12 14:52:31 +00:00
|
|
|
"test": true,
|
2018-07-31 22:29:48 +00:00
|
|
|
"edition": "2015",
|
2015-12-16 22:04:19 +00:00
|
|
|
"name":"foo",
|
2018-08-02 09:18:48 +00:00
|
|
|
"src_path":"[..]/foo/src/foo.rs"
|
2020-05-25 07:07:16 +00:00
|
|
|
}}],
|
|
|
|
"features":{{}},
|
2018-04-14 19:07:23 +00:00
|
|
|
"manifest_path":"[..]Cargo.toml",
|
2019-09-11 18:46:12 +00:00
|
|
|
"metadata": null,
|
|
|
|
"publish": null
|
2020-05-25 07:09:12 +00:00
|
|
|
}}"#,
|
|
|
|
readme_value
|
2020-05-25 07:07:16 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn manifest_output_no_readme() -> String {
|
|
|
|
manifest_output("null")
|
|
|
|
}
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2020-05-30 21:14:50 +00:00
|
|
|
pub fn basic_bin_manifest_with_readme(name: &str, readme_filename: &str) -> String {
|
|
|
|
format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
2020-05-30 21:14:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "{}"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
readme = {}
|
2020-05-30 21:14:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
2020-05-30 21:14:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "{}"
|
|
|
|
"#,
|
2020-05-30 21:14:50 +00:00
|
|
|
name, readme_filename, name
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_read_manifest_path_to_cargo_toml_relative() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-08-29 16:08:12 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("read-manifest --manifest-path foo/Cargo.toml")
|
|
|
|
.cwd(p.root().parent().unwrap())
|
2020-05-25 07:07:16 +00:00
|
|
|
.with_json(&manifest_output_no_readme())
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_read_manifest_path_to_cargo_toml_absolute() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-08-29 16:08:12 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("read-manifest --manifest-path")
|
|
|
|
.arg(p.root().join("Cargo.toml"))
|
|
|
|
.cwd(p.root().parent().unwrap())
|
2020-05-25 07:07:16 +00:00
|
|
|
.with_json(&manifest_output_no_readme())
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_read_manifest_path_to_cargo_toml_parent_relative() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-08-29 16:08:12 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("read-manifest --manifest-path foo")
|
|
|
|
.cwd(p.root().parent().unwrap())
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"[ERROR] the manifest-path must be \
|
|
|
|
a path to a Cargo.toml file",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_read_manifest_path_to_cargo_toml_parent_absolute() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-08-29 16:08:12 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("read-manifest --manifest-path")
|
|
|
|
.arg(p.root())
|
|
|
|
.cwd(p.root().parent().unwrap())
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"[ERROR] the manifest-path must be \
|
|
|
|
a path to a Cargo.toml file",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_read_manifest_cwd() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-08-29 16:08:12 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2015-08-29 16:08:12 +00:00
|
|
|
|
2020-05-25 07:09:12 +00:00
|
|
|
p.cargo("read-manifest")
|
|
|
|
.with_json(&manifest_output_no_readme())
|
|
|
|
.run();
|
2020-05-25 07:07:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 05:07:12 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn cargo_read_manifest_with_specified_readme() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&basic_bin_manifest_with_readme("foo", r#""SomeReadme.txt""#),
|
|
|
|
)
|
|
|
|
.file("SomeReadme.txt", "Sample Project")
|
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("read-manifest")
|
|
|
|
.with_json(&manifest_output(&format!(r#""{}""#, "SomeReadme.txt")))
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-05-25 07:07:16 +00:00
|
|
|
#[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();
|
|
|
|
|
2020-05-25 07:09:12 +00:00
|
|
|
p.cargo("read-manifest")
|
|
|
|
.with_json(&manifest_output(&format!(r#""{}""#, readme)))
|
|
|
|
.run();
|
2020-05-25 07:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn cargo_read_manifest_suppress_default_readme() {
|
|
|
|
let p = project()
|
2020-05-25 07:09:12 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&basic_bin_manifest_with_readme("foo", "false"),
|
|
|
|
)
|
2020-05-25 07:07:16 +00:00
|
|
|
.file("README.txt", "Sample project")
|
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
|
|
|
|
2020-05-25 07:09:12 +00:00
|
|
|
p.cargo("read-manifest")
|
|
|
|
.with_json(&manifest_output_no_readme())
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2020-05-29 05:07:12 +00:00
|
|
|
|
2020-06-09 07:03:15 +00:00
|
|
|
// If a file named README.md exists, and `readme = true`, the value `README.md` should be defaulted in.
|
2020-05-29 05:07:12 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn cargo_read_manifest_defaults_readme_if_true() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest_with_readme("foo", "true"))
|
2020-06-09 07:03:15 +00:00
|
|
|
.file("README.md", "Sample project")
|
2020-05-29 05:07:12 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("read-manifest")
|
2020-06-11 21:55:33 +00:00
|
|
|
.with_json(&manifest_output(r#""README.md""#))
|
2020-05-29 05:07:12 +00:00
|
|
|
.run();
|
|
|
|
}
|