mirror of https://github.com/rust-lang/cargo
Fix failure with missing readme.
This commit is contained in:
parent
ee417cbc2f
commit
7a5f0369cb
|
@ -233,10 +233,13 @@ fn transmit(
|
|||
ref badges,
|
||||
ref links,
|
||||
} = *manifest.metadata();
|
||||
let readme_content = match *readme {
|
||||
Some(ref readme) => Some(paths::read(&pkg.root().join(readme))?),
|
||||
None => None,
|
||||
};
|
||||
let readme_content = readme
|
||||
.as_ref()
|
||||
.map(|readme| {
|
||||
paths::read(&pkg.root().join(readme))
|
||||
.chain_err(|| format!("failed to read `readme` file for package `{}`", pkg))
|
||||
})
|
||||
.transpose()?;
|
||||
if let Some(ref file) = *license_file {
|
||||
if !pkg.root().join(file).exists() {
|
||||
bail!("the license file `{}` does not exist", file)
|
||||
|
|
|
@ -1209,18 +1209,11 @@ impl TomlManifest {
|
|||
project.namespaced_features.unwrap_or(false),
|
||||
)?;
|
||||
|
||||
let readme = readme_for_project(package_root, project);
|
||||
if let Some(ref r) = readme {
|
||||
if !package_root.join(r).is_file() {
|
||||
bail!("readme file with name '{}' was not found", r);
|
||||
}
|
||||
};
|
||||
|
||||
let metadata = ManifestMetadata {
|
||||
description: project.description.clone(),
|
||||
homepage: project.homepage.clone(),
|
||||
documentation: project.documentation.clone(),
|
||||
readme,
|
||||
readme: readme_for_project(package_root, project),
|
||||
authors: project.authors.clone().unwrap_or_default(),
|
||||
license: project.license.clone(),
|
||||
license_file: project.license_file.clone(),
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use cargo_test_support::git::{self, repo};
|
||||
use cargo_test_support::paths;
|
||||
use cargo_test_support::registry::{self, registry_path, registry_url, Package};
|
||||
use cargo_test_support::{basic_manifest, project, publish};
|
||||
use cargo_test_support::{basic_manifest, no_such_file_err_msg, project, publish};
|
||||
use std::fs;
|
||||
|
||||
const CLEAN_FOO_JSON: &str = r#"
|
||||
|
@ -1341,3 +1341,43 @@ See [..]
|
|||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn publish_with_missing_readme() {
|
||||
registry::init();
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
authors = []
|
||||
license = "MIT"
|
||||
description = "foo"
|
||||
homepage = "https://example.com/"
|
||||
readme = "foo.md"
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --no-verify --token sekrit")
|
||||
.with_status(101)
|
||||
.with_stderr(&format!(
|
||||
"\
|
||||
[UPDATING] [..]
|
||||
[PACKAGING] foo v0.1.0 [..]
|
||||
[UPLOADING] foo v0.1.0 [..]
|
||||
[ERROR] failed to read `readme` file for package `foo v0.1.0 ([ROOT]/foo)`
|
||||
|
||||
Caused by:
|
||||
failed to read `[ROOT]/foo/foo.md`
|
||||
|
||||
Caused by:
|
||||
{}
|
||||
",
|
||||
no_such_file_err_msg()
|
||||
))
|
||||
.run();
|
||||
}
|
||||
|
|
|
@ -195,19 +195,6 @@ fn cargo_read_manifest_defaults_readme_if_true() {
|
|||
.build();
|
||||
|
||||
p.cargo("read-manifest")
|
||||
.with_json(&manifest_output(&format!(r#""{}""#, "README.md")))
|
||||
.with_json(&manifest_output(r#""README.md""#))
|
||||
.run();
|
||||
}
|
||||
|
||||
// If a file named README.md does not exist, and `readme = true`, it should panic.
|
||||
#[cargo_test]
|
||||
#[should_panic]
|
||||
fn cargo_read_manifest_panics_if_default_readme_not_found() {
|
||||
let p = project()
|
||||
.file("Cargo.toml", &basic_bin_manifest_with_readme("foo", "true"))
|
||||
.file("README.txt", "Sample project")
|
||||
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
||||
.build();
|
||||
|
||||
p.cargo("read-manifest").run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue