assert_that(p.cargo_process("build"),
execs().with_status(101)
- .with_stderr_contains(r#"[ERROR] couldn't read "[..]main.rs"[..]"#));
+ .with_stderr_contains("\
+[ERROR] failed to parse manifest at `[..]`
+
+Caused by:
+ can't find `foo` bin, specify bin.path"));
+}
+
+
+#[test]
+fn dirs_in_bin_dir_with_main_rs() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
+ "#)
+ .file("src/main.rs", "fn main() {}")
+ .file("src/bin/bar.rs", "fn main() {}")
+ .file("src/bin/bar2.rs", "fn main() {}")
+ .file("src/bin/bar3/main.rs", "fn main() {}")
+ .file("src/bin/bar4/main.rs", "fn main() {}");
+
+ assert_that(p.cargo_process("build"), execs().with_status(0));
+ assert_that(&p.bin("foo"), existing_file());
+ assert_that(&p.bin("bar"), existing_file());
+ assert_that(&p.bin("bar2"), existing_file());
+ assert_that(&p.bin("bar3"), existing_file());
+ assert_that(&p.bin("bar4"), existing_file());
+}
+
+#[test]
+fn dir_and_file_with_same_name_in_bin() {
+ // this should fail, because we have two binaries with the same name
+ let p = project("bar")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "bar"
+ version = "0.1.0"
+ authors = []
+ "#)
+ .file("src/main.rs", "fn main() {}")
+ .file("src/bin/foo.rs", "fn main() {}")
+ .file("src/bin/foo/main.rs", "fn main() {}");
+
+ assert_that(p.cargo_process("build"),
+ execs().with_status(101)
+ .with_stderr_contains("\
+[..]found duplicate binary name foo, but all binary targets must have a unique name[..]
+"));
+}
+
+#[test]
+fn inferred_path_in_src_bin_foo() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
+
+ [[bin]]
+ name = "bar"
+ # Note, no `path` key!
+ "#)
+ .file("src/bin/bar/main.rs", "fn main() {}");
+
+ assert_that(p.cargo_process("build"), execs().with_status(0));
+ assert_that(&p.bin("bar"), existing_file());
}
+
+ #[test]
+ fn same_metadata_different_directory() {
+ // A top-level crate built in two different workspaces should have the
+ // same metadata hash.
+ let p = project("foo1")
+ .file("Cargo.toml", &basic_bin_manifest("foo"))
+ .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
+ let output = t!(String::from_utf8(
+ t!(p.cargo_process("build").arg("-v").exec_with_output())
+ .stderr,
+ ));
+ let metadata = output
+ .split_whitespace()
+ .filter(|arg| arg.starts_with("metadata="))
+ .next()
+ .unwrap();
+
+ let p = project("foo2")
+ .file("Cargo.toml", &basic_bin_manifest("foo"))
+ .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
+
+ assert_that(
+ p.cargo_process("build").arg("-v"),
+ execs().with_status(0).with_stderr_contains(
+ format!("[..]{}[..]", metadata),
+ ),
+ );
+ }