Skip to content

Commit

Permalink
new/init: Don't include email if it is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Mar 31, 2019
1 parent ede459e commit 4282274
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,13 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
(Some(name), Some(email), _, _)
| (Some(name), None, _, Some(email))
| (None, Some(email), name, _)
| (None, None, name, Some(email)) => format!("{} <{}>", name, email),
| (None, None, name, Some(email)) => {
if email.is_empty() {
name
} else {
format!("{} <{}>", name, email)
}
}
(Some(name), None, _, None) | (None, None, name, None) => name,
};

Expand Down
11 changes: 11 additions & 0 deletions tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,14 @@ fn new_with_bad_edition() {
.with_status(1)
.run();
}

#[test]
fn new_with_blank_email() {
cargo_process("new foo")
.env("CARGO_NAME", "Sen")
.env("CARGO_EMAIL", "")
.run();

let contents = fs::read_to_string(paths::root().join("foo/Cargo.toml")).unwrap();
assert!(contents.contains(r#"authors = ["Sen"]"#), contents);
}

0 comments on commit 4282274

Please sign in to comment.