Skip to content

Commit

Permalink
Auto merge of #3818 - jmatraszek:3814-run_proper_binary_main_rs, r=al…
Browse files Browse the repository at this point in the history
…excrichton

Fixes #3814
  • Loading branch information
bors committed Mar 12, 2017
2 parents 16d8706 + 53a32fe commit 4a3c0a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,12 @@ fn normalize(package_root: &Path,
if package_root.join(&default_bin_path.0).exists() {
default_bin_path // inferred from bin's name
} else {
PathValue(Path::new("src").join("main.rs"))
let path = PathValue(Path::new("src").join("main.rs"));
if package_root.join(&path.0).exists() {
path
} else {
PathValue(Path::new("src").join("bin").join("main.rs"))
}
}
});
let mut target = Target::bin_target(&bin.name(), package_root.join(&path.0),
Expand Down
21 changes: 21 additions & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2849,3 +2849,24 @@ fn run_proper_binary() {
assert_that(p.cargo_process("run").arg("--bin").arg("other"),
execs().with_status(0));
}

#[test]
fn run_proper_binary_main_rs() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
authors = []
version = "0.0.0"
[[bin]]
name = "foo"
"#)
.file("src/lib.rs", "")
.file("src/bin/main.rs", r#"
fn main() {
}
"#);

assert_that(p.cargo_process("run").arg("--bin").arg("foo"),
execs().with_status(0));
}

0 comments on commit 4a3c0a6

Please sign in to comment.