mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
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:
commit
be1db6ca60
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,9 @@
|
||||
//! Tests for the `cargo pkgid` command.
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use cargo_test_support::basic_lib_manifest;
|
||||
use cargo_test_support::compare::assert_e2e;
|
||||
use cargo_test_support::git;
|
||||
use cargo_test_support::prelude::*;
|
||||
use cargo_test_support::project;
|
||||
use cargo_test_support::registry::Package;
|
||||
use cargo_test_support::str;
|
||||
@ -40,38 +39,36 @@ fn local() {
|
||||
p.cargo("generate-lockfile").run();
|
||||
|
||||
p.cargo("pkgid foo")
|
||||
.with_stdout(format!(
|
||||
"path+file://[..]{}#0.1.0",
|
||||
p.root().to_str().unwrap()
|
||||
))
|
||||
.with_stdout_data(str![[r#"
|
||||
path+[ROOTURL]/foo#0.1.0
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
// Bad file URL.
|
||||
p.cargo("pkgid ./Cargo.toml")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: invalid package ID specification: `./Cargo.toml`
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] invalid package ID specification: `./Cargo.toml`
|
||||
|
||||
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();
|
||||
|
||||
// Bad file URL with similar name.
|
||||
p.cargo("pkgid './bar'")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: invalid package ID specification: `./bar`
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] invalid package ID specification: `./bar`
|
||||
|
||||
<tab>Did you mean `bar`?
|
||||
Did you mean `bar`?
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -98,32 +95,33 @@ fn registry() {
|
||||
p.cargo("generate-lockfile").run();
|
||||
|
||||
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();
|
||||
|
||||
// Bad URL.
|
||||
p.cargo("pkgid https://example.com/crates-io")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: package ID specification `https://example.com/crates-io` did not match any packages
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] package ID specification `https://example.com/crates-io` did not match any packages
|
||||
Did you mean one of these?
|
||||
|
||||
crates-io@0.1.0
|
||||
",
|
||||
)
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
// Bad name.
|
||||
p.cargo("pkgid crates_io")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: package ID specification `crates_io` did not match any packages
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] package ID specification `crates_io` did not match any packages
|
||||
|
||||
<tab>Did you mean `crates-io`?
|
||||
",
|
||||
)
|
||||
Did you mean `crates-io`?
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -152,56 +150,55 @@ fn multiple_versions() {
|
||||
p.cargo("generate-lockfile").run();
|
||||
|
||||
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();
|
||||
|
||||
// Incomplete version.
|
||||
p.cargo("pkgid two-ver@0")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: There are multiple `two-ver` packages in your project, and the specification `two-ver@0` is ambiguous.
|
||||
.with_stderr_data(str![[r#"
|
||||
[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:
|
||||
two-ver@0.1.0
|
||||
two-ver@0.2.0
|
||||
",
|
||||
)
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
// Incomplete version.
|
||||
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
|
||||
",
|
||||
)
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
// Ambiguous.
|
||||
p.cargo("pkgid two-ver")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: There are multiple `two-ver` packages in your project, and the specification `two-ver` is ambiguous.
|
||||
.with_stderr_data(str![[r#"
|
||||
[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:
|
||||
two-ver@0.1.0
|
||||
two-ver@0.2.0
|
||||
",
|
||||
)
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
// Bad version.
|
||||
p.cargo("pkgid two-ver:0.3.0")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: package ID specification `two-ver@0.3.0` did not match any packages
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] package ID specification `two-ver@0.3.0` did not match any packages
|
||||
Did you mean one of these?
|
||||
|
||||
two-ver@0.1.0
|
||||
two-ver@0.2.0
|
||||
",
|
||||
)
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -260,12 +257,12 @@ fn multiple_git_same_version() {
|
||||
|
||||
p.cargo("check").run();
|
||||
p.cargo("tree")
|
||||
.with_stdout(&format!(
|
||||
.with_stdout_data(&format!(
|
||||
"\
|
||||
foo v0.1.0 ([..]/foo)
|
||||
├── bar v0.1.0 ([..]/foo/bar)
|
||||
│ └── xyz v0.5.0 (file://[..]/xyz?rev={}#{})
|
||||
└── xyz v0.5.0 (file://[..]/xyz?rev={}#{})
|
||||
foo v0.1.0 ([ROOT]/foo)
|
||||
├── bar v0.1.0 ([ROOT]/foo/bar)
|
||||
│ └── xyz v0.5.0 ([ROOTURL]/xyz?rev={}#{})
|
||||
└── xyz v0.5.0 ([ROOTURL]/xyz?rev={}#{})
|
||||
",
|
||||
rev2,
|
||||
&rev2.to_string()[..8],
|
||||
@ -277,14 +274,13 @@ foo v0.1.0 ([..]/foo)
|
||||
// possible pkgids are also ambiguous.
|
||||
p.cargo("pkgid xyz")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: There are multiple `xyz` packages in your project, and the specification `xyz` is ambiguous.
|
||||
.with_stderr_data(str![[r#"
|
||||
[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:
|
||||
git+file://[..]/xyz?rev=[..]#0.5.0
|
||||
git+file://[..]/xyz?rev=[..]#0.5.0
|
||||
",
|
||||
)
|
||||
git+[ROOTURL]/xyz?rev=[..]#0.5.0
|
||||
git+[ROOTURL]/xyz?rev=[..]#0.5.0
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
// TODO, what should the `-p` value be here?
|
||||
//p.cargo("update -p")
|
||||
@ -310,6 +306,7 @@ fn pkgid_json_message_metadata_consistency() {
|
||||
let pkgid = pkgid.trim();
|
||||
assert_e2e().eq(pkgid, str!["path+[ROOTURL]/foo#0.5.0"]);
|
||||
|
||||
#[allow(deprecated)]
|
||||
p.cargo("check --message-format=json")
|
||||
.with_json(
|
||||
&r#"
|
||||
@ -373,13 +370,15 @@ fn pkgid_json_message_metadata_consistency() {
|
||||
.run();
|
||||
|
||||
p.cargo("metadata")
|
||||
.with_json(
|
||||
&r#"
|
||||
.with_stdout_data(
|
||||
str![[r#"
|
||||
{
|
||||
"metadata": null,
|
||||
"packages": [
|
||||
{
|
||||
"authors": "{...}",
|
||||
"authors": [
|
||||
"wycats@example.com"
|
||||
],
|
||||
"categories": [],
|
||||
"default_run": null,
|
||||
"dependencies": [],
|
||||
@ -388,12 +387,12 @@ fn pkgid_json_message_metadata_consistency() {
|
||||
"edition": "2015",
|
||||
"features": {},
|
||||
"homepage": null,
|
||||
"id": "$PKGID",
|
||||
"id": "path+[ROOTURL]/foo#0.5.0",
|
||||
"keywords": [],
|
||||
"license": null,
|
||||
"license_file": null,
|
||||
"links": null,
|
||||
"manifest_path": "[..]",
|
||||
"manifest_path": "[ROOT]/foo/Cargo.toml",
|
||||
"metadata": null,
|
||||
"name": "foo",
|
||||
"publish": null,
|
||||
@ -411,23 +410,23 @@ fn pkgid_json_message_metadata_consistency() {
|
||||
"dependencies": [],
|
||||
"deps": [],
|
||||
"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,
|
||||
"workspace_default_members": [
|
||||
"$PKGID"
|
||||
"path+[ROOTURL]/foo#0.5.0"
|
||||
],
|
||||
"workspace_members": [
|
||||
"$PKGID"
|
||||
"path+[ROOTURL]/foo#0.5.0"
|
||||
],
|
||||
"workspace_root": "[..]"
|
||||
"workspace_root": "[ROOT]/foo"
|
||||
}
|
||||
"#
|
||||
.replace("$PKGID", pkgid),
|
||||
"#]]
|
||||
.json(),
|
||||
)
|
||||
.run()
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! Tests for proc-macros.
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use cargo_test_support::prelude::*;
|
||||
use cargo_test_support::project;
|
||||
use cargo_test_support::str;
|
||||
|
||||
#[cargo_test]
|
||||
fn probe_cfg_before_crate_type_discovery() {
|
||||
@ -207,7 +207,12 @@ fn impl_and_derive() {
|
||||
.build();
|
||||
|
||||
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]
|
||||
@ -251,8 +256,21 @@ fn proc_macro_doctest() {
|
||||
.build();
|
||||
|
||||
foo.cargo("test")
|
||||
.with_stdout_contains("test a ... ok")
|
||||
.with_stdout_contains_n("test [..] ... ok", 2)
|
||||
.with_stdout_data(str![[r#"
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -319,8 +337,21 @@ fn proc_macro_crate_type() {
|
||||
.build();
|
||||
|
||||
foo.cargo("test")
|
||||
.with_stdout_contains("test tests::it_works ... ok")
|
||||
.with_stdout_contains_n("test [..] ... ok", 2)
|
||||
.with_stdout_data(str![[r#"
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -342,8 +373,12 @@ fn proc_macro_crate_type_warning() {
|
||||
.build();
|
||||
|
||||
foo.cargo("check")
|
||||
.with_stderr_contains(
|
||||
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
|
||||
.with_stderr_data(str![[r#"
|
||||
[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();
|
||||
}
|
||||
|
||||
@ -365,7 +400,12 @@ fn lib_plugin_unused_key_warning() {
|
||||
.build();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -387,9 +427,13 @@ fn proc_macro_crate_type_warning_plugin() {
|
||||
.build();
|
||||
|
||||
foo.cargo("check")
|
||||
.with_stderr_contains(
|
||||
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
|
||||
.run();
|
||||
.with_stderr_data(str![[r#"
|
||||
[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();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
@ -410,14 +454,13 @@ fn proc_macro_crate_type_multiple() {
|
||||
.build();
|
||||
|
||||
foo.cargo("check")
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
||||
|
||||
Caused by:
|
||||
cannot mix `proc-macro` crate type with others
|
||||
",
|
||||
)
|
||||
|
||||
"#]])
|
||||
.with_status(101)
|
||||
.run();
|
||||
}
|
||||
@ -508,19 +551,21 @@ fn proc_macro_built_once() {
|
||||
.file("the-macro/src/lib.rs", "")
|
||||
.build();
|
||||
p.cargo("build --verbose")
|
||||
.with_stderr_unordered(
|
||||
"\
|
||||
.with_stderr_data(
|
||||
str![[r#"
|
||||
[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 [..]`
|
||||
[COMPILING] b [..]
|
||||
[COMPILING] b v0.1.0 ([ROOT]/foo/b)
|
||||
[RUNNING] `rustc --crate-name b [..]`
|
||||
[COMPILING] a [..]
|
||||
[COMPILING] a v0.1.0 ([ROOT]/foo/a)
|
||||
[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 [..]`
|
||||
[FINISHED] [..]
|
||||
",
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]]
|
||||
.unordered(),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! Tests for progress bar.
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use cargo_test_support::prelude::*;
|
||||
use cargo_test_support::project;
|
||||
use cargo_test_support::registry::Package;
|
||||
use cargo_test_support::str;
|
||||
|
||||
#[cargo_test]
|
||||
fn bad_progress_config_unknown_when() {
|
||||
@ -20,15 +20,13 @@ fn bad_progress_config_unknown_when() {
|
||||
|
||||
p.cargo("check")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] error in [..].cargo/config.toml: \
|
||||
could not load config key `term.progress.when`
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `term.progress.when`
|
||||
|
||||
Caused by:
|
||||
unknown variant `unknown`, expected one of `auto`, `never`, `always`
|
||||
",
|
||||
)
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -47,11 +45,10 @@ fn bad_progress_config_missing_width() {
|
||||
|
||||
p.cargo("check")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] \"always\" progress requires a `width` key
|
||||
",
|
||||
)
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] "always" progress requires a `width` key
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -70,14 +67,13 @@ fn bad_progress_config_missing_when() {
|
||||
|
||||
p.cargo("check")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: error in [..]: could not load config key `term.progress`
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `term.progress`
|
||||
|
||||
Caused by:
|
||||
missing field `when`
|
||||
",
|
||||
)
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -116,12 +112,23 @@ fn always_shows_progress() {
|
||||
.build();
|
||||
|
||||
p.cargo("check")
|
||||
.with_stderr_contains("[DOWNLOADING] [..] crates [..]")
|
||||
.with_stderr_contains("[..][DOWNLOADED] 3 crates ([..]) in [..]")
|
||||
.with_stderr_contains("[BUILDING] [..] [..]/4: [..]")
|
||||
.with_stderr_data(
|
||||
str![[r#"
|
||||
[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();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn never_progress() {
|
||||
const N: usize = 3;
|
||||
|
Loading…
x
Reference in New Issue
Block a user