Skip to content

Commit 917fc99

Browse files
committed
Test cargo new with missing authors
- test case for missing name and email (author_without_user_or_email) - test case for handling email only (finds_author_email_only)
1 parent 5c09ad1 commit 917fc99

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/testsuite/new.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,39 @@ fn finds_author_user() {
195195
cargo_process("new foo").env("USER", "foo").run();
196196

197197
let toml = paths::root().join("foo/Cargo.toml");
198+
println!("{:?}", toml);
198199
let contents = fs::read_to_string(&toml).unwrap();
199200
assert!(contents.contains(r#"authors = ["foo"]"#));
200201
}
201202

203+
#[cargo_test]
204+
fn author_without_user_or_email() {
205+
create_empty_gitconfig();
206+
cargo_process("new foo")
207+
.env_remove("USER")
208+
.env_remove("USERNAME")
209+
.env_remove("NAME")
210+
.env_remove("EMAIL")
211+
.run();
212+
213+
let toml = paths::root().join("foo/Cargo.toml");
214+
let contents = fs::read_to_string(&toml).unwrap();
215+
assert!(contents.contains(r#"authors = []"#));
216+
}
217+
218+
#[cargo_test]
219+
fn finds_author_email_only() {
220+
create_empty_gitconfig();
221+
cargo_process("new foo")
222+
.env("EMAIL", "baz")
223+
.run();
224+
225+
let toml = paths::root().join("foo/Cargo.toml");
226+
println!("{:?}", toml);
227+
let contents = fs::read_to_string(&toml).unwrap();
228+
assert!(contents.contains(r#"authors = ["<baz>"]"#));
229+
}
230+
202231
#[cargo_test]
203232
fn finds_author_user_escaped() {
204233
create_empty_gitconfig();

0 commit comments

Comments
 (0)