Correct the situation with git repository test cases

This commit is contained in:
Lin Yihai 2023-11-10 14:22:03 +08:00
parent 2c503f89c4
commit 4577c0ec61

View file

@ -4,7 +4,7 @@ use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::publish::validate_crate_contents;
use cargo_test_support::registry::{self, Package};
use cargo_test_support::{
basic_manifest, cargo_process, git, path2url, paths, project, symlink_supported, t,
basic_manifest, cargo_process, git, path2url, paths, project, project_in, symlink_supported, t,
ProjectBuilder,
};
use flate2::read::GzDecoder;
@ -3138,8 +3138,9 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
fn include_files_called_target_project() {
// https://github.com/rust-lang/cargo/issues/12790
// files and folders called "target" should be included, unless they're the actual target directory
let p = init_project_files_called_target(project()).build();
let p = init_and_add_inner_target(project())
.file("target/foo.txt", "")
.build();
p.cargo("package -l")
.with_stdout(
@ -3161,9 +3162,9 @@ src/main.rs
fn include_files_called_target_git() {
// https://github.com/rust-lang/cargo/issues/12790
// files and folders called "target" should be included, unless they're the actual target directory
let p = git::new("all", |p| init_project_files_called_target(p));
let (p, repo) = git::new_repo("all", |p| init_and_add_inner_target(p));
// add target folder but not committed.
let _ = project_in(&repo.path().display().to_string()).file("target/foo.txt", "");
p.cargo("package -l")
.with_stdout(
"\
@ -3176,12 +3177,33 @@ data/target
derp/not_target/foo.txt
derp/target/foo.txt
src/main.rs
",
)
.run();
// if target is committed, it should be include.
let p = git::new("all", |p| {
init_and_add_inner_target(p).file("target/foo.txt", "")
});
p.cargo("package -l")
.with_stdout(
"\
.cargo_vcs_info.json
Cargo.lock
Cargo.toml
Cargo.toml.orig
data/not_target
data/target
derp/not_target/foo.txt
derp/target/foo.txt
src/main.rs
target/foo.txt
",
)
.run();
}
fn init_project_files_called_target(p: ProjectBuilder) -> ProjectBuilder {
fn init_and_add_inner_target(p: ProjectBuilder) -> ProjectBuilder {
p.file(
"Cargo.toml",
r#"
@ -3194,8 +3216,6 @@ fn init_project_files_called_target(p: ProjectBuilder) -> ProjectBuilder {
"#,
)
.file("src/main.rs", r#"fn main() { println!("hello"); }"#)
// actual target dir, should be excluded
.file("target/foo.txt", "")
// file called target, should be included
.file("data/target", "")
.file("data/not_target", "")