From ebb5764ad80a1c2a985c6b08217e3adf0ece00f5 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 5 Apr 2019 13:25:08 -0700 Subject: [PATCH] Move publish-lockfile tests to a dedicated file. --- tests/testsuite/main.rs | 1 + tests/testsuite/package.rs | 167 --------------------------- tests/testsuite/publish_lockfile.rs | 171 ++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 167 deletions(-) create mode 100644 tests/testsuite/publish_lockfile.rs diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 95030c037..ddc922ce8 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -68,6 +68,7 @@ mod profile_overrides; mod profile_targets; mod profiles; mod publish; +mod publish_lockfile; mod read_manifest; mod registry; mod rename_deps; diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 2b2a35550..64a2e051b 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1018,173 +1018,6 @@ Caused by: .run(); } -#[test] -fn package_lockfile() { - let p = project() - .file( - "Cargo.toml", - r#" - cargo-features = ["publish-lockfile"] - - [project] - name = "foo" - version = "0.0.1" - authors = [] - license = "MIT" - description = "foo" - publish-lockfile = true - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("package") - .masquerade_as_nightly_cargo() - .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 [..] -", - ) - .run(); - assert!(p.root().join("target/package/foo-0.0.1.crate").is_file()); - p.cargo("package -l") - .masquerade_as_nightly_cargo() - .with_stdout( - "\ -Cargo.lock -Cargo.toml -src/main.rs -", - ) - .run(); - p.cargo("package") - .masquerade_as_nightly_cargo() - .with_stdout("") - .run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"], - &[], - ); -} - -#[test] -fn package_lockfile_git_repo() { - let p = project().build(); - - // Create a Git repository containing a minimal Rust project. - let _ = git::repo(&paths::root().join("foo")) - .file( - "Cargo.toml", - r#" - cargo-features = ["publish-lockfile"] - - [project] - name = "foo" - version = "0.0.1" - license = "MIT" - description = "foo" - documentation = "foo" - homepage = "foo" - repository = "foo" - publish-lockfile = true - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - p.cargo("package -l") - .masquerade_as_nightly_cargo() - .with_stdout( - "\ -.cargo_vcs_info.json -Cargo.lock -Cargo.toml -src/main.rs -", - ) - .run(); -} - -#[test] -fn no_lock_file_with_library() { - let p = project() - .file( - "Cargo.toml", - r#" - cargo-features = ["publish-lockfile"] - - [project] - name = "foo" - version = "0.0.1" - authors = [] - license = "MIT" - description = "foo" - publish-lockfile = true - "#, - ) - .file("src/lib.rs", "") - .build(); - - p.cargo("package").masquerade_as_nightly_cargo().run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[], - ); -} - -#[test] -fn lock_file_and_workspace() { - let p = project() - .file( - "Cargo.toml", - r#" - [workspace] - members = ["foo"] - "#, - ) - .file( - "foo/Cargo.toml", - r#" - cargo-features = ["publish-lockfile"] - - [package] - name = "foo" - version = "0.0.1" - authors = [] - license = "MIT" - description = "foo" - publish-lockfile = true - "#, - ) - .file("foo/src/main.rs", "fn main() {}") - .build(); - - p.cargo("package") - .cwd("foo") - .masquerade_as_nightly_cargo() - .run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.toml", "Cargo.toml.orig", "src/main.rs", "Cargo.lock"], - &[], - ); -} - #[test] fn do_not_package_if_src_was_modified() { let p = project() diff --git a/tests/testsuite/publish_lockfile.rs b/tests/testsuite/publish_lockfile.rs new file mode 100644 index 000000000..5aa0caa3f --- /dev/null +++ b/tests/testsuite/publish_lockfile.rs @@ -0,0 +1,171 @@ +use std; +use std::fs::File; + +use crate::support::{git, paths, project, publish::validate_crate_contents}; + +#[test] +fn package_lockfile() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["publish-lockfile"] + + [project] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + publish-lockfile = true + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("package") + .masquerade_as_nightly_cargo() + .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 [..] +", + ) + .run(); + assert!(p.root().join("target/package/foo-0.0.1.crate").is_file()); + p.cargo("package -l") + .masquerade_as_nightly_cargo() + .with_stdout( + "\ +Cargo.lock +Cargo.toml +src/main.rs +", + ) + .run(); + p.cargo("package") + .masquerade_as_nightly_cargo() + .with_stdout("") + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"], + &[], + ); +} + +#[test] +fn package_lockfile_git_repo() { + let p = project().build(); + + // Create a Git repository containing a minimal Rust project. + let _ = git::repo(&paths::root().join("foo")) + .file( + "Cargo.toml", + r#" + cargo-features = ["publish-lockfile"] + + [project] + name = "foo" + version = "0.0.1" + license = "MIT" + description = "foo" + documentation = "foo" + homepage = "foo" + repository = "foo" + publish-lockfile = true + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + p.cargo("package -l") + .masquerade_as_nightly_cargo() + .with_stdout( + "\ +.cargo_vcs_info.json +Cargo.lock +Cargo.toml +src/main.rs +", + ) + .run(); +} + +#[test] +fn no_lock_file_with_library() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["publish-lockfile"] + + [project] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + publish-lockfile = true + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("package").masquerade_as_nightly_cargo().run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[], + ); +} + +#[test] +fn lock_file_and_workspace() { + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["foo"] + "#, + ) + .file( + "foo/Cargo.toml", + r#" + cargo-features = ["publish-lockfile"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + publish-lockfile = true + "#, + ) + .file("foo/src/main.rs", "fn main() {}") + .build(); + + p.cargo("package") + .cwd("foo") + .masquerade_as_nightly_cargo() + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/main.rs", "Cargo.lock"], + &[], + ); +}