Skip to content

Commit 552b52a

Browse files
committed
Test for cargo new/init autodetct and ignore file rules
1 parent 3e71240 commit 552b52a

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

tests/testsuite/init.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn simple_git_ignore_exists() {
8383
# already existing elements were commented out\n\
8484
\n\
8585
#/target\n\
86-
Cargo.lock\n",
86+
/Cargo.lock\n",
8787
);
8888

8989
cargo_process("build").cwd(&paths::root().join("foo")).run();
@@ -105,7 +105,7 @@ fn git_ignore_exists_no_conflicting_entries() {
105105
# Added by cargo\n\
106106
\n\
107107
/target\n\
108-
Cargo.lock\n",
108+
/Cargo.lock\n",
109109
);
110110
}
111111

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

343345
#[cargo_test]
@@ -349,7 +351,45 @@ fn mercurial_autodetect() {
349351
assert!(paths::root().join("Cargo.toml").is_file());
350352
assert!(paths::root().join("src/lib.rs").is_file());
351353
assert!(!paths::root().join(".git").is_dir());
352-
assert!(paths::root().join(".hgignore").is_file());
354+
let path = paths::root().join(".hgignore");
355+
assert!(paths::root().join(&path).is_file());
356+
assert_eq!(
357+
fs::read_to_string(&path).unwrap(),
358+
"^target/\n^Cargo.lock$\n",
359+
);
360+
}
361+
362+
#[cargo_test]
363+
fn fossil_autodetect() {
364+
fs::create_dir(&paths::root().join(".fossil")).unwrap();
365+
366+
cargo_process("init --lib").run();
367+
368+
assert!(paths::root().join("Cargo.toml").is_file());
369+
assert!(paths::root().join("src/lib.rs").is_file());
370+
assert!(!paths::root().join(".git").is_dir());
371+
for path in [
372+
".fossil-settings/ignore-glob",
373+
".fossil-settings/clean-glob",
374+
] {
375+
let path = paths::root().join(path);
376+
assert!(paths::root().join(&path).is_file());
377+
assert_eq!(fs::read_to_string(&path).unwrap(), "target\nCargo.lock\n",);
378+
}
379+
}
380+
381+
#[cargo_test]
382+
fn pijul_autodetect() {
383+
fs::create_dir(&paths::root().join(".pijul")).unwrap();
384+
385+
cargo_process("init --lib").run();
386+
387+
assert!(paths::root().join("Cargo.toml").is_file());
388+
assert!(paths::root().join("src/lib.rs").is_file());
389+
assert!(!paths::root().join(".git").is_dir());
390+
let path = paths::root().join(".ignore");
391+
assert!(paths::root().join(&path).is_file());
392+
assert_eq!(fs::read_to_string(&path).unwrap(), "/target\n/Cargo.lock\n",);
353393
}
354394

355395
#[cargo_test]

tests/testsuite/new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn simple_git() {
8989

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

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

0 commit comments

Comments
 (0)