Skip to content

Commit

Permalink
Test for cargo new/init autodetct and ignore file rules
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Feb 11, 2022
1 parent 3e71240 commit 552b52a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
48 changes: 44 additions & 4 deletions tests/testsuite/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn simple_git_ignore_exists() {
# already existing elements were commented out\n\
\n\
#/target\n\
Cargo.lock\n",
/Cargo.lock\n",
);

cargo_process("build").cwd(&paths::root().join("foo")).run();
Expand All @@ -105,7 +105,7 @@ fn git_ignore_exists_no_conflicting_entries() {
# Added by cargo\n\
\n\
/target\n\
Cargo.lock\n",
/Cargo.lock\n",
);
}

Expand Down Expand Up @@ -337,7 +337,9 @@ fn git_autodetect() {
assert!(paths::root().join("Cargo.toml").is_file());
assert!(paths::root().join("src/lib.rs").is_file());
assert!(paths::root().join(".git").is_dir());
assert!(paths::root().join(".gitignore").is_file());
let path = paths::root().join(".gitignore");
assert!(paths::root().join(&path).is_file());
assert_eq!(fs::read_to_string(&path).unwrap(), "/target\n/Cargo.lock\n",);
}

#[cargo_test]
Expand All @@ -349,7 +351,45 @@ fn mercurial_autodetect() {
assert!(paths::root().join("Cargo.toml").is_file());
assert!(paths::root().join("src/lib.rs").is_file());
assert!(!paths::root().join(".git").is_dir());
assert!(paths::root().join(".hgignore").is_file());
let path = paths::root().join(".hgignore");
assert!(paths::root().join(&path).is_file());
assert_eq!(
fs::read_to_string(&path).unwrap(),
"^target/\n^Cargo.lock$\n",
);
}

#[cargo_test]
fn fossil_autodetect() {
fs::create_dir(&paths::root().join(".fossil")).unwrap();

cargo_process("init --lib").run();

assert!(paths::root().join("Cargo.toml").is_file());
assert!(paths::root().join("src/lib.rs").is_file());
assert!(!paths::root().join(".git").is_dir());
for path in [
".fossil-settings/ignore-glob",
".fossil-settings/clean-glob",
] {
let path = paths::root().join(path);
assert!(paths::root().join(&path).is_file());
assert_eq!(fs::read_to_string(&path).unwrap(), "target\nCargo.lock\n",);
}
}

#[cargo_test]
fn pijul_autodetect() {
fs::create_dir(&paths::root().join(".pijul")).unwrap();

cargo_process("init --lib").run();

assert!(paths::root().join("Cargo.toml").is_file());
assert!(paths::root().join("src/lib.rs").is_file());
assert!(!paths::root().join(".git").is_dir());
let path = paths::root().join(".ignore");
assert!(paths::root().join(&path).is_file());
assert_eq!(fs::read_to_string(&path).unwrap(), "/target\n/Cargo.lock\n",);
}

#[cargo_test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn simple_git() {

let fp = paths::root().join("foo/.gitignore");
let contents = fs::read_to_string(&fp).unwrap();
assert_eq!(contents, "/target\nCargo.lock\n",);
assert_eq!(contents, "/target\n/Cargo.lock\n",);

cargo_process("build").cwd(&paths::root().join("foo")).run();
}
Expand Down

0 comments on commit 552b52a

Please sign in to comment.