From 57c83d8281441e46f160629a2f1ec8b3fb980130 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Mon, 24 Jun 2024 05:19:34 +0800 Subject: [PATCH] test: migrate publish_lockfile to snapbox --- tests/testsuite/publish_lockfile.rs | 255 +++++++++++++--------------- 1 file changed, 118 insertions(+), 137 deletions(-) diff --git a/tests/testsuite/publish_lockfile.rs b/tests/testsuite/publish_lockfile.rs index d8a29d45c47d..4bed46cd52e5 100644 --- a/tests/testsuite/publish_lockfile.rs +++ b/tests/testsuite/publish_lockfile.rs @@ -1,12 +1,11 @@ //! Tests for including `Cargo.lock` when publishing/packaging. -#![allow(deprecated)] - use std::fs::File; +use cargo_test_support::prelude::*; use cargo_test_support::registry::Package; use cargo_test_support::{ - basic_manifest, cargo_process, git, paths, project, publish::validate_crate_contents, + basic_manifest, cargo_process, git, paths, project, publish::validate_crate_contents, str, }; fn pl_manifest(name: &str, version: &str, extra: &str) -> String { @@ -53,17 +52,16 @@ fn removed() { p.cargo("package") .masquerade_as_nightly_cargo(&["publish-lockfile"]) .with_status(101) - .with_stderr( - "\ -[ERROR] failed to parse manifest at [..] + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: the cargo feature `publish-lockfile` has been removed in the 1.37 release Remove the feature from Cargo.toml to remove this error. - See https://doc.rust-lang.org/[..]cargo/reference/unstable.html#publish-lockfile [..] -", - ) + See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#publish-lockfile for more information about using this feature. + +"#]]) .run(); } @@ -75,37 +73,34 @@ fn package_lockfile() { .build(); p.cargo("package") - .with_stderr( - "\ -[PACKAGING] foo v0.0.1 ([CWD]) -[PACKAGED] [..] files, [..] ([..] compressed) -[VERIFYING] foo v0.0.1 ([CWD]) -[COMPILING] foo v0.0.1 ([CWD][..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_data(str![[r#" +[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert!(p.root().join("target/package/foo-0.0.1.crate").is_file()); p.cargo("package -l") - .with_stdout( - "\ + .with_stdout_data(str![[r#" Cargo.lock Cargo.toml Cargo.toml.orig src/main.rs -", - ) + +"#]]) .run(); p.cargo("package") - .with_stderr( - "\ -[PACKAGING] foo v0.0.1 [..] -[PACKAGED] 4 files, [..] -[VERIFYING] foo v0.0.1 [..] -[COMPILING] foo v0.0.1 [..] -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); @@ -126,33 +121,31 @@ fn package_lockfile_git_repo() { .build(); cargo_process("package -l") .cwd(g.root()) - .with_stdout( - "\ + .with_stdout_data(str![[r#" .cargo_vcs_info.json Cargo.lock Cargo.toml Cargo.toml.orig src/main.rs -", - ) + +"#]]) .run(); cargo_process("package -v") .cwd(g.root()) - .with_stderr( - "\ -[PACKAGING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[PACKAGING] foo v0.0.1 ([ROOT]/foo) [ARCHIVING] .cargo_vcs_info.json [ARCHIVING] Cargo.lock [ARCHIVING] Cargo.toml [ARCHIVING] Cargo.toml.orig [ARCHIVING] src/main.rs -[PACKAGED] 5 files, [..] ([..] compressed) -[VERIFYING] foo v0.0.1 ([..]) -[COMPILING] foo v0.0.1 ([..]) -[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -238,19 +231,18 @@ fn note_resolve_changes() { Package::new("updated", "1.0.1").publish(); p.cargo("package --no-verify -v --allow-dirty") - .with_stderr_unordered( - "\ -[PACKAGING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[PACKAGING] foo v0.0.1 ([ROOT]/foo) [ARCHIVING] Cargo.lock +[UPDATING] `dummy-registry` index +[NOTE] package `multi v0.1.0` added to the packaged Cargo.lock file, was originally sourced from `[ROOT]/foo/multi` +[NOTE] package `patched v1.0.0` added to the packaged Cargo.lock file, was originally sourced from `[ROOT]/foo/patched` [ARCHIVING] Cargo.toml [ARCHIVING] Cargo.toml.orig [ARCHIVING] src/main.rs -[UPDATING] `[..]` index -[NOTE] package `multi v0.1.0` added to the packaged Cargo.lock file, was originally sourced from `[..]/foo/multi` -[NOTE] package `patched v1.0.0` added to the packaged Cargo.lock file, was originally sourced from `[..]/foo/patched` -[PACKAGED] [..] files, [..] ([..] compressed) -", - ) +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) + +"#]].unordered()) .run(); } @@ -268,14 +260,13 @@ fn outdated_lock_version_change_does_not_warn() { p.change_file("Cargo.toml", &pl_manifest("foo", "0.2.0", "")); p.cargo("package --no-verify") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 1 package to latest compatible version -[UPDATING] foo v0.1.0 ([CWD]) -> v0.2.0 -[PACKAGING] foo v0.2.0 ([..]) -[PACKAGED] [..] files, [..] ([..] compressed) -", - ) +[UPDATING] foo v0.1.0 ([ROOT]/foo) -> v0.2.0 +[PACKAGING] foo v0.2.0 ([ROOT]/foo) +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) + +"#]]) .run(); } @@ -321,13 +312,12 @@ fn no_warn_workspace_extras() { p.cargo("generate-lockfile").run(); p.cargo("package --no-verify") .cwd("a") - .with_stderr( - "\ -[PACKAGING] a v0.1.0 ([..]) -[UPDATING] `[..]` index -[PACKAGED] [..] files, [..] ([..] compressed) -", - ) + .with_stderr_data(str![[r#" +[PACKAGING] a v0.1.0 ([ROOT]/foo/a) +[UPDATING] `dummy-registry` index +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) + +"#]]) .run(); } @@ -353,15 +343,13 @@ fn warn_package_with_yanked() { // Make sure it sticks with the locked (yanked) version. Package::new("bar", "0.1.1").publish(); p.cargo("package --no-verify") - .with_stderr( - "\ -[PACKAGING] foo v0.0.1 ([..]) -[UPDATING] `[..]` index -[WARNING] package `bar v0.1.0` in Cargo.lock is yanked in registry \ - `crates-io`, consider updating to a version that is not yanked -[PACKAGED] [..] files, [..] ([..] compressed) -", - ) + .with_stderr_data(str![[r#" +[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[UPDATING] `dummy-registry` index +[WARNING] package `bar v0.1.0` in Cargo.lock is yanked in registry `crates-io`, consider updating to a version that is not yanked +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) + +"#]]) .run(); } @@ -391,43 +379,40 @@ dependencies = [ .publish(); cargo_process("install --locked foo") - .with_stderr( - "\ -[UPDATING] `[..]` index + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [DOWNLOADING] crates ... -[DOWNLOADED] foo v0.1.0 (registry `[..]`) +[DOWNLOADED] foo v0.1.0 (registry `dummy-registry`) [INSTALLING] foo v0.1.0 -[WARNING] package `bar v0.1.0` in Cargo.lock is yanked in registry \ - `crates-io`, consider running without --locked +[WARNING] package `bar v0.1.0` in Cargo.lock is yanked in registry `crates-io`, consider running without --locked [DOWNLOADING] crates ... -[DOWNLOADED] bar v0.1.0 (registry `[..]`) +[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`) [COMPILING] bar v0.1.0 [COMPILING] foo v0.1.0 -[FINISHED] `release` profile [optimized] target(s) in [..] -[INSTALLING] [..]/.cargo/bin/foo[EXE] +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s +[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE] [INSTALLED] package `foo v0.1.0` (executable `foo[EXE]`) -[WARNING] be sure to add [..] -", - ) +[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries + +"#]]) .run(); // Try again without --locked, make sure it uses 0.1.1 and does not warn. cargo_process("install --force foo") - .with_stderr( - "\ -[UPDATING] `[..]` index + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [INSTALLING] foo v0.1.0 [LOCKING] 2 packages to latest compatible versions [DOWNLOADING] crates ... -[DOWNLOADED] bar v0.1.1 (registry `[..]`) +[DOWNLOADED] bar v0.1.1 (registry `dummy-registry`) [COMPILING] bar v0.1.1 [COMPILING] foo v0.1.0 -[FINISHED] `release` profile [optimized] target(s) in [..] -[REPLACING] [..]/.cargo/bin/foo[EXE] +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s +[REPLACING] [ROOT]/home/.cargo/bin/foo[EXE] [REPLACED] package `foo v0.1.0` with `foo v0.1.0` (executable `foo[EXE]`) -[WARNING] be sure to add [..] -", - ) +[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries + +"#]]) .run(); } @@ -453,33 +438,31 @@ fn ignore_lockfile() { .file(".gitignore", "Cargo.lock") }); p.cargo("package -l") - .with_stdout( - "\ + .with_stdout_data(str![[r#" .cargo_vcs_info.json Cargo.lock Cargo.toml Cargo.toml.orig src/main.rs -", - ) + +"#]]) .run(); p.cargo("generate-lockfile").run(); p.cargo("package -v") - .with_stderr( - "\ -[PACKAGING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[PACKAGING] foo v0.0.1 ([ROOT]/foo) [ARCHIVING] .cargo_vcs_info.json [ARCHIVING] Cargo.lock [ARCHIVING] Cargo.toml [ARCHIVING] Cargo.toml.orig [ARCHIVING] src/main.rs -[PACKAGED] 5 files, [..] ([..] compressed) -[VERIFYING] foo v0.0.1 ([..]) -[COMPILING] foo v0.0.1 ([..]) -[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -495,18 +478,17 @@ fn ignore_lockfile_inner() { p.cargo("generate-lockfile").cwd("bar").run(); p.cargo("package -v --no-verify") .cwd("bar") - .with_stderr( - "\ -[PACKAGING] bar v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[PACKAGING] bar v0.0.1 ([ROOT]/foo/bar) [ARCHIVING] .cargo_vcs_info.json [ARCHIVING] .gitignore [ARCHIVING] Cargo.lock [ARCHIVING] Cargo.toml [ARCHIVING] Cargo.toml.orig [ARCHIVING] src/main.rs -[PACKAGED] 6 files, [..] ([..] compressed) -", - ) +[PACKAGED] 6 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) + +"#]]) .run(); } @@ -564,29 +546,28 @@ fn use_workspace_root_lockfile() { // Expect: package `bar` uses `serde v0.2.0` as required by workspace `Cargo.lock`. p.cargo("package --workspace") - .with_stderr( - "\ -[WARNING] manifest has no documentation, [..] -See [..] -[PACKAGING] bar v0.0.1 ([CWD]/bar) + .with_stderr_data(str![[r#" +[WARNING] manifest has no documentation, homepage or repository. +See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info. +[PACKAGING] bar v0.0.1 ([ROOT]/foo/bar) [UPDATING] `dummy-registry` index -[PACKAGED] 4 files, [..] -[VERIFYING] bar v0.0.1 ([CWD]/bar) +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] bar v0.0.1 ([ROOT]/foo/bar) [DOWNLOADING] crates ... -[DOWNLOADED] serde v0.2.0 ([..]) +[DOWNLOADED] serde v0.2.0 (registry `dummy-registry`) [COMPILING] serde v0.2.0 -[COMPILING] bar v0.0.1 ([CWD][..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[WARNING] manifest has no documentation, [..] -See [..] -[PACKAGING] foo v0.0.1 ([CWD]) -[PACKAGED] 4 files, [..] -[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] bar v0.0.1 ([ROOT]/foo/target/package/bar-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] manifest has no documentation, homepage or repository. +See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info. +[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) [COMPILING] serde v0.2.0 -[COMPILING] foo v0.0.1 ([CWD][..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); let package_path = p.root().join("target/package/foo-0.0.1.crate");