Skip to content

Commit

Permalink
Auto merge of #2440 - ThinTim:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Prevent the use of "test" as a crate name

Fixes #2432

?r @alexcrichton
  • Loading branch information
bors committed Mar 22, 2016
2 parents 132b82d + d30e963 commit 61ad6a0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ fn get_name<'a>(path: &'a Path, opts: &'a NewOptions, config: &Config) -> CargoR
}

fn check_name(name: &str) -> CargoResult<()> {
if name == "test" {
bail!("The name `{}` cannot be used as a crate name\n\
use --name to override crate name",
name)
}

for c in name.chars() {
if c.is_alphanumeric() { continue }
if c == '_' || c == '-' { continue }
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cargo_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ error = ERROR)));
assert_that(&foo.join("Cargo.toml"), is_not(existing_file()));
});

test!(reserved_name {
let test = &paths::root().join("test");
fs::create_dir_all(&test).unwrap();
assert_that(cargo_process("init").cwd(test.clone())
.env("USER", "foo"),
execs().with_status(101).with_stderr(&format!("\
{error} The name `test` cannot be used as a crate name\n\
use --name to override crate name
",
error = ERROR)));

assert_that(&test.join("Cargo.toml"), is_not(existing_file()));
});

test!(git_autodetect {
fs::create_dir(&paths::root().join(".git")).unwrap();

Expand Down
9 changes: 9 additions & 0 deletions tests/test_cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ use --name to override crate name",
error = ERROR)));
});

test!(reserved_name {
assert_that(cargo_process("new").arg("test"),
execs().with_status(101)
.with_stderr(&format!("\
{error} The name `test` cannot be used as a crate name\n\
use --name to override crate name",
error = ERROR)));
});

test!(rust_prefix_stripped {
assert_that(cargo_process("new").arg("rust-foo").env("USER", "foo"),
execs().with_status(0)
Expand Down

0 comments on commit 61ad6a0

Please sign in to comment.