human("No `package` or `project` section found.")
}));
+ if project.name.trim().is_empty() {
+ return Err(human("package name cannot be an empty string."))
+ }
+
let pkgid = try!(project.to_package_id(source_id));
let metadata = pkgid.generate_metadata();
Some(ref bins) => {
let bin = layout.main();
+ for target in bins {
+ try!(validate_binary_name(target));
+ }
+
bins.iter().map(|t| {
if bin.is_some() && t.path.is_none() {
TomlTarget {
}
fn validate_library_name(target: &TomlTarget) -> CargoResult<()> {
- if target.name.contains("-") {
+ if target.name.trim().is_empty() {
+ Err(human(format!("library target names cannot be empty.")))
+ } else if target.name.contains("-") {
Err(human(format!("library target names cannot contain hyphens: {}",
target.name)))
} else {
}
}
+fn validate_binary_name(target: &TomlTarget) -> CargoResult<()> {
+ if target.name.trim().is_empty() {
+ Err(human(format!("binary target names cannot be empty.")))
+ } else {
+ Ok(())
+ }
+}
+
fn process_dependencies<F>(cx: &mut Context,
new_deps: Option<&HashMap<String, TomlDependency>>,
mut f: F) -> CargoResult<()>
});
+test!(cargo_compile_with_invalid_package_name {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = ""
+ authors = []
+ version = "0.0.0"
+ "#);
+
+ assert_that(p.cargo_process("build"),
+ execs()
+ .with_status(101)
+ .with_stderr("\
+failed to parse manifest at `[..]`
+
+Caused by:
+ package name cannot be an empty string.
+"))
+});
+
+test!(cargo_compile_with_invalid_bin_target_name {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ authors = []
+ version = "0.0.0"
+
+ [[bin]]
+ name = ""
+ "#);
+
+ assert_that(p.cargo_process("build"),
+ execs()
+ .with_status(101)
+ .with_stderr("\
+failed to parse manifest at `[..]`
+
+Caused by:
+ binary target names cannot be empty.
+"))
+});
+
+test!(cargo_compile_with_invalid_lib_target_name {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ authors = []
+ version = "0.0.0"
+
+ [lib]
+ name = ""
+ "#);
+
+ assert_that(p.cargo_process("build"),
+ execs()
+ .with_status(101)
+ .with_stderr("\
+failed to parse manifest at `[..]`
+
+Caused by:
+ library target names cannot be empty.
+"))
+});
+
test!(cargo_compile_without_manifest {
let tmpdir = TempDir::new("cargo").unwrap();
let p = ProjectBuilder::new("foo", tmpdir.path().to_path_buf());