diff --git a/tests/snapshots/init/auto_git.in b/tests/snapshots/init/auto_git.in new file mode 120000 index 00000000000..10ad175ba3f --- /dev/null +++ b/tests/snapshots/init/auto_git.in @@ -0,0 +1 @@ +empty-dir \ No newline at end of file diff --git a/tests/snapshots/init/auto_git.out/.gitignore b/tests/snapshots/init/auto_git.out/.gitignore new file mode 100644 index 00000000000..4fffb2f89cb --- /dev/null +++ b/tests/snapshots/init/auto_git.out/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/tests/snapshots/init/auto_git.out/Cargo.toml b/tests/snapshots/init/auto_git.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/auto_git.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/auto_git.out/src/lib.rs b/tests/snapshots/init/auto_git.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/auto_git.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/auto_git.stderr b/tests/snapshots/init/auto_git.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/auto_git.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/auto_git.stdout b/tests/snapshots/init/auto_git.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/bin_already_exists_explicit.in/src/main.rs b/tests/snapshots/init/bin_already_exists_explicit.in/src/main.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_explicit.in/src/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_explicit.out/Cargo.toml b/tests/snapshots/init/bin_already_exists_explicit.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_explicit.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/bin_already_exists_explicit.out/src/main.rs b/tests/snapshots/init/bin_already_exists_explicit.out/src/main.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_explicit.out/src/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_explicit.stderr b/tests/snapshots/init/bin_already_exists_explicit.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_explicit.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/bin_already_exists_explicit.stdout b/tests/snapshots/init/bin_already_exists_explicit.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/bin_already_exists_explicit_nosrc.in/main.rs b/tests/snapshots/init/bin_already_exists_explicit_nosrc.in/main.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_explicit_nosrc.in/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_explicit_nosrc.out/Cargo.toml b/tests/snapshots/init/bin_already_exists_explicit_nosrc.out/Cargo.toml new file mode 100644 index 00000000000..5c6c9158cf3 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_explicit_nosrc.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[[bin]] +name = "case" +path = "main.rs" diff --git a/tests/snapshots/init/bin_already_exists_explicit_nosrc.out/main.rs b/tests/snapshots/init/bin_already_exists_explicit_nosrc.out/main.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_explicit_nosrc.out/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_explicit_nosrc.stderr b/tests/snapshots/init/bin_already_exists_explicit_nosrc.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_explicit_nosrc.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/bin_already_exists_explicit_nosrc.stdout b/tests/snapshots/init/bin_already_exists_explicit_nosrc.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/bin_already_exists_implicit.in/src/main.rs b/tests/snapshots/init/bin_already_exists_implicit.in/src/main.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit.in/src/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_implicit.out/Cargo.toml b/tests/snapshots/init/bin_already_exists_implicit.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/bin_already_exists_implicit.out/src/main.rs b/tests/snapshots/init/bin_already_exists_implicit.out/src/main.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit.out/src/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_implicit.stderr b/tests/snapshots/init/bin_already_exists_implicit.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/bin_already_exists_implicit.stdout b/tests/snapshots/init/bin_already_exists_implicit.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/bin_already_exists_implicit_namenosrc.in/case.rs b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.in/case.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.in/case.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_implicit_namenosrc.out/Cargo.toml b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.out/Cargo.toml new file mode 100644 index 00000000000..8da5fe778d6 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[[bin]] +name = "case" +path = "case.rs" diff --git a/tests/snapshots/init/bin_already_exists_implicit_namenosrc.out/case.rs b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.out/case.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.out/case.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_implicit_namenosrc.stderr b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/bin_already_exists_implicit_namenosrc.stdout b/tests/snapshots/init/bin_already_exists_implicit_namenosrc.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/bin_already_exists_implicit_namesrc.in/src/case.rs b/tests/snapshots/init/bin_already_exists_implicit_namesrc.in/src/case.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_namesrc.in/src/case.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_implicit_namesrc.out/Cargo.toml b/tests/snapshots/init/bin_already_exists_implicit_namesrc.out/Cargo.toml new file mode 100644 index 00000000000..dec0aaea9a3 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_namesrc.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[[bin]] +name = "case" +path = "src/case.rs" diff --git a/tests/snapshots/init/bin_already_exists_implicit_namesrc.out/src/case.rs b/tests/snapshots/init/bin_already_exists_implicit_namesrc.out/src/case.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_namesrc.out/src/case.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_implicit_namesrc.stderr b/tests/snapshots/init/bin_already_exists_implicit_namesrc.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_namesrc.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/bin_already_exists_implicit_namesrc.stdout b/tests/snapshots/init/bin_already_exists_implicit_namesrc.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/bin_already_exists_implicit_nosrc.in/main.rs b/tests/snapshots/init/bin_already_exists_implicit_nosrc.in/main.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_nosrc.in/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_implicit_nosrc.out/Cargo.toml b/tests/snapshots/init/bin_already_exists_implicit_nosrc.out/Cargo.toml new file mode 100644 index 00000000000..5c6c9158cf3 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_nosrc.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[[bin]] +name = "case" +path = "main.rs" diff --git a/tests/snapshots/init/bin_already_exists_implicit_nosrc.out/main.rs b/tests/snapshots/init/bin_already_exists_implicit_nosrc.out/main.rs new file mode 100644 index 00000000000..65fdcf8da52 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_nosrc.out/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Check that our file is not overwritten") +} + diff --git a/tests/snapshots/init/bin_already_exists_implicit_nosrc.stderr b/tests/snapshots/init/bin_already_exists_implicit_nosrc.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/bin_already_exists_implicit_nosrc.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/bin_already_exists_implicit_nosrc.stdout b/tests/snapshots/init/bin_already_exists_implicit_nosrc.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/both_lib_and_bin.stderr b/tests/snapshots/init/both_lib_and_bin.stderr new file mode 100644 index 00000000000..9d635a42725 --- /dev/null +++ b/tests/snapshots/init/both_lib_and_bin.stderr @@ -0,0 +1 @@ +error: can't specify both lib and binary outputs diff --git a/tests/snapshots/init/both_lib_and_bin.stdout b/tests/snapshots/init/both_lib_and_bin.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/cant_create_library_when_both_binlib_present.in/case.rs b/tests/snapshots/init/cant_create_library_when_both_binlib_present.in/case.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/snapshots/init/cant_create_library_when_both_binlib_present.in/case.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/snapshots/init/cant_create_library_when_both_binlib_present.in/lib.rs b/tests/snapshots/init/cant_create_library_when_both_binlib_present.in/lib.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/cant_create_library_when_both_binlib_present.in/lib.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/cant_create_library_when_both_binlib_present.stderr b/tests/snapshots/init/cant_create_library_when_both_binlib_present.stderr new file mode 100644 index 00000000000..c08dce96bd9 --- /dev/null +++ b/tests/snapshots/init/cant_create_library_when_both_binlib_present.stderr @@ -0,0 +1 @@ +error: cannot have a package with multiple libraries, found both `case.rs` and `lib.rs` diff --git a/tests/snapshots/init/cant_create_library_when_both_binlib_present.stdout b/tests/snapshots/init/cant_create_library_when_both_binlib_present.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/confused_by_multiple_lib_files.in/lib.rs b/tests/snapshots/init/confused_by_multiple_lib_files.in/lib.rs new file mode 100644 index 00000000000..32116374407 --- /dev/null +++ b/tests/snapshots/init/confused_by_multiple_lib_files.in/lib.rs @@ -0,0 +1 @@ +fn f() { println!("lib.rs"); } diff --git a/tests/snapshots/init/confused_by_multiple_lib_files.in/src/lib.rs b/tests/snapshots/init/confused_by_multiple_lib_files.in/src/lib.rs new file mode 100644 index 00000000000..f71455a1a49 --- /dev/null +++ b/tests/snapshots/init/confused_by_multiple_lib_files.in/src/lib.rs @@ -0,0 +1 @@ +fn f() { println!("src/lib.rs"); } diff --git a/tests/snapshots/init/confused_by_multiple_lib_files.out/lib.rs b/tests/snapshots/init/confused_by_multiple_lib_files.out/lib.rs new file mode 100644 index 00000000000..32116374407 --- /dev/null +++ b/tests/snapshots/init/confused_by_multiple_lib_files.out/lib.rs @@ -0,0 +1 @@ +fn f() { println!("lib.rs"); } diff --git a/tests/snapshots/init/confused_by_multiple_lib_files.out/src/lib.rs b/tests/snapshots/init/confused_by_multiple_lib_files.out/src/lib.rs new file mode 100644 index 00000000000..f71455a1a49 --- /dev/null +++ b/tests/snapshots/init/confused_by_multiple_lib_files.out/src/lib.rs @@ -0,0 +1 @@ +fn f() { println!("src/lib.rs"); } diff --git a/tests/snapshots/init/confused_by_multiple_lib_files.stderr b/tests/snapshots/init/confused_by_multiple_lib_files.stderr new file mode 100644 index 00000000000..8dbd2aaf064 --- /dev/null +++ b/tests/snapshots/init/confused_by_multiple_lib_files.stderr @@ -0,0 +1 @@ +error: cannot have a package with multiple libraries, found both `src/lib.rs` and `lib.rs` diff --git a/tests/snapshots/init/confused_by_multiple_lib_files.stdout b/tests/snapshots/init/confused_by_multiple_lib_files.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/creates_binary_when_both_binlib_present.in/case.rs b/tests/snapshots/init/creates_binary_when_both_binlib_present.in/case.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_both_binlib_present.in/case.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/snapshots/init/creates_binary_when_both_binlib_present.in/lib.rs b/tests/snapshots/init/creates_binary_when_both_binlib_present.in/lib.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_both_binlib_present.in/lib.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/creates_binary_when_both_binlib_present.out/Cargo.toml b/tests/snapshots/init/creates_binary_when_both_binlib_present.out/Cargo.toml new file mode 100644 index 00000000000..675c888a5ab --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_both_binlib_present.out/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[[bin]] +name = "case" +path = "case.rs" + +[lib] +name = "case" +path = "lib.rs" diff --git a/tests/snapshots/init/creates_binary_when_both_binlib_present.out/case.rs b/tests/snapshots/init/creates_binary_when_both_binlib_present.out/case.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_both_binlib_present.out/case.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/snapshots/init/creates_binary_when_both_binlib_present.out/lib.rs b/tests/snapshots/init/creates_binary_when_both_binlib_present.out/lib.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_both_binlib_present.out/lib.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/creates_binary_when_both_binlib_present.stderr b/tests/snapshots/init/creates_binary_when_both_binlib_present.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_both_binlib_present.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/creates_binary_when_both_binlib_present.stdout b/tests/snapshots/init/creates_binary_when_both_binlib_present.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.in/case.rs b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.in/case.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.in/case.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.out/Cargo.toml b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.out/Cargo.toml new file mode 100644 index 00000000000..8da5fe778d6 --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[[bin]] +name = "case" +path = "case.rs" diff --git a/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.out/case.rs b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.out/case.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.out/case.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.stderr b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.stderr new file mode 100644 index 00000000000..ec428f31cc2 --- /dev/null +++ b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.stderr @@ -0,0 +1,2 @@ +warning: file `case.rs` seems to be a library file + Created binary (application) package diff --git a/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.stdout b/tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.in/case.rs b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.in/case.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.in/case.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.out/Cargo.toml b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.out/Cargo.toml new file mode 100644 index 00000000000..2c0464468e0 --- /dev/null +++ b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[lib] +name = "case" +path = "case.rs" diff --git a/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.out/case.rs b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.out/case.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.out/case.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.stderr b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.stderr new file mode 100644 index 00000000000..bf070e2da16 --- /dev/null +++ b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.stderr @@ -0,0 +1,2 @@ +warning: file `case.rs` seems to be a binary (application) file + Created library package diff --git a/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.stdout b/tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/empty-dir/.keep b/tests/snapshots/init/empty-dir/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/explicit_bin_with_git.in b/tests/snapshots/init/explicit_bin_with_git.in new file mode 120000 index 00000000000..10ad175ba3f --- /dev/null +++ b/tests/snapshots/init/explicit_bin_with_git.in @@ -0,0 +1 @@ +empty-dir \ No newline at end of file diff --git a/tests/snapshots/init/explicit_bin_with_git.out/.gitignore b/tests/snapshots/init/explicit_bin_with_git.out/.gitignore new file mode 100644 index 00000000000..ea8c4bf7f35 --- /dev/null +++ b/tests/snapshots/init/explicit_bin_with_git.out/.gitignore @@ -0,0 +1 @@ +/target diff --git a/tests/snapshots/init/explicit_bin_with_git.out/Cargo.toml b/tests/snapshots/init/explicit_bin_with_git.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/explicit_bin_with_git.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/explicit_bin_with_git.out/src/main.rs b/tests/snapshots/init/explicit_bin_with_git.out/src/main.rs new file mode 100644 index 00000000000..e7a11a969c0 --- /dev/null +++ b/tests/snapshots/init/explicit_bin_with_git.out/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/tests/snapshots/init/explicit_bin_with_git.stderr b/tests/snapshots/init/explicit_bin_with_git.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/explicit_bin_with_git.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/explicit_bin_with_git.stdout b/tests/snapshots/init/explicit_bin_with_git.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/formats_source.in/rustfmt.toml b/tests/snapshots/init/formats_source.in/rustfmt.toml new file mode 100644 index 00000000000..b196eaa2dc0 --- /dev/null +++ b/tests/snapshots/init/formats_source.in/rustfmt.toml @@ -0,0 +1 @@ +tab_spaces = 2 diff --git a/tests/snapshots/init/formats_source.out/Cargo.toml b/tests/snapshots/init/formats_source.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/formats_source.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/formats_source.out/rustfmt.toml b/tests/snapshots/init/formats_source.out/rustfmt.toml new file mode 100644 index 00000000000..b196eaa2dc0 --- /dev/null +++ b/tests/snapshots/init/formats_source.out/rustfmt.toml @@ -0,0 +1 @@ +tab_spaces = 2 diff --git a/tests/snapshots/init/formats_source.out/src/lib.rs b/tests/snapshots/init/formats_source.out/src/lib.rs new file mode 100644 index 00000000000..059dc12384e --- /dev/null +++ b/tests/snapshots/init/formats_source.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/formats_source.stderr b/tests/snapshots/init/formats_source.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/formats_source.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/formats_source.stdout b/tests/snapshots/init/formats_source.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/fossil_autodetect.in/.fossil/.keep b/tests/snapshots/init/fossil_autodetect.in/.fossil/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/fossil_autodetect.out/.fossil-settings/clean-glob b/tests/snapshots/init/fossil_autodetect.out/.fossil-settings/clean-glob new file mode 100644 index 00000000000..a9d37c560c6 --- /dev/null +++ b/tests/snapshots/init/fossil_autodetect.out/.fossil-settings/clean-glob @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/tests/snapshots/init/fossil_autodetect.out/.fossil-settings/ignore-glob b/tests/snapshots/init/fossil_autodetect.out/.fossil-settings/ignore-glob new file mode 100644 index 00000000000..a9d37c560c6 --- /dev/null +++ b/tests/snapshots/init/fossil_autodetect.out/.fossil-settings/ignore-glob @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/tests/snapshots/init/fossil_autodetect.out/Cargo.toml b/tests/snapshots/init/fossil_autodetect.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/fossil_autodetect.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/fossil_autodetect.out/src/lib.rs b/tests/snapshots/init/fossil_autodetect.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/fossil_autodetect.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/fossil_autodetect.stderr b/tests/snapshots/init/fossil_autodetect.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/fossil_autodetect.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/fossil_autodetect.stdout b/tests/snapshots/init/fossil_autodetect.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/git_autodetect.out/.gitignore b/tests/snapshots/init/git_autodetect.out/.gitignore new file mode 100644 index 00000000000..4fffb2f89cb --- /dev/null +++ b/tests/snapshots/init/git_autodetect.out/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/tests/snapshots/init/git_autodetect.out/Cargo.toml b/tests/snapshots/init/git_autodetect.out/Cargo.toml new file mode 100644 index 00000000000..1d9cfe3176c --- /dev/null +++ b/tests/snapshots/init/git_autodetect.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/git_autodetect.out/src/lib.rs b/tests/snapshots/init/git_autodetect.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/git_autodetect.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/git_autodetect.stderr b/tests/snapshots/init/git_autodetect.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/git_autodetect.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/git_autodetect.stdout b/tests/snapshots/init/git_autodetect.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.in/.gitignore b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.in/.gitignore new file mode 100644 index 00000000000..e3a2b0401a3 --- /dev/null +++ b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.in/.gitignore @@ -0,0 +1 @@ +**/some.file \ No newline at end of file diff --git a/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/.gitignore b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/.gitignore new file mode 100644 index 00000000000..e2e02f22f3c --- /dev/null +++ b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/.gitignore @@ -0,0 +1,6 @@ +**/some.file + +# Added by cargo + +/target +/Cargo.lock diff --git a/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/Cargo.toml b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/Cargo.toml new file mode 100644 index 00000000000..a6269fdcd23 --- /dev/null +++ b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2015" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/src/lib.rs b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.stderr b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.stdout b/tests/snapshots/init/git_ignore_exists_no_conflicting_entries.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/ignores_failure_to_format_source.in/rustfmt.toml b/tests/snapshots/init/ignores_failure_to_format_source.in/rustfmt.toml new file mode 100644 index 00000000000..b196eaa2dc0 --- /dev/null +++ b/tests/snapshots/init/ignores_failure_to_format_source.in/rustfmt.toml @@ -0,0 +1 @@ +tab_spaces = 2 diff --git a/tests/snapshots/init/ignores_failure_to_format_source.out/Cargo.toml b/tests/snapshots/init/ignores_failure_to_format_source.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/ignores_failure_to_format_source.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/ignores_failure_to_format_source.out/rustfmt.toml b/tests/snapshots/init/ignores_failure_to_format_source.out/rustfmt.toml new file mode 100644 index 00000000000..b196eaa2dc0 --- /dev/null +++ b/tests/snapshots/init/ignores_failure_to_format_source.out/rustfmt.toml @@ -0,0 +1 @@ +tab_spaces = 2 diff --git a/tests/snapshots/init/ignores_failure_to_format_source.out/src/lib.rs b/tests/snapshots/init/ignores_failure_to_format_source.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/ignores_failure_to_format_source.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/ignores_failure_to_format_source.stderr b/tests/snapshots/init/ignores_failure_to_format_source.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/ignores_failure_to_format_source.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/ignores_failure_to_format_source.stdout b/tests/snapshots/init/ignores_failure_to_format_source.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/implicit_bin_with_git.stderr b/tests/snapshots/init/implicit_bin_with_git.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/implicit_bin_with_git.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/implicit_bin_with_git.stdout b/tests/snapshots/init/implicit_bin_with_git.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/inferred_bin_with_git.in/main.rs b/tests/snapshots/init/inferred_bin_with_git.in/main.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/snapshots/init/inferred_bin_with_git.in/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/snapshots/init/inferred_bin_with_git.out/.gitignore b/tests/snapshots/init/inferred_bin_with_git.out/.gitignore new file mode 100644 index 00000000000..ea8c4bf7f35 --- /dev/null +++ b/tests/snapshots/init/inferred_bin_with_git.out/.gitignore @@ -0,0 +1 @@ +/target diff --git a/tests/snapshots/init/inferred_bin_with_git.out/Cargo.toml b/tests/snapshots/init/inferred_bin_with_git.out/Cargo.toml new file mode 100644 index 00000000000..5c6c9158cf3 --- /dev/null +++ b/tests/snapshots/init/inferred_bin_with_git.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[[bin]] +name = "case" +path = "main.rs" diff --git a/tests/snapshots/init/inferred_bin_with_git.out/main.rs b/tests/snapshots/init/inferred_bin_with_git.out/main.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/snapshots/init/inferred_bin_with_git.out/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/snapshots/init/inferred_bin_with_git.stderr b/tests/snapshots/init/inferred_bin_with_git.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/inferred_bin_with_git.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/inferred_bin_with_git.stdout b/tests/snapshots/init/inferred_bin_with_git.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/inferred_lib_with_git.in/lib.rs b/tests/snapshots/init/inferred_lib_with_git.in/lib.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/inferred_lib_with_git.in/lib.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/inferred_lib_with_git.out/.gitignore b/tests/snapshots/init/inferred_lib_with_git.out/.gitignore new file mode 100644 index 00000000000..4fffb2f89cb --- /dev/null +++ b/tests/snapshots/init/inferred_lib_with_git.out/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/tests/snapshots/init/inferred_lib_with_git.out/Cargo.toml b/tests/snapshots/init/inferred_lib_with_git.out/Cargo.toml new file mode 100644 index 00000000000..39e95fe94a3 --- /dev/null +++ b/tests/snapshots/init/inferred_lib_with_git.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[lib] +name = "case" +path = "lib.rs" diff --git a/tests/snapshots/init/inferred_lib_with_git.out/lib.rs b/tests/snapshots/init/inferred_lib_with_git.out/lib.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/inferred_lib_with_git.out/lib.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/inferred_lib_with_git.stderr b/tests/snapshots/init/inferred_lib_with_git.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/inferred_lib_with_git.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/inferred_lib_with_git.stdout b/tests/snapshots/init/inferred_lib_with_git.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/invalid_dir_name.stderr b/tests/snapshots/init/invalid_dir_name.stderr new file mode 100644 index 00000000000..86d2c665f62 --- /dev/null +++ b/tests/snapshots/init/invalid_dir_name.stderr @@ -0,0 +1,8 @@ +error: invalid character `.` in package name: `foo.bar`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters) +If you need a package name to not match the directory name, consider using --name flag. +If you need a binary with the name "foo.bar", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/foo.bar.rs` or change the name in Cargo.toml with: + + [[bin]] + name = "foo.bar" + path = "src/main.rs" + diff --git a/tests/snapshots/init/invalid_dir_name.stdout b/tests/snapshots/init/invalid_dir_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/lib_already_exists_nosrc.in/lib.rs b/tests/snapshots/init/lib_already_exists_nosrc.in/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/lib_already_exists_nosrc.out/Cargo.toml b/tests/snapshots/init/lib_already_exists_nosrc.out/Cargo.toml new file mode 100644 index 00000000000..39e95fe94a3 --- /dev/null +++ b/tests/snapshots/init/lib_already_exists_nosrc.out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[lib] +name = "case" +path = "lib.rs" diff --git a/tests/snapshots/init/lib_already_exists_nosrc.out/lib.rs b/tests/snapshots/init/lib_already_exists_nosrc.out/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/lib_already_exists_nosrc.stderr b/tests/snapshots/init/lib_already_exists_nosrc.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/lib_already_exists_nosrc.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/lib_already_exists_nosrc.stdout b/tests/snapshots/init/lib_already_exists_nosrc.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/lib_already_exists_src.in/src/lib.rs b/tests/snapshots/init/lib_already_exists_src.in/src/lib.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/lib_already_exists_src.in/src/lib.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/lib_already_exists_src.out/Cargo.toml b/tests/snapshots/init/lib_already_exists_src.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/lib_already_exists_src.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/lib_already_exists_src.out/src/lib.rs b/tests/snapshots/init/lib_already_exists_src.out/src/lib.rs new file mode 100644 index 00000000000..59760b549cd --- /dev/null +++ b/tests/snapshots/init/lib_already_exists_src.out/src/lib.rs @@ -0,0 +1 @@ +fn f() {} diff --git a/tests/snapshots/init/lib_already_exists_src.stderr b/tests/snapshots/init/lib_already_exists_src.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/lib_already_exists_src.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/lib_already_exists_src.stdout b/tests/snapshots/init/lib_already_exists_src.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/mercurial_autodetect.in/.hg/.keep b/tests/snapshots/init/mercurial_autodetect.in/.hg/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/mercurial_autodetect.out/.hgignore b/tests/snapshots/init/mercurial_autodetect.out/.hgignore new file mode 100644 index 00000000000..1ae6a78bbc9 --- /dev/null +++ b/tests/snapshots/init/mercurial_autodetect.out/.hgignore @@ -0,0 +1,2 @@ +^target/ +^Cargo.lock$ diff --git a/tests/snapshots/init/mercurial_autodetect.out/Cargo.toml b/tests/snapshots/init/mercurial_autodetect.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/mercurial_autodetect.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/mercurial_autodetect.out/src/lib.rs b/tests/snapshots/init/mercurial_autodetect.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/mercurial_autodetect.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/mercurial_autodetect.stderr b/tests/snapshots/init/mercurial_autodetect.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/mercurial_autodetect.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/mercurial_autodetect.stdout b/tests/snapshots/init/mercurial_autodetect.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/multibin_project_name_clash.in/case.rs b/tests/snapshots/init/multibin_project_name_clash.in/case.rs new file mode 100644 index 00000000000..b31221118a6 --- /dev/null +++ b/tests/snapshots/init/multibin_project_name_clash.in/case.rs @@ -0,0 +1 @@ +fn main() { println!("foo.rs"); } diff --git a/tests/snapshots/init/multibin_project_name_clash.in/main.rs b/tests/snapshots/init/multibin_project_name_clash.in/main.rs new file mode 100644 index 00000000000..7937627b906 --- /dev/null +++ b/tests/snapshots/init/multibin_project_name_clash.in/main.rs @@ -0,0 +1 @@ +fn main() { println!("main.rs"); } diff --git a/tests/snapshots/init/multibin_project_name_clash.out/case.rs b/tests/snapshots/init/multibin_project_name_clash.out/case.rs new file mode 100644 index 00000000000..b31221118a6 --- /dev/null +++ b/tests/snapshots/init/multibin_project_name_clash.out/case.rs @@ -0,0 +1 @@ +fn main() { println!("foo.rs"); } diff --git a/tests/snapshots/init/multibin_project_name_clash.out/main.rs b/tests/snapshots/init/multibin_project_name_clash.out/main.rs new file mode 100644 index 00000000000..7937627b906 --- /dev/null +++ b/tests/snapshots/init/multibin_project_name_clash.out/main.rs @@ -0,0 +1 @@ +fn main() { println!("main.rs"); } diff --git a/tests/snapshots/init/multibin_project_name_clash.stderr b/tests/snapshots/init/multibin_project_name_clash.stderr new file mode 100644 index 00000000000..21a1dabee6d --- /dev/null +++ b/tests/snapshots/init/multibin_project_name_clash.stderr @@ -0,0 +1,4 @@ +error: multiple possible binary sources found: + main.rs + case.rs +cannot automatically generate Cargo.toml as the main target would be ambiguous diff --git a/tests/snapshots/init/multibin_project_name_clash.stdout b/tests/snapshots/init/multibin_project_name_clash.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/no_filename.stderr b/tests/snapshots/init/no_filename.stderr new file mode 100644 index 00000000000..bd087ec9052 --- /dev/null +++ b/tests/snapshots/init/no_filename.stderr @@ -0,0 +1 @@ +error: cannot auto-detect package name from path "/" ; use --name to override diff --git a/tests/snapshots/init/no_filename.stdout b/tests/snapshots/init/no_filename.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/pijul_autodetect.in/.pijul/.keep b/tests/snapshots/init/pijul_autodetect.in/.pijul/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/pijul_autodetect.out/.ignore b/tests/snapshots/init/pijul_autodetect.out/.ignore new file mode 100644 index 00000000000..4fffb2f89cb --- /dev/null +++ b/tests/snapshots/init/pijul_autodetect.out/.ignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/tests/snapshots/init/pijul_autodetect.out/Cargo.toml b/tests/snapshots/init/pijul_autodetect.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/pijul_autodetect.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/pijul_autodetect.out/src/lib.rs b/tests/snapshots/init/pijul_autodetect.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/pijul_autodetect.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/pijul_autodetect.stderr b/tests/snapshots/init/pijul_autodetect.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/pijul_autodetect.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/pijul_autodetect.stdout b/tests/snapshots/init/pijul_autodetect.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/reserved_name.stderr b/tests/snapshots/init/reserved_name.stderr new file mode 100644 index 00000000000..748971bdffd --- /dev/null +++ b/tests/snapshots/init/reserved_name.stderr @@ -0,0 +1,8 @@ +error: the name `test` cannot be used as a package name, it conflicts with Rust's built-in test library +If you need a package name to not match the directory name, consider using --name flag. +If you need a binary with the name "test", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/test.rs` or change the name in Cargo.toml with: + + [[bin]] + name = "test" + path = "src/main.rs" + diff --git a/tests/snapshots/init/reserved_name.stdout b/tests/snapshots/init/reserved_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/simple_bin.in b/tests/snapshots/init/simple_bin.in new file mode 120000 index 00000000000..10ad175ba3f --- /dev/null +++ b/tests/snapshots/init/simple_bin.in @@ -0,0 +1 @@ +empty-dir \ No newline at end of file diff --git a/tests/snapshots/init/simple_bin.out/Cargo.toml b/tests/snapshots/init/simple_bin.out/Cargo.toml new file mode 100644 index 00000000000..a6269fdcd23 --- /dev/null +++ b/tests/snapshots/init/simple_bin.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2015" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/simple_bin.out/src/main.rs b/tests/snapshots/init/simple_bin.out/src/main.rs new file mode 100644 index 00000000000..e7a11a969c0 --- /dev/null +++ b/tests/snapshots/init/simple_bin.out/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/tests/snapshots/init/simple_bin.stderr b/tests/snapshots/init/simple_bin.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/simple_bin.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/simple_bin.stdout b/tests/snapshots/init/simple_bin.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/simple_git.in b/tests/snapshots/init/simple_git.in new file mode 120000 index 00000000000..10ad175ba3f --- /dev/null +++ b/tests/snapshots/init/simple_git.in @@ -0,0 +1 @@ +empty-dir \ No newline at end of file diff --git a/tests/snapshots/init/simple_git.out/.gitignore b/tests/snapshots/init/simple_git.out/.gitignore new file mode 100644 index 00000000000..4fffb2f89cb --- /dev/null +++ b/tests/snapshots/init/simple_git.out/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/tests/snapshots/init/simple_git.out/Cargo.toml b/tests/snapshots/init/simple_git.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/simple_git.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/simple_git.out/src/lib.rs b/tests/snapshots/init/simple_git.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/simple_git.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/simple_git.stderr b/tests/snapshots/init/simple_git.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/simple_git.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/simple_git.stdout b/tests/snapshots/init/simple_git.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/simple_git_ignore_exists.in/.gitignore b/tests/snapshots/init/simple_git_ignore_exists.in/.gitignore new file mode 100644 index 00000000000..d0f753ef71f --- /dev/null +++ b/tests/snapshots/init/simple_git_ignore_exists.in/.gitignore @@ -0,0 +1,2 @@ +/target +**/some.file \ No newline at end of file diff --git a/tests/snapshots/init/simple_git_ignore_exists.out/.gitignore b/tests/snapshots/init/simple_git_ignore_exists.out/.gitignore new file mode 100644 index 00000000000..4447742e0eb --- /dev/null +++ b/tests/snapshots/init/simple_git_ignore_exists.out/.gitignore @@ -0,0 +1,9 @@ +/target +**/some.file + +# Added by cargo +# +# already existing elements were commented out + +#/target +/Cargo.lock diff --git a/tests/snapshots/init/simple_git_ignore_exists.out/Cargo.toml b/tests/snapshots/init/simple_git_ignore_exists.out/Cargo.toml new file mode 100644 index 00000000000..a6269fdcd23 --- /dev/null +++ b/tests/snapshots/init/simple_git_ignore_exists.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2015" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/simple_git_ignore_exists.out/src/lib.rs b/tests/snapshots/init/simple_git_ignore_exists.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/simple_git_ignore_exists.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/simple_git_ignore_exists.stderr b/tests/snapshots/init/simple_git_ignore_exists.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/simple_git_ignore_exists.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/simple_git_ignore_exists.stdout b/tests/snapshots/init/simple_git_ignore_exists.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/simple_hg.in b/tests/snapshots/init/simple_hg.in new file mode 120000 index 00000000000..10ad175ba3f --- /dev/null +++ b/tests/snapshots/init/simple_hg.in @@ -0,0 +1 @@ +empty-dir \ No newline at end of file diff --git a/tests/snapshots/init/simple_hg.out/.hgignore b/tests/snapshots/init/simple_hg.out/.hgignore new file mode 100644 index 00000000000..1ae6a78bbc9 --- /dev/null +++ b/tests/snapshots/init/simple_hg.out/.hgignore @@ -0,0 +1,2 @@ +^target/ +^Cargo.lock$ diff --git a/tests/snapshots/init/simple_hg.out/Cargo.toml b/tests/snapshots/init/simple_hg.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/simple_hg.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/simple_hg.out/src/lib.rs b/tests/snapshots/init/simple_hg.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/simple_hg.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/simple_hg.stderr b/tests/snapshots/init/simple_hg.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/simple_hg.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/simple_hg.stdout b/tests/snapshots/init/simple_hg.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/simple_hg_ignore_exists.in/.hg/.keep b/tests/snapshots/init/simple_hg_ignore_exists.in/.hg/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/simple_hg_ignore_exists.in/.hgignore b/tests/snapshots/init/simple_hg_ignore_exists.in/.hgignore new file mode 100644 index 00000000000..0fc474f2793 --- /dev/null +++ b/tests/snapshots/init/simple_hg_ignore_exists.in/.hgignore @@ -0,0 +1 @@ +^/somefile \ No newline at end of file diff --git a/tests/snapshots/init/simple_hg_ignore_exists.out/.hgignore b/tests/snapshots/init/simple_hg_ignore_exists.out/.hgignore new file mode 100644 index 00000000000..2ab1fce0101 --- /dev/null +++ b/tests/snapshots/init/simple_hg_ignore_exists.out/.hgignore @@ -0,0 +1,6 @@ +^/somefile + +# Added by cargo + +^target/ +^Cargo.lock$ diff --git a/tests/snapshots/init/simple_hg_ignore_exists.out/Cargo.toml b/tests/snapshots/init/simple_hg_ignore_exists.out/Cargo.toml new file mode 100644 index 00000000000..dcdb8da2c97 --- /dev/null +++ b/tests/snapshots/init/simple_hg_ignore_exists.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/simple_hg_ignore_exists.out/src/lib.rs b/tests/snapshots/init/simple_hg_ignore_exists.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/simple_hg_ignore_exists.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/simple_hg_ignore_exists.stderr b/tests/snapshots/init/simple_hg_ignore_exists.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/simple_hg_ignore_exists.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/simple_hg_ignore_exists.stdout b/tests/snapshots/init/simple_hg_ignore_exists.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/simple_lib.in b/tests/snapshots/init/simple_lib.in new file mode 120000 index 00000000000..10ad175ba3f --- /dev/null +++ b/tests/snapshots/init/simple_lib.in @@ -0,0 +1 @@ +empty-dir \ No newline at end of file diff --git a/tests/snapshots/init/simple_lib.out/Cargo.toml b/tests/snapshots/init/simple_lib.out/Cargo.toml new file mode 100644 index 00000000000..a6269fdcd23 --- /dev/null +++ b/tests/snapshots/init/simple_lib.out/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "case" +version = "0.1.0" +edition = "2015" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/simple_lib.out/src/lib.rs b/tests/snapshots/init/simple_lib.out/src/lib.rs new file mode 100644 index 00000000000..1b4a90c9383 --- /dev/null +++ b/tests/snapshots/init/simple_lib.out/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/tests/snapshots/init/simple_lib.stderr b/tests/snapshots/init/simple_lib.stderr new file mode 100644 index 00000000000..f459bf2260d --- /dev/null +++ b/tests/snapshots/init/simple_lib.stderr @@ -0,0 +1 @@ + Created library package diff --git a/tests/snapshots/init/simple_lib.stdout b/tests/snapshots/init/simple_lib.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/unknown_flags.stderr b/tests/snapshots/init/unknown_flags.stderr new file mode 100644 index 00000000000..93e111d841c --- /dev/null +++ b/tests/snapshots/init/unknown_flags.stderr @@ -0,0 +1,8 @@ +error: Found argument '--flag' which wasn't expected, or isn't valid in this context + + If you tried to supply `--flag` as a value rather than a flag, use `-- --flag` + +USAGE: + cargo[EXE] init + +For more information try --help diff --git a/tests/snapshots/init/unknown_flags.stdout b/tests/snapshots/init/unknown_flags.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/with_argument.in/foo/.keep b/tests/snapshots/init/with_argument.in/foo/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/init/with_argument.out/foo/Cargo.toml b/tests/snapshots/init/with_argument.out/foo/Cargo.toml new file mode 100644 index 00000000000..1d9cfe3176c --- /dev/null +++ b/tests/snapshots/init/with_argument.out/foo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/snapshots/init/with_argument.out/foo/src/main.rs b/tests/snapshots/init/with_argument.out/foo/src/main.rs new file mode 100644 index 00000000000..e7a11a969c0 --- /dev/null +++ b/tests/snapshots/init/with_argument.out/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/tests/snapshots/init/with_argument.stderr b/tests/snapshots/init/with_argument.stderr new file mode 100644 index 00000000000..3847e4e4a26 --- /dev/null +++ b/tests/snapshots/init/with_argument.stderr @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/snapshots/init/with_argument.stdout b/tests/snapshots/init/with_argument.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/init.rs b/tests/testsuite/init.rs index 992ec285d1d..ebb05f3885a 100644 --- a/tests/testsuite/init.rs +++ b/tests/testsuite/init.rs @@ -1,16 +1,11 @@ //! Tests for the `cargo init` command. -use cargo_test_support::{command_is_available, paths, Execs}; -use std::env; +use cargo_test_support::compare::assert; +use cargo_test_support::prelude::*; +use cargo_test_support::{command_is_available, paths, Project}; use std::fs; use std::process::Command; -fn cargo_process(s: &str) -> Execs { - let mut execs = cargo_test_support::cargo_process(s); - execs.cwd(&paths::root()).env("HOME", &paths::home()); - execs -} - fn mercurial_available() -> bool { let result = Command::new("hg") .arg("--version") @@ -25,573 +20,591 @@ fn mercurial_available() -> bool { #[cargo_test] fn simple_lib() { - cargo_process("init --lib --vcs none --edition 2015") - .with_stderr("[CREATED] library package") - .run(); + let project = Project::from_template("tests/snapshots/init/simple_lib.in"); + let project_root = &project.root(); - assert!(paths::root().join("Cargo.toml").is_file()); - assert!(paths::root().join("src/lib.rs").is_file()); - assert!(!paths::root().join(".gitignore").is_file()); + snapbox::cmd::Command::cargo() + .arg_line("init --lib --vcs none --edition 2015") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/simple_lib.stdout") + .stderr_matches_path("tests/snapshots/init/simple_lib.stderr"); - cargo_process("build").run(); + assert().subset_matches("tests/snapshots/init/simple_lib.out", project_root); + assert!(!project_root.join(".gitignore").is_file()); + + snapbox::cmd::Command::cargo() + .current_dir(project_root) + .arg("build") + .assert() + .success(); + assert!(!project.bin("foo").is_file()); } #[cargo_test] fn simple_bin() { - let path = paths::root().join("foo"); - fs::create_dir(&path).unwrap(); - cargo_process("init --bin --vcs none --edition 2015") - .cwd(&path) - .with_stderr("[CREATED] binary (application) package") - .run(); + let project = Project::from_template("tests/snapshots/init/simple_bin.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --bin --vcs none --edition 2015") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/simple_bin.stdout") + .stderr_matches_path("tests/snapshots/init/simple_bin.stderr"); - assert!(paths::root().join("foo/Cargo.toml").is_file()); - assert!(paths::root().join("foo/src/main.rs").is_file()); + assert().subset_matches("tests/snapshots/init/simple_bin.out", project_root); + assert!(!project_root.join(".gitignore").is_file()); - cargo_process("build").cwd(&path).run(); - assert!(paths::root() - .join(&format!("foo/target/debug/foo{}", env::consts::EXE_SUFFIX)) - .is_file()); + snapbox::cmd::Command::cargo() + .current_dir(project_root) + .arg("build") + .assert() + .success(); + assert!(project.bin("case").is_file()); } #[cargo_test] fn simple_git_ignore_exists() { - // write a .gitignore file with two entries - fs::create_dir_all(paths::root().join("foo")).unwrap(); - fs::write( - paths::root().join("foo/.gitignore"), - "/target\n**/some.file", - ) - .unwrap(); - - cargo_process("init --lib foo --edition 2015").run(); - - assert!(paths::root().is_dir()); - assert!(paths::root().join("foo/Cargo.toml").is_file()); - assert!(paths::root().join("foo/src/lib.rs").is_file()); - assert!(paths::root().join("foo/.git").is_dir()); - assert!(paths::root().join("foo/.gitignore").is_file()); - - let fp = paths::root().join("foo/.gitignore"); - let contents = fs::read_to_string(fp).unwrap(); - assert_eq!( - contents, - "/target\n\ - **/some.file\n\n\ - # Added by cargo\n\ - #\n\ - # already existing elements were commented out\n\ - \n\ - #/target\n\ - /Cargo.lock\n", + let project = Project::from_template("tests/snapshots/init/simple_git_ignore_exists.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --lib --edition 2015") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/simple_git_ignore_exists.stdout") + .stderr_matches_path("tests/snapshots/init/simple_git_ignore_exists.stderr"); + + assert().subset_matches( + "tests/snapshots/init/simple_git_ignore_exists.out", + project_root, ); + assert!(project_root.join(".git").is_dir()); - cargo_process("build").cwd(&paths::root().join("foo")).run(); + snapbox::cmd::Command::cargo() + .current_dir(project_root) + .arg("build") + .assert() + .success(); } #[cargo_test] fn git_ignore_exists_no_conflicting_entries() { - // write a .gitignore file with one entry - fs::create_dir_all(paths::root().join("foo")).unwrap(); - fs::write(paths::root().join("foo/.gitignore"), "**/some.file").unwrap(); - - cargo_process("init --lib foo --edition 2015").run(); - - let fp = paths::root().join("foo/.gitignore"); - let contents = fs::read_to_string(&fp).unwrap(); - assert_eq!( - contents, - "**/some.file\n\n\ - # Added by cargo\n\ - \n\ - /target\n\ - /Cargo.lock\n", + let project = + Project::from_template("tests/snapshots/init/git_ignore_exists_no_conflicting_entries.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --lib --edition 2015") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/git_ignore_exists_no_conflicting_entries.stdout") + .stderr_matches_path( + "tests/snapshots/init/git_ignore_exists_no_conflicting_entries.stderr", + ); + + assert().subset_matches( + "tests/snapshots/init/git_ignore_exists_no_conflicting_entries.out", + project_root, ); + assert!(project_root.join(".git").is_dir()); } #[cargo_test] fn both_lib_and_bin() { - cargo_process("init --lib --bin") - .with_status(101) - .with_stderr("[ERROR] can't specify both lib and binary outputs") - .run(); -} - -fn bin_already_exists(explicit: bool, rellocation: &str) { - let path = paths::root().join("foo"); - fs::create_dir_all(&path.join("src")).unwrap(); - - let sourcefile_path = path.join(rellocation); - - let content = r#" - fn main() { - println!("Hello, world 2!"); - } - "#; + let cwd = paths::root(); - fs::write(&sourcefile_path, content).unwrap(); + snapbox::cmd::Command::cargo() + .arg_line("init --lib --bin") + .current_dir(&cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/init/both_lib_and_bin.stdout") + .stderr_matches_path("tests/snapshots/init/both_lib_and_bin.stderr"); - if explicit { - cargo_process("init --bin --vcs none").cwd(&path).run(); - } else { - cargo_process("init --vcs none").cwd(&path).run(); - } - - assert!(paths::root().join("foo/Cargo.toml").is_file()); - assert!(!paths::root().join("foo/src/lib.rs").is_file()); - - // Check that our file is not overwritten - let new_content = fs::read_to_string(&sourcefile_path).unwrap(); - assert_eq!(content, new_content); + assert!(!cwd.join("Cargo.toml").is_file()); } #[cargo_test] fn bin_already_exists_explicit() { - bin_already_exists(true, "src/main.rs") + let project = Project::from_template("tests/snapshots/init/bin_already_exists_explicit.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --bin --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/bin_already_exists_explicit.stdout") + .stderr_matches_path("tests/snapshots/init/bin_already_exists_explicit.stderr"); + + assert().subset_matches( + "tests/snapshots/init/bin_already_exists_explicit.out", + project_root, + ); } #[cargo_test] fn bin_already_exists_implicit() { - bin_already_exists(false, "src/main.rs") + let project = Project::from_template("tests/snapshots/init/bin_already_exists_implicit.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/bin_already_exists_implicit.stdout") + .stderr_matches_path("tests/snapshots/init/bin_already_exists_implicit.stderr"); + + assert().subset_matches( + "tests/snapshots/init/bin_already_exists_implicit.out", + project_root, + ); } #[cargo_test] fn bin_already_exists_explicit_nosrc() { - bin_already_exists(true, "main.rs") + let project = + Project::from_template("tests/snapshots/init/bin_already_exists_explicit_nosrc.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --bin --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/bin_already_exists_explicit_nosrc.stdout") + .stderr_matches_path("tests/snapshots/init/bin_already_exists_explicit_nosrc.stderr"); + + assert().subset_matches( + "tests/snapshots/init/bin_already_exists_explicit_nosrc.out", + project_root, + ); + assert!(!project_root.join("src").is_dir()); } #[cargo_test] fn bin_already_exists_implicit_nosrc() { - bin_already_exists(false, "main.rs") + let project = + Project::from_template("tests/snapshots/init/bin_already_exists_implicit_nosrc.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/bin_already_exists_implicit_nosrc.stdout") + .stderr_matches_path("tests/snapshots/init/bin_already_exists_implicit_nosrc.stderr"); + + assert().subset_matches( + "tests/snapshots/init/bin_already_exists_implicit_nosrc.out", + project_root, + ); + assert!(!project_root.join("src").is_dir()); } #[cargo_test] fn bin_already_exists_implicit_namenosrc() { - bin_already_exists(false, "foo.rs") + let project = + Project::from_template("tests/snapshots/init/bin_already_exists_implicit_namenosrc.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/bin_already_exists_implicit_namenosrc.stdout") + .stderr_matches_path("tests/snapshots/init/bin_already_exists_implicit_namenosrc.stderr"); + + assert().subset_matches( + "tests/snapshots/init/bin_already_exists_implicit_namenosrc.out", + project_root, + ); + assert!(!project_root.join("src").is_dir()); } #[cargo_test] fn bin_already_exists_implicit_namesrc() { - bin_already_exists(false, "src/foo.rs") + let project = + Project::from_template("tests/snapshots/init/bin_already_exists_implicit_namesrc.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/bin_already_exists_implicit_namesrc.stdout") + .stderr_matches_path("tests/snapshots/init/bin_already_exists_implicit_namesrc.stderr"); + + assert().subset_matches( + "tests/snapshots/init/bin_already_exists_implicit_namesrc.out", + project_root, + ); + assert!(!project_root.join("src/main.rs").is_file()); } #[cargo_test] fn confused_by_multiple_lib_files() { - let path = paths::root().join("foo"); - fs::create_dir_all(&path.join("src")).unwrap(); - - let path1 = path.join("src/lib.rs"); - fs::write(path1, r#"fn qqq () { println!("Hello, world 2!"); }"#).unwrap(); - - let path2 = path.join("lib.rs"); - fs::write(path2, r#" fn qqq () { println!("Hello, world 3!"); }"#).unwrap(); - - cargo_process("init --vcs none") - .cwd(&path) - .with_status(101) - .with_stderr( - "[ERROR] cannot have a package with multiple libraries, \ - found both `src/lib.rs` and `lib.rs`", - ) - .run(); - - assert!(!paths::root().join("foo/Cargo.toml").is_file()); + let project = Project::from_template("tests/snapshots/init/confused_by_multiple_lib_files.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --vcs none") + .current_dir(project_root) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/init/confused_by_multiple_lib_files.stdout") + .stderr_matches_path("tests/snapshots/init/confused_by_multiple_lib_files.stderr"); + + assert().subset_matches( + "tests/snapshots/init/confused_by_multiple_lib_files.out", + project_root, + ); + assert!(!project_root.join("Cargo.toml").is_file()); } #[cargo_test] fn multibin_project_name_clash() { - let path = paths::root().join("foo"); - fs::create_dir(&path).unwrap(); - - let path1 = path.join("foo.rs"); - fs::write(path1, r#"fn main () { println!("Hello, world 2!"); }"#).unwrap(); - - let path2 = path.join("main.rs"); - fs::write(path2, r#"fn main () { println!("Hello, world 3!"); }"#).unwrap(); - - cargo_process("init --lib --vcs none") - .cwd(&path) - .with_status(101) - .with_stderr( - "\ -[ERROR] multiple possible binary sources found: - main.rs - foo.rs -cannot automatically generate Cargo.toml as the main target would be ambiguous -", - ) - .run(); - - assert!(!paths::root().join("foo/Cargo.toml").is_file()); -} - -fn lib_already_exists(rellocation: &str) { - let path = paths::root().join("foo"); - fs::create_dir_all(&path.join("src")).unwrap(); - - let sourcefile_path = path.join(rellocation); - - let content = "pub fn qqq() {}"; - fs::write(&sourcefile_path, content).unwrap(); - - cargo_process("init --vcs none").cwd(&path).run(); - - assert!(paths::root().join("foo/Cargo.toml").is_file()); - assert!(!paths::root().join("foo/src/main.rs").is_file()); - - // Check that our file is not overwritten - let new_content = fs::read_to_string(&sourcefile_path).unwrap(); - assert_eq!(content, new_content); + let project = Project::from_template("tests/snapshots/init/multibin_project_name_clash.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --lib --vcs none") + .current_dir(project_root) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/init/multibin_project_name_clash.stdout") + .stderr_matches_path("tests/snapshots/init/multibin_project_name_clash.stderr"); + + assert().subset_matches( + "tests/snapshots/init/multibin_project_name_clash.out", + project_root, + ); + assert!(!project_root.join("Cargo.toml").is_file()); } #[cargo_test] fn lib_already_exists_src() { - lib_already_exists("src/lib.rs"); + let project = Project::from_template("tests/snapshots/init/lib_already_exists_src.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/lib_already_exists_src.stdout") + .stderr_matches_path("tests/snapshots/init/lib_already_exists_src.stderr"); + + assert().subset_matches( + "tests/snapshots/init/lib_already_exists_src.out", + project_root, + ); + assert!(!project_root.join("src/main.rs").is_file()); } #[cargo_test] fn lib_already_exists_nosrc() { - lib_already_exists("lib.rs"); + let project = Project::from_template("tests/snapshots/init/lib_already_exists_nosrc.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/lib_already_exists_nosrc.stdout") + .stderr_matches_path("tests/snapshots/init/lib_already_exists_nosrc.stderr"); + + assert().subset_matches( + "tests/snapshots/init/lib_already_exists_nosrc.out", + project_root, + ); + assert!(!project_root.join("src/main.rs").is_file()); } #[cargo_test] fn simple_git() { - cargo_process("init --lib --vcs git").run(); + let project = Project::from_template("tests/snapshots/init/simple_git.in"); + let project_root = &project.root(); - 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()); + snapbox::cmd::Command::cargo() + .arg_line("init --lib --vcs git") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/simple_git.stdout") + .stderr_matches_path("tests/snapshots/init/simple_git.stderr"); + + assert().subset_matches("tests/snapshots/init/simple_git.out", project_root); + assert!(project_root.join(".git").is_dir()); } #[cargo_test] fn auto_git() { - cargo_process("init --lib").run(); + let project = Project::from_template("tests/snapshots/init/auto_git.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --lib") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/auto_git.stdout") + .stderr_matches_path("tests/snapshots/init/auto_git.stderr"); - 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()); + assert().subset_matches("tests/snapshots/init/auto_git.out", &project_root); + assert!(project_root.join(".git").is_dir()); } #[cargo_test] fn invalid_dir_name() { let foo = &paths::root().join("foo.bar"); - fs::create_dir_all(&foo).unwrap(); - cargo_process("init") - .cwd(foo.clone()) - .with_status(101) - .with_stderr( - "\ -[ERROR] invalid character `.` in package name: `foo.bar`, [..] -If you need a package name to not match the directory name, consider using --name flag. -If you need a binary with the name \"foo.bar\", use a valid package name, \ -and set the binary name to be different from the package. \ -This can be done by setting the binary filename to `src/bin/foo.bar.rs` \ -or change the name in Cargo.toml with: - - [[bin]] - name = \"foo.bar\" - path = \"src/main.rs\" - -", - ) - .run(); + fs::create_dir_all(foo).unwrap(); + + snapbox::cmd::Command::cargo() + .arg_line("init") + .current_dir(foo) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/init/invalid_dir_name.stdout") + .stderr_matches_path("tests/snapshots/init/invalid_dir_name.stderr"); assert!(!foo.join("Cargo.toml").is_file()); } #[cargo_test] fn reserved_name() { - let test = &paths::root().join("test"); - fs::create_dir_all(&test).unwrap(); - cargo_process("init") - .cwd(test.clone()) - .with_status(101) - .with_stderr( - "\ -[ERROR] the name `test` cannot be used as a package name, it conflicts [..]\n\ -If you need a package name to not match the directory name, consider using --name flag. -If you need a binary with the name \"test\", use a valid package name, \ -and set the binary name to be different from the package. \ -This can be done by setting the binary filename to `src/bin/test.rs` \ -or change the name in Cargo.toml with: - - [[bin]] - name = \"test\" - path = \"src/main.rs\" - -", - ) - .run(); + let project_root = &paths::root().join("test"); + fs::create_dir_all(project_root).unwrap(); + + snapbox::cmd::Command::cargo() + .arg_line("init") + .current_dir(project_root) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/init/reserved_name.stdout") + .stderr_matches_path("tests/snapshots/init/reserved_name.stderr"); - assert!(!test.join("Cargo.toml").is_file()); + assert!(!project_root.join("Cargo.toml").is_file()); } #[cargo_test] fn git_autodetect() { - fs::create_dir(&paths::root().join(".git")).unwrap(); + let project_root = &paths::root().join("foo"); + // Need to create `.git` dir manually because it cannot be tracked under a git repo + fs::create_dir_all(project_root.join(".git")).unwrap(); - cargo_process("init --lib").run(); + snapbox::cmd::Command::cargo() + .arg_line("init --lib") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/git_autodetect.stdout") + .stderr_matches_path("tests/snapshots/init/git_autodetect.stderr"); - 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(".gitignore"); - assert!(paths::root().join(&path).is_file()); - assert_eq!(fs::read_to_string(&path).unwrap(), "/target\n/Cargo.lock\n",); + assert().subset_matches("tests/snapshots/init/git_autodetect.out", project_root); + assert!(project_root.join(".git").is_dir()); } #[cargo_test] fn mercurial_autodetect() { - fs::create_dir(&paths::root().join(".hg")).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(".hgignore"); - assert!(paths::root().join(&path).is_file()); - assert_eq!( - fs::read_to_string(&path).unwrap(), - "^target/\n^Cargo.lock$\n", + let project = Project::from_template("tests/snapshots/init/mercurial_autodetect.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --lib") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/mercurial_autodetect.stdout") + .stderr_matches_path("tests/snapshots/init/mercurial_autodetect.stderr"); + + assert().subset_matches( + "tests/snapshots/init/mercurial_autodetect.out", + project_root, ); + assert!(!project_root.join(".git").is_dir()); } #[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] -fn gitignore_appended_not_replaced() { - fs::create_dir(&paths::root().join(".git")).unwrap(); - - fs::write(&paths::root().join(".gitignore"), "qqqqqq\n").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()); - assert!(paths::root().join(".gitignore").is_file()); - - let contents = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); - assert!(contents.contains("qqqqqq")); -} - -#[cargo_test] -fn gitignore_added_newline_in_existing() { - fs::create_dir(&paths::root().join(".git")).unwrap(); + let project = Project::from_template("tests/snapshots/init/fossil_autodetect.in"); + let project_root = &project.root(); - fs::write(&paths::root().join(".gitignore"), "first").unwrap(); + snapbox::cmd::Command::cargo() + .arg_line("init --lib") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/fossil_autodetect.stdout") + .stderr_matches_path("tests/snapshots/init/fossil_autodetect.stderr"); - cargo_process("init --lib").run(); - - assert!(paths::root().join(".gitignore").is_file()); - - let contents = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); - assert!(contents.starts_with("first\n")); -} - -#[cargo_test] -fn gitignore_no_newline_in_new() { - fs::create_dir(&paths::root().join(".git")).unwrap(); - - cargo_process("init --lib").run(); - - assert!(paths::root().join(".gitignore").is_file()); - - let contents = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); - assert!(!contents.starts_with('\n')); -} - -#[cargo_test] -fn mercurial_added_newline_in_existing() { - fs::create_dir(&paths::root().join(".hg")).unwrap(); - - fs::write(&paths::root().join(".hgignore"), "first").unwrap(); - - cargo_process("init --lib").run(); - - assert!(paths::root().join(".hgignore").is_file()); - - let contents = fs::read_to_string(&paths::root().join(".hgignore")).unwrap(); - assert!(contents.starts_with("first\n")); + assert().subset_matches("tests/snapshots/init/fossil_autodetect.out", project_root); + assert!(!project_root.join(".git").is_dir()); } #[cargo_test] -fn mercurial_no_newline_in_new() { - fs::create_dir(&paths::root().join(".hg")).unwrap(); - - cargo_process("init --lib").run(); - - assert!(paths::root().join(".hgignore").is_file()); - - let contents = fs::read_to_string(&paths::root().join(".hgignore")).unwrap(); - assert!(!contents.starts_with('\n')); -} - -#[cargo_test] -fn terminating_newline_in_new_git_ignore() { - cargo_process("init --vcs git --lib").run(); +fn pijul_autodetect() { + let project = Project::from_template("tests/snapshots/init/pijul_autodetect.in"); + let project_root = &project.root(); - let content = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); + snapbox::cmd::Command::cargo() + .arg_line("init --lib") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/pijul_autodetect.stdout") + .stderr_matches_path("tests/snapshots/init/pijul_autodetect.stderr"); - let mut last_chars = content.chars().rev(); - assert_eq!(last_chars.next(), Some('\n')); - assert_ne!(last_chars.next(), Some('\n')); + assert().subset_matches("tests/snapshots/init/pijul_autodetect.out", project_root); + assert!(!project_root.join(".git").is_dir()); } #[cargo_test] -fn terminating_newline_in_new_mercurial_ignore() { +fn simple_hg() { if !mercurial_available() { return; } - cargo_process("init --vcs hg --lib").run(); - let content = fs::read_to_string(&paths::root().join(".hgignore")).unwrap(); + let project = Project::from_template("tests/snapshots/init/simple_hg.in"); + let project_root = &project.root(); - let mut last_chars = content.chars().rev(); - assert_eq!(last_chars.next(), Some('\n')); - assert_ne!(last_chars.next(), Some('\n')); -} - -#[cargo_test] -fn terminating_newline_in_existing_git_ignore() { - fs::create_dir(&paths::root().join(".git")).unwrap(); - fs::write(&paths::root().join(".gitignore"), b"first").unwrap(); - - cargo_process("init --lib").run(); + snapbox::cmd::Command::cargo() + .arg_line("init --lib --vcs hg") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/simple_hg.stdout") + .stderr_matches_path("tests/snapshots/init/simple_hg.stderr"); - let content = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); - - let mut last_chars = content.chars().rev(); - assert_eq!(last_chars.next(), Some('\n')); - assert_ne!(last_chars.next(), Some('\n')); + assert().subset_matches("tests/snapshots/init/simple_hg.out", project_root); + assert!(!project_root.join(".git").is_dir()); } #[cargo_test] -fn terminating_newline_in_existing_mercurial_ignore() { - fs::create_dir(&paths::root().join(".hg")).unwrap(); - fs::write(&paths::root().join(".hgignore"), b"first").unwrap(); - - cargo_process("init --lib").run(); +fn simple_hg_ignore_exists() { + let project = Project::from_template("tests/snapshots/init/simple_hg_ignore_exists.in"); + let project_root = &project.root(); - let content = fs::read_to_string(&paths::root().join(".hgignore")).unwrap(); + snapbox::cmd::Command::cargo() + .arg_line("init --lib") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/simple_hg_ignore_exists.stdout") + .stderr_matches_path("tests/snapshots/init/simple_hg_ignore_exists.stderr"); - let mut last_chars = content.chars().rev(); - assert_eq!(last_chars.next(), Some('\n')); - assert_ne!(last_chars.next(), Some('\n')); + assert().subset_matches( + "tests/snapshots/init/simple_hg_ignore_exists.out", + project_root, + ); + assert!(!project_root.join(".git").is_dir()); } #[cargo_test] -fn cargo_lock_gitignored_if_lib1() { - fs::create_dir(&paths::root().join(".git")).unwrap(); +fn inferred_lib_with_git() { + let project = Project::from_template("tests/snapshots/init/inferred_lib_with_git.in"); + let project_root = &project.root(); - cargo_process("init --lib --vcs git").run(); + snapbox::cmd::Command::cargo() + .arg_line("init --vcs git") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/inferred_lib_with_git.stdout") + .stderr_matches_path("tests/snapshots/init/inferred_lib_with_git.stderr"); - assert!(paths::root().join(".gitignore").is_file()); - - let contents = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); - assert!(contents.contains(r#"Cargo.lock"#)); + assert().subset_matches( + "tests/snapshots/init/inferred_lib_with_git.out", + project_root, + ); } #[cargo_test] -fn cargo_lock_gitignored_if_lib2() { - fs::create_dir(&paths::root().join(".git")).unwrap(); - - fs::write(&paths::root().join("lib.rs"), "").unwrap(); - - cargo_process("init --vcs git").run(); +fn explicit_bin_with_git() { + let project = Project::from_template("tests/snapshots/init/explicit_bin_with_git.in"); + let project_root = &project.root(); - assert!(paths::root().join(".gitignore").is_file()); + snapbox::cmd::Command::cargo() + .arg_line("init --vcs git --bin") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/explicit_bin_with_git.stdout") + .stderr_matches_path("tests/snapshots/init/explicit_bin_with_git.stderr"); - let contents = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); - assert!(contents.contains(r#"Cargo.lock"#)); + assert().subset_matches( + "tests/snapshots/init/explicit_bin_with_git.out", + project_root, + ); } #[cargo_test] -fn cargo_lock_not_gitignored_if_bin1() { - fs::create_dir(&paths::root().join(".git")).unwrap(); - - cargo_process("init --vcs git --bin").run(); +fn inferred_bin_with_git() { + let project = Project::from_template("tests/snapshots/init/inferred_bin_with_git.in"); + let project_root = &project.root(); - assert!(paths::root().join(".gitignore").is_file()); + snapbox::cmd::Command::cargo() + .arg_line("init --vcs git") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/inferred_bin_with_git.stdout") + .stderr_matches_path("tests/snapshots/init/inferred_bin_with_git.stderr"); - let contents = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); - assert!(!contents.contains(r#"Cargo.lock"#)); + assert().subset_matches( + "tests/snapshots/init/inferred_bin_with_git.out", + project_root, + ); } #[cargo_test] -fn cargo_lock_not_gitignored_if_bin2() { - fs::create_dir(&paths::root().join(".git")).unwrap(); - - fs::write(&paths::root().join("main.rs"), "").unwrap(); - - cargo_process("init --vcs git").run(); +fn with_argument() { + let project = Project::from_template("tests/snapshots/init/with_argument.in"); + let project_root = &project.root(); - assert!(paths::root().join(".gitignore").is_file()); + snapbox::cmd::Command::cargo() + .arg_line("init foo --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/with_argument.stdout") + .stderr_matches_path("tests/snapshots/init/with_argument.stderr"); - let contents = fs::read_to_string(&paths::root().join(".gitignore")).unwrap(); - assert!(!contents.contains(r#"Cargo.lock"#)); -} - -#[cargo_test] -fn with_argument() { - cargo_process("init foo --vcs none").run(); - assert!(paths::root().join("foo/Cargo.toml").is_file()); + assert().subset_matches("tests/snapshots/init/with_argument.out", project_root); } #[cargo_test] fn unknown_flags() { - cargo_process("init foo --flag") - .with_status(1) - .with_stderr_contains( - "error: Found argument '--flag' which wasn't expected, or isn't valid in this context", - ) - .run(); + snapbox::cmd::Command::cargo() + .arg_line("init foo --flag") + .current_dir(paths::root()) + .assert() + .code(1) + .stdout_matches_path("tests/snapshots/init/unknown_flags.stdout") + .stderr_matches_path("tests/snapshots/init/unknown_flags.stderr"); } #[cfg(not(windows))] #[cargo_test] fn no_filename() { - cargo_process("init /") - .with_status(101) - .with_stderr( - "[ERROR] cannot auto-detect package name from path \"/\" ; use --name to override" - .to_string(), - ) - .run(); + snapbox::cmd::Command::cargo() + .arg_line("init /") + .current_dir(paths::root()) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/init/no_filename.stdout") + .stderr_matches_path("tests/snapshots/init/no_filename.stderr"); } #[cargo_test] @@ -600,114 +613,127 @@ fn formats_source() { return; } - fs::write(&paths::root().join("rustfmt.toml"), "tab_spaces = 2").unwrap(); + let project = Project::from_template("tests/snapshots/init/formats_source.in"); + let project_root = &project.root(); - cargo_process("init --lib") - .with_stderr("[CREATED] library package") - .run(); + snapbox::cmd::Command::cargo() + .arg_line("init --lib --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/formats_source.stdout") + .stderr_matches_path("tests/snapshots/init/formats_source.stderr"); - assert_eq!( - fs::read_to_string(paths::root().join("src/lib.rs")).unwrap(), - r#"#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -} -"# - ); + assert().subset_matches("tests/snapshots/init/formats_source.out", project_root); } #[cargo_test] fn ignores_failure_to_format_source() { - cargo_process("init --lib") + let project = + Project::from_template("tests/snapshots/init/ignores_failure_to_format_source.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --lib --vcs none") .env("PATH", "") // pretend that `rustfmt` is missing - .with_stderr("[CREATED] library package") - .run(); - - assert_eq!( - fs::read_to_string(paths::root().join("src/lib.rs")).unwrap(), - r#"#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -} -"# + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/ignores_failure_to_format_source.stdout") + .stderr_matches_path("tests/snapshots/init/ignores_failure_to_format_source.stderr"); + + assert().subset_matches( + "tests/snapshots/init/ignores_failure_to_format_source.out", + project_root, ); } #[cargo_test] -fn creates_binary_when_instructed_and_has_lib_file_no_warning() { - let path = paths::root().join("foo"); - fs::create_dir(&path).unwrap(); - fs::write(path.join("foo.rs"), "fn not_main() {}").unwrap(); - cargo_process("init --bin") - .cwd(&path) - .with_stderr( - "\ -[WARNING] file `foo.rs` seems to be a library file -[CREATED] binary (application) package -", +fn creates_binary_when_instructed_and_has_lib_file() { + let project = Project::from_template( + "tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.in", + ); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --bin --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path( + "tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.stdout", ) - .run(); + .stderr_matches_path( + "tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.stderr", + ); - let cargo_toml = fs::read_to_string(path.join("Cargo.toml")).unwrap(); - assert!(cargo_toml.contains("[[bin]]")); - assert!(!cargo_toml.contains("[lib]")); + assert().subset_matches( + "tests/snapshots/init/creates_binary_when_instructed_and_has_lib_file.out", + project_root, + ); } #[cargo_test] fn creates_library_when_instructed_and_has_bin_file() { - let path = paths::root().join("foo"); - fs::create_dir(&path).unwrap(); - fs::write(path.join("foo.rs"), "fn main() {}").unwrap(); - cargo_process("init --lib") - .cwd(&path) - .with_stderr( - "\ -[WARNING] file `foo.rs` seems to be a binary (application) file -[CREATED] library package -", + let project = Project::from_template( + "tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.in", + ); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --lib --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path( + "tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.stdout", ) - .run(); + .stderr_matches_path( + "tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.stderr", + ); - let cargo_toml = fs::read_to_string(path.join("Cargo.toml")).unwrap(); - assert!(!cargo_toml.contains("[[bin]]")); - assert!(cargo_toml.contains("[lib]")); + assert().subset_matches( + "tests/snapshots/init/creates_library_when_instructed_and_has_bin_file.out", + project_root, + ); } #[cargo_test] fn creates_binary_when_both_binlib_present() { - let path = paths::root().join("foo"); - fs::create_dir(&path).unwrap(); - fs::write(path.join("foo.rs"), "fn main() {}").unwrap(); - fs::write(path.join("lib.rs"), "fn notmain() {}").unwrap(); - cargo_process("init --bin") - .cwd(&path) - .with_stderr("[CREATED] binary (application) package") - .run(); - - let cargo_toml = fs::read_to_string(path.join("Cargo.toml")).unwrap(); - assert!(cargo_toml.contains("[[bin]]")); - assert!(cargo_toml.contains("[lib]")); + let project = + Project::from_template("tests/snapshots/init/creates_binary_when_both_binlib_present.in"); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --bin --vcs none") + .current_dir(project_root) + .assert() + .success() + .stdout_matches_path("tests/snapshots/init/creates_binary_when_both_binlib_present.stdout") + .stderr_matches_path("tests/snapshots/init/creates_binary_when_both_binlib_present.stderr"); + + assert().subset_matches( + "tests/snapshots/init/creates_binary_when_both_binlib_present.out", + project_root, + ); } #[cargo_test] fn cant_create_library_when_both_binlib_present() { - let path = paths::root().join("foo"); - fs::create_dir(&path).unwrap(); - fs::write(path.join("foo.rs"), "fn main() {}").unwrap(); - fs::write(path.join("lib.rs"), "fn notmain() {}").unwrap(); - cargo_process("init --lib") - .cwd(&path) - .with_status(101) - .with_stderr( - "[ERROR] cannot have a package with multiple libraries, found both `foo.rs` and `lib.rs`" - ) - .run(); + let project = Project::from_template( + "tests/snapshots/init/cant_create_library_when_both_binlib_present.in", + ); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo() + .arg_line("init --lib") + .current_dir(project_root) + .assert() + .code(101) + .stdout_matches_path( + "tests/snapshots/init/cant_create_library_when_both_binlib_present.stdout", + ) + .stderr_matches_path( + "tests/snapshots/init/cant_create_library_when_both_binlib_present.stderr", + ); }