summaryrefslogtreecommitdiffstats
path: root/src/tools/cargo/tests/testsuite/package.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/cargo/tests/testsuite/package.rs')
-rw-r--r--src/tools/cargo/tests/testsuite/package.rs239
1 files changed, 230 insertions, 9 deletions
diff --git a/src/tools/cargo/tests/testsuite/package.rs b/src/tools/cargo/tests/testsuite/package.rs
index 4ec4fc0d6..371157e4e 100644
--- a/src/tools/cargo/tests/testsuite/package.rs
+++ b/src/tools/cargo/tests/testsuite/package.rs
@@ -5,6 +5,7 @@ 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,
+ ProjectBuilder,
};
use flate2::read::GzDecoder;
use std::fs::{self, read_to_string, File};
@@ -54,7 +55,19 @@ src/main.rs
",
)
.run();
- p.cargo("package").with_stdout("").run();
+ p.cargo("package")
+ .with_stderr(
+ "\
+[WARNING] manifest has no documentation[..]
+See [..]
+[PACKAGING] foo v0.0.1 ([CWD])
+[VERIFYING] foo v0.0.1 ([CWD])
+[COMPILING] foo v0.0.1 ([CWD][..])
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[PACKAGED] 4 files, [..] ([..] compressed)
+",
+ )
+ .run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
validate_crate_contents(
@@ -695,6 +708,7 @@ fn ignore_nested() {
authors = []
license = "MIT"
description = "foo"
+ homepage = "https://example.com/"
"#;
let main_rs = r#"
fn main() { println!("hello"); }
@@ -711,8 +725,6 @@ fn ignore_nested() {
p.cargo("package")
.with_stderr(
"\
-[WARNING] manifest has no documentation[..]
-See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] foo v0.0.1 ([CWD])
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
@@ -732,7 +744,17 @@ src/main.rs
",
)
.run();
- p.cargo("package").with_stdout("").run();
+ p.cargo("package")
+ .with_stderr(
+ "\
+[PACKAGING] foo v0.0.1 ([CWD])
+[VERIFYING] foo v0.0.1 ([CWD])
+[COMPILING] foo v0.0.1 ([CWD][..])
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[PACKAGED] 4 files, [..] ([..] compressed)
+",
+ )
+ .run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
validate_crate_contents(
@@ -2730,6 +2752,7 @@ fn basic_filesizes() {
exclude = ["*.txt"]
license = "MIT"
description = "foo"
+ homepage = "https://example.com/"
"#;
let main_rs_contents = r#"fn main() { println!("🦀"); }"#;
let cargo_toml_contents = format!(
@@ -2740,6 +2763,7 @@ version = "0.0.1"
authors = []
exclude = ["*.txt"]
description = "foo"
+homepage = "https://example.com/"
license = "MIT"
"#,
cargo::core::package::MANIFEST_PREAMBLE
@@ -2775,7 +2799,17 @@ src/main.rs
",
)
.run();
- p.cargo("package").with_stdout("").run();
+ p.cargo("package")
+ .with_stderr(
+ "\
+[PACKAGING] foo v0.0.1 [..]
+[VERIFYING] foo v0.0.1 [..]
+[COMPILING] foo v0.0.1 [..]
+[FINISHED] [..]
+[PACKAGED] 4 files[..]
+",
+ )
+ .run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
let compressed_size = f.metadata().unwrap().len();
@@ -2802,6 +2836,7 @@ fn larger_filesizes() {
authors = []
license = "MIT"
description = "foo"
+ documentation = "https://example.com/"
"#;
let lots_of_crabs = std::iter::repeat("🦀").take(1337).collect::<String>();
let main_rs_contents = format!(r#"fn main() {{ println!("{}"); }}"#, lots_of_crabs);
@@ -2820,6 +2855,7 @@ name = "foo"
version = "0.0.1"
authors = []
description = "foo"
+documentation = "https://example.com/"
license = "MIT"
"#,
cargo::core::package::MANIFEST_PREAMBLE
@@ -2857,7 +2893,17 @@ src/main.rs
",
)
.run();
- p.cargo("package").with_stdout("").run();
+ p.cargo("package")
+ .with_stderr(
+ "\
+[PACKAGING] foo v0.0.1 [..]
+[VERIFYING] foo v0.0.1 [..]
+[COMPILING] foo v0.0.1 [..]
+[FINISHED] [..]
+[PACKAGED] 5 files, [..]
+",
+ )
+ .run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
let compressed_size = f.metadata().unwrap().len();
@@ -2895,6 +2941,7 @@ fn symlink_filesizes() {
authors = []
license = "MIT"
description = "foo"
+ homepage = "https://example.com/"
"#;
let lots_of_crabs = std::iter::repeat("🦀").take(1337).collect::<String>();
let main_rs_contents = format!(r#"fn main() {{ println!("{}"); }}"#, lots_of_crabs);
@@ -2913,6 +2960,7 @@ name = "foo"
version = "0.0.1"
authors = []
description = "foo"
+homepage = "https://example.com/"
license = "MIT"
"#,
cargo::core::package::MANIFEST_PREAMBLE
@@ -2955,7 +3003,17 @@ src/main.rs.bak
",
)
.run();
- p.cargo("package").with_stdout("").run();
+ p.cargo("package")
+ .with_stderr(
+ "\
+[PACKAGING] foo v0.0.1 [..]
+[VERIFYING] foo v0.0.1 [..]
+[COMPILING] foo v0.0.1 [..]
+[FINISHED] [..]
+[PACKAGED] 7 files, [..]
+",
+ )
+ .run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
let compressed_size = f.metadata().unwrap().len();
@@ -3031,7 +3089,19 @@ src/main.rs
",
)
.run();
- p.cargo("package").with_stdout("").run();
+ p.cargo("package")
+ .with_stderr(
+ "\
+[WARNING] manifest has no documentation[..]
+See [..]
+[PACKAGING] foo v0.0.1 ([CWD])
+[VERIFYING] foo v0.0.1 ([CWD])
+[COMPILING] foo v0.0.1 ([CWD][..])
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[PACKAGED] 4 files, [..] ([..] compressed)
+",
+ )
+ .run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
validate_crate_contents(
@@ -3085,7 +3155,19 @@ src/main.rs
",
)
.run();
- p.cargo("package").with_stdout("").run();
+ p.cargo("package")
+ .with_stderr(
+ "\
+[WARNING] manifest has no documentation[..]
+See [..]
+[PACKAGING] foo v0.0.1 ([CWD])
+[VERIFYING] foo v0.0.1 ([CWD])
+[COMPILING] foo v0.0.1 ([CWD][..])
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[PACKAGED] 4 files, [..] ([..] compressed)
+",
+ )
+ .run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
validate_crate_contents(
@@ -3132,3 +3214,142 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
&[],
);
}
+
+#[cargo_test]
+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_and_add_inner_target(project())
+ .file("target/foo.txt", "")
+ .build();
+
+ p.cargo("package -l")
+ .with_stdout(
+ "\
+Cargo.lock
+Cargo.toml
+Cargo.toml.orig
+data/not_target
+data/target
+derp/not_target/foo.txt
+derp/target/foo.txt
+src/main.rs
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+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, repo) = git::new_repo("foo", |p| init_and_add_inner_target(p));
+ // add target folder but not committed.
+ _ = fs::create_dir(p.build_dir()).unwrap();
+ _ = fs::write(p.build_dir().join("foo.txt"), "").unwrap();
+ 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
+",
+ )
+ .run();
+
+ // if target is committed, it should be include.
+ git::add(&repo);
+ git::commit(&repo);
+ 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_and_add_inner_target(p: ProjectBuilder) -> ProjectBuilder {
+ p.file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ license = "MIT"
+ description = "foo"
+ "#,
+ )
+ .file("src/main.rs", r#"fn main() { println!("hello"); }"#)
+ // file called target, should be included
+ .file("data/target", "")
+ .file("data/not_target", "")
+ // folder called target, should be included
+ .file("derp/target/foo.txt", "")
+ .file("derp/not_target/foo.txt", "")
+}
+
+#[cargo_test]
+fn build_script_outside_pkg_root() {
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ license = "MIT"
+ description = "foo"
+ authors = []
+ build = "../t_custom_build/custom_build.rs"
+ "#,
+ )
+ .file("src/main.rs", "fn main() {}")
+ .build();
+ let mut expect_msg = String::from("\
+warning: manifest has no documentation, homepage or repository.
+See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
+error: the source file of build script doesn't appear to exist.
+This may cause issue during packaging, as modules resolution and resources included via macros are often relative to the path of source files.
+Please update the `build` setting in the manifest at `[CWD]/Cargo.toml` and point to a path inside the root of the package.
+");
+ // custom_build.rs does not exist
+ p.cargo("package -l")
+ .with_status(101)
+ .with_stderr(&expect_msg)
+ .run();
+
+ // custom_build.rs outside the package root
+ let custom_build_root = paths::root().join("t_custom_build");
+ _ = fs::create_dir(&custom_build_root).unwrap();
+ _ = fs::write(&custom_build_root.join("custom_build.rs"), "fn main() {}");
+ expect_msg = format!(
+ "\
+warning: manifest has no documentation, homepage or repository.
+See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
+error: the source file of build script doesn't appear to be a path inside of the package.
+It is at `{}/t_custom_build/custom_build.rs`, whereas the root the package is `[CWD]`.
+This may cause issue during packaging, as modules resolution and resources included via macros are often relative to the path of source files.
+Please update the `build` setting in the manifest at `[CWD]/Cargo.toml` and point to a path inside the root of the package.
+", paths::root().display());
+ p.cargo("package -l")
+ .with_status(101)
+ .with_stderr(&expect_msg)
+ .run();
+}