Auto merge of #14181 - eth3lbert:snapbox-p, r=epage

test: migrate patch, pkgid, proc_macro and progress to snapbox

### What does this PR try to resolve?

Part of https://github.com/rust-lang/cargo/issues/14039.

Migrate following to snapbox:

- `tests/testsuite/patch.rs`
- `tests/testsuite/pkgid.rs`
- `tests/testsuite/proc_macro.rs`
- `tests/testsuite/progress.rs`
This commit is contained in:
bors 2024-07-05 21:07:06 +00:00
commit be1db6ca60
4 changed files with 715 additions and 641 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,9 @@
//! Tests for the `cargo pkgid` command. //! Tests for the `cargo pkgid` command.
#![allow(deprecated)]
use cargo_test_support::basic_lib_manifest; use cargo_test_support::basic_lib_manifest;
use cargo_test_support::compare::assert_e2e; use cargo_test_support::compare::assert_e2e;
use cargo_test_support::git; use cargo_test_support::git;
use cargo_test_support::prelude::*;
use cargo_test_support::project; use cargo_test_support::project;
use cargo_test_support::registry::Package; use cargo_test_support::registry::Package;
use cargo_test_support::str; use cargo_test_support::str;
@ -40,38 +39,36 @@ fn local() {
p.cargo("generate-lockfile").run(); p.cargo("generate-lockfile").run();
p.cargo("pkgid foo") p.cargo("pkgid foo")
.with_stdout(format!( .with_stdout_data(str![[r#"
"path+file://[..]{}#0.1.0", path+[ROOTURL]/foo#0.1.0
p.root().to_str().unwrap()
)) "#]])
.run(); .run();
// Bad file URL. // Bad file URL.
p.cargo("pkgid ./Cargo.toml") p.cargo("pkgid ./Cargo.toml")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] invalid package ID specification: `./Cargo.toml`
error: invalid package ID specification: `./Cargo.toml`
Caused by: Caused by:
package ID specification `./Cargo.toml` looks like a file path, maybe try file://[..]/Cargo.toml package ID specification `./Cargo.toml` looks like a file path, maybe try [ROOTURL]/foo/Cargo.toml
",
) "#]])
.run(); .run();
// Bad file URL with similar name. // Bad file URL with similar name.
p.cargo("pkgid './bar'") p.cargo("pkgid './bar'")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] invalid package ID specification: `./bar`
error: invalid package ID specification: `./bar`
<tab>Did you mean `bar`? Did you mean `bar`?
Caused by: Caused by:
package ID specification `./bar` looks like a file path, maybe try file://[..]/bar package ID specification `./bar` looks like a file path, maybe try [ROOTURL]/foo/bar
",
) "#]])
.run(); .run();
} }
@ -98,32 +95,33 @@ fn registry() {
p.cargo("generate-lockfile").run(); p.cargo("generate-lockfile").run();
p.cargo("pkgid crates-io") p.cargo("pkgid crates-io")
.with_stdout("registry+https://github.com/rust-lang/crates.io-index#crates-io@0.1.0") .with_stdout_data(str![[r#"
registry+https://github.com/rust-lang/crates.io-index#crates-io@0.1.0
"#]])
.run(); .run();
// Bad URL. // Bad URL.
p.cargo("pkgid https://example.com/crates-io") p.cargo("pkgid https://example.com/crates-io")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] package ID specification `https://example.com/crates-io` did not match any packages
error: package ID specification `https://example.com/crates-io` did not match any packages
Did you mean one of these? Did you mean one of these?
crates-io@0.1.0 crates-io@0.1.0
",
) "#]])
.run(); .run();
// Bad name. // Bad name.
p.cargo("pkgid crates_io") p.cargo("pkgid crates_io")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] package ID specification `crates_io` did not match any packages
error: package ID specification `crates_io` did not match any packages
<tab>Did you mean `crates-io`? Did you mean `crates-io`?
",
) "#]])
.run(); .run();
} }
@ -152,56 +150,55 @@ fn multiple_versions() {
p.cargo("generate-lockfile").run(); p.cargo("generate-lockfile").run();
p.cargo("pkgid two-ver:0.2.0") p.cargo("pkgid two-ver:0.2.0")
.with_stdout("registry+https://github.com/rust-lang/crates.io-index#two-ver@0.2.0") .with_stdout_data(str![[r#"
registry+https://github.com/rust-lang/crates.io-index#two-ver@0.2.0
"#]])
.run(); .run();
// Incomplete version. // Incomplete version.
p.cargo("pkgid two-ver@0") p.cargo("pkgid two-ver@0")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] There are multiple `two-ver` packages in your project, and the specification `two-ver@0` is ambiguous.
error: There are multiple `two-ver` packages in your project, and the specification `two-ver@0` is ambiguous.
Please re-run this command with one of the following specifications: Please re-run this command with one of the following specifications:
two-ver@0.1.0 two-ver@0.1.0
two-ver@0.2.0 two-ver@0.2.0
",
) "#]])
.run(); .run();
// Incomplete version. // Incomplete version.
p.cargo("pkgid two-ver@0.2") p.cargo("pkgid two-ver@0.2")
.with_stdout( .with_stdout_data(str![[r#"
"\
registry+https://github.com/rust-lang/crates.io-index#two-ver@0.2.0 registry+https://github.com/rust-lang/crates.io-index#two-ver@0.2.0
",
) "#]])
.run(); .run();
// Ambiguous. // Ambiguous.
p.cargo("pkgid two-ver") p.cargo("pkgid two-ver")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] There are multiple `two-ver` packages in your project, and the specification `two-ver` is ambiguous.
error: There are multiple `two-ver` packages in your project, and the specification `two-ver` is ambiguous.
Please re-run this command with one of the following specifications: Please re-run this command with one of the following specifications:
two-ver@0.1.0 two-ver@0.1.0
two-ver@0.2.0 two-ver@0.2.0
",
) "#]])
.run(); .run();
// Bad version. // Bad version.
p.cargo("pkgid two-ver:0.3.0") p.cargo("pkgid two-ver:0.3.0")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] package ID specification `two-ver@0.3.0` did not match any packages
error: package ID specification `two-ver@0.3.0` did not match any packages
Did you mean one of these? Did you mean one of these?
two-ver@0.1.0 two-ver@0.1.0
two-ver@0.2.0 two-ver@0.2.0
",
) "#]])
.run(); .run();
} }
@ -260,12 +257,12 @@ fn multiple_git_same_version() {
p.cargo("check").run(); p.cargo("check").run();
p.cargo("tree") p.cargo("tree")
.with_stdout(&format!( .with_stdout_data(&format!(
"\ "\
foo v0.1.0 ([..]/foo) foo v0.1.0 ([ROOT]/foo)
bar v0.1.0 ([..]/foo/bar) bar v0.1.0 ([ROOT]/foo/bar)
xyz v0.5.0 (file://[..]/xyz?rev={}#{}) xyz v0.5.0 ([ROOTURL]/xyz?rev={}#{})
xyz v0.5.0 (file://[..]/xyz?rev={}#{}) xyz v0.5.0 ([ROOTURL]/xyz?rev={}#{})
", ",
rev2, rev2,
&rev2.to_string()[..8], &rev2.to_string()[..8],
@ -277,14 +274,13 @@ foo v0.1.0 ([..]/foo)
// possible pkgids are also ambiguous. // possible pkgids are also ambiguous.
p.cargo("pkgid xyz") p.cargo("pkgid xyz")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] There are multiple `xyz` packages in your project, and the specification `xyz` is ambiguous.
error: There are multiple `xyz` packages in your project, and the specification `xyz` is ambiguous.
Please re-run this command with one of the following specifications: Please re-run this command with one of the following specifications:
git+file://[..]/xyz?rev=[..]#0.5.0 git+[ROOTURL]/xyz?rev=[..]#0.5.0
git+file://[..]/xyz?rev=[..]#0.5.0 git+[ROOTURL]/xyz?rev=[..]#0.5.0
",
) "#]])
.run(); .run();
// TODO, what should the `-p` value be here? // TODO, what should the `-p` value be here?
//p.cargo("update -p") //p.cargo("update -p")
@ -310,6 +306,7 @@ fn pkgid_json_message_metadata_consistency() {
let pkgid = pkgid.trim(); let pkgid = pkgid.trim();
assert_e2e().eq(pkgid, str!["path+[ROOTURL]/foo#0.5.0"]); assert_e2e().eq(pkgid, str!["path+[ROOTURL]/foo#0.5.0"]);
#[allow(deprecated)]
p.cargo("check --message-format=json") p.cargo("check --message-format=json")
.with_json( .with_json(
&r#" &r#"
@ -373,13 +370,15 @@ fn pkgid_json_message_metadata_consistency() {
.run(); .run();
p.cargo("metadata") p.cargo("metadata")
.with_json( .with_stdout_data(
&r#" str![[r#"
{ {
"metadata": null, "metadata": null,
"packages": [ "packages": [
{ {
"authors": "{...}", "authors": [
"wycats@example.com"
],
"categories": [], "categories": [],
"default_run": null, "default_run": null,
"dependencies": [], "dependencies": [],
@ -388,12 +387,12 @@ fn pkgid_json_message_metadata_consistency() {
"edition": "2015", "edition": "2015",
"features": {}, "features": {},
"homepage": null, "homepage": null,
"id": "$PKGID", "id": "path+[ROOTURL]/foo#0.5.0",
"keywords": [], "keywords": [],
"license": null, "license": null,
"license_file": null, "license_file": null,
"links": null, "links": null,
"manifest_path": "[..]", "manifest_path": "[ROOT]/foo/Cargo.toml",
"metadata": null, "metadata": null,
"name": "foo", "name": "foo",
"publish": null, "publish": null,
@ -411,23 +410,23 @@ fn pkgid_json_message_metadata_consistency() {
"dependencies": [], "dependencies": [],
"deps": [], "deps": [],
"features": [], "features": [],
"id": "$PKGID" "id": "path+[ROOTURL]/foo#0.5.0"
} }
], ],
"root": "$PKGID" "root": "path+[ROOTURL]/foo#0.5.0"
}, },
"target_directory": "[..]", "target_directory": "[ROOT]/foo/target",
"version": 1, "version": 1,
"workspace_default_members": [ "workspace_default_members": [
"$PKGID" "path+[ROOTURL]/foo#0.5.0"
], ],
"workspace_members": [ "workspace_members": [
"$PKGID" "path+[ROOTURL]/foo#0.5.0"
], ],
"workspace_root": "[..]" "workspace_root": "[ROOT]/foo"
} }
"# "#]]
.replace("$PKGID", pkgid), .json(),
) )
.run() .run()
} }

View File

@ -1,8 +1,8 @@
//! Tests for proc-macros. //! Tests for proc-macros.
#![allow(deprecated)] use cargo_test_support::prelude::*;
use cargo_test_support::project; use cargo_test_support::project;
use cargo_test_support::str;
#[cargo_test] #[cargo_test]
fn probe_cfg_before_crate_type_discovery() { fn probe_cfg_before_crate_type_discovery() {
@ -207,7 +207,12 @@ fn impl_and_derive() {
.build(); .build();
p.cargo("build").run(); p.cargo("build").run();
p.cargo("run").with_stdout("X { success: true }").run(); p.cargo("run")
.with_stdout_data(str![[r#"
X { success: true }
"#]])
.run();
} }
#[cargo_test] #[cargo_test]
@ -251,8 +256,21 @@ fn proc_macro_doctest() {
.build(); .build();
foo.cargo("test") foo.cargo("test")
.with_stdout_contains("test a ... ok") .with_stdout_data(str![[r#"
.with_stdout_contains_n("test [..] ... ok", 2)
running 1 test
test a ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
running 1 test
test src/lib.rs - derive (line 8) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
"#]])
.run(); .run();
} }
@ -319,8 +337,21 @@ fn proc_macro_crate_type() {
.build(); .build();
foo.cargo("test") foo.cargo("test")
.with_stdout_contains("test tests::it_works ... ok") .with_stdout_data(str![[r#"
.with_stdout_contains_n("test [..] ... ok", 2)
running 1 test
test tests::it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
running 1 test
test src/lib.rs - (line 2) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
"#]])
.run(); .run();
} }
@ -342,8 +373,12 @@ fn proc_macro_crate_type_warning() {
.build(); .build();
foo.cargo("check") foo.cargo("check")
.with_stderr_contains( .with_stderr_data(str![[r#"
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`") [WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run(); .run();
} }
@ -365,7 +400,12 @@ fn lib_plugin_unused_key_warning() {
.build(); .build();
foo.cargo("check") foo.cargo("check")
.with_stderr_contains("[WARNING] unused manifest key: lib.plugin") .with_stderr_data(str![[r#"
[WARNING] unused manifest key: lib.plugin
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run(); .run();
} }
@ -387,8 +427,12 @@ fn proc_macro_crate_type_warning_plugin() {
.build(); .build();
foo.cargo("check") foo.cargo("check")
.with_stderr_contains( .with_stderr_data(str![[r#"
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`") [WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run(); .run();
} }
@ -410,14 +454,13 @@ fn proc_macro_crate_type_multiple() {
.build(); .build();
foo.cargo("check") foo.cargo("check")
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
Caused by: Caused by:
cannot mix `proc-macro` crate type with others cannot mix `proc-macro` crate type with others
",
) "#]])
.with_status(101) .with_status(101)
.run(); .run();
} }
@ -508,19 +551,21 @@ fn proc_macro_built_once() {
.file("the-macro/src/lib.rs", "") .file("the-macro/src/lib.rs", "")
.build(); .build();
p.cargo("build --verbose") p.cargo("build --verbose")
.with_stderr_unordered( .with_stderr_data(
"\ str![[r#"
[LOCKING] 3 packages to latest compatible versions [LOCKING] 3 packages to latest compatible versions
[COMPILING] the-macro [..] [COMPILING] the-macro v0.1.0 ([ROOT]/foo/the-macro)
[RUNNING] `rustc --crate-name the_macro [..]` [RUNNING] `rustc --crate-name the_macro [..]`
[COMPILING] b [..] [COMPILING] b v0.1.0 ([ROOT]/foo/b)
[RUNNING] `rustc --crate-name b [..]` [RUNNING] `rustc --crate-name b [..]`
[COMPILING] a [..] [COMPILING] a v0.1.0 ([ROOT]/foo/a)
[RUNNING] `rustc --crate-name build_script_build [..]` [RUNNING] `rustc --crate-name build_script_build [..]`
[RUNNING] `[..]build[..]script[..]build[..]` [RUNNING] `[ROOT]/foo/target/debug/build/a-[HASH]/build-script-build`
[RUNNING] `rustc --crate-name a [..]` [RUNNING] `rustc --crate-name a [..]`
[FINISHED] [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
"#]]
.unordered(),
) )
.run(); .run();
} }

View File

@ -1,9 +1,9 @@
//! Tests for progress bar. //! Tests for progress bar.
#![allow(deprecated)] use cargo_test_support::prelude::*;
use cargo_test_support::project; use cargo_test_support::project;
use cargo_test_support::registry::Package; use cargo_test_support::registry::Package;
use cargo_test_support::str;
#[cargo_test] #[cargo_test]
fn bad_progress_config_unknown_when() { fn bad_progress_config_unknown_when() {
@ -20,15 +20,13 @@ fn bad_progress_config_unknown_when() {
p.cargo("check") p.cargo("check")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `term.progress.when`
[ERROR] error in [..].cargo/config.toml: \
could not load config key `term.progress.when`
Caused by: Caused by:
unknown variant `unknown`, expected one of `auto`, `never`, `always` unknown variant `unknown`, expected one of `auto`, `never`, `always`
",
) "#]])
.run(); .run();
} }
@ -47,11 +45,10 @@ fn bad_progress_config_missing_width() {
p.cargo("check") p.cargo("check")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] "always" progress requires a `width` key
[ERROR] \"always\" progress requires a `width` key
", "#]])
)
.run(); .run();
} }
@ -70,14 +67,13 @@ fn bad_progress_config_missing_when() {
p.cargo("check") p.cargo("check")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `term.progress`
error: error in [..]: could not load config key `term.progress`
Caused by: Caused by:
missing field `when` missing field `when`
",
) "#]])
.run(); .run();
} }
@ -116,12 +112,23 @@ fn always_shows_progress() {
.build(); .build();
p.cargo("check") p.cargo("check")
.with_stderr_contains("[DOWNLOADING] [..] crates [..]") .with_stderr_data(
.with_stderr_contains("[..][DOWNLOADED] 3 crates ([..]) in [..]") str![[r#"
.with_stderr_contains("[BUILDING] [..] [..]/4: [..]") [DOWNLOADING] 1 crate
[DOWNLOADING] 2 crates
[DOWNLOADING] 3 crates
[DOWNLOADED] 3 crates ([..]KB) in [..]s
[BUILDING] [..] 0/4: [..]
[BUILDING] [..] 3/4: foo
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
...
"#]]
.unordered(),
)
.run(); .run();
} }
#[allow(deprecated)]
#[cargo_test] #[cargo_test]
fn never_progress() { fn never_progress() {
const N: usize = 3; const N: usize = 3;