Skip to content

Commit 96fc12c

Browse files
committed
Auto merge of #14091 - henry40408:issue-14039, r=weihanglo
test: migrate testsuites to snapbox ### What does this PR try to resolve? Part of #14039. Migrate the following testsuites to snapbox: - tests/testsuite/death.rs - ~~tests/testsuite/locate_project.rs~~ see #14091 (comment) - tests/testsuite/message_format.rs - tests/testsuite/precise_pre_release.rs - tests/testsuite/verify_project.rs - tests/testsuite/version.rs ### How should we test and review this PR? N/A ### Additional information N/A
2 parents 361a488 + 2c517d9 commit 96fc12c

File tree

5 files changed

+88
-57
lines changed

5 files changed

+88
-57
lines changed

tests/testsuite/death.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Tests for ctrl-C handling.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::{project, slow_cpu_multiplier};
64
use std::fs;
75
use std::io::{self, Read};

tests/testsuite/message_format.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Tests for --message-format flag.
22
3-
#![allow(deprecated)]
4-
5-
use cargo_test_support::{basic_lib_manifest, basic_manifest, project};
3+
use cargo_test_support::{basic_lib_manifest, basic_manifest, project, str};
64

75
#[cargo_test]
86
fn cannot_specify_two() {
@@ -13,12 +11,14 @@ fn cannot_specify_two() {
1311

1412
let formats = ["human", "json", "short"];
1513

16-
let two_kinds = "error: cannot specify two kinds of `message-format` arguments\n";
1714
for a in formats.iter() {
1815
for b in formats.iter() {
1916
p.cargo(&format!("build --message-format {},{}", a, b))
2017
.with_status(101)
21-
.with_stderr(two_kinds)
18+
.with_stderr_data(str![[r#"
19+
[ERROR] cannot specify two kinds of `message-format` arguments
20+
21+
"#]])
2222
.run();
2323
}
2424
}
@@ -45,6 +45,7 @@ fn double_json_works() {
4545
.run();
4646
}
4747

48+
#[allow(deprecated)]
4849
#[cargo_test]
4950
fn cargo_renders() {
5051
let p = project()
@@ -89,17 +90,17 @@ fn cargo_renders_short() {
8990

9091
p.cargo("check --message-format json-render-diagnostics,json-diagnostic-short")
9192
.with_status(101)
92-
.with_stderr_contains(
93-
"\
94-
[CHECKING] foo [..]
95-
error[..]`main`[..]
96-
",
97-
)
98-
.with_stderr_does_not_contain("note:")
93+
.with_stderr_data(str![[r#"
94+
[CHECKING] foo v0.1.0 ([ROOT]/foo)
95+
error[E0601]: `main` function not found in crate `foo`
96+
[ERROR] could not compile `foo` (bin "foo") due to 1 previous error
97+
98+
"#]])
9999
.run();
100100
}
101101

102102
#[cargo_test]
103+
#[allow(deprecated)]
103104
fn cargo_renders_ansi() {
104105
let p = project()
105106
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
@@ -129,7 +130,24 @@ fn cargo_renders_doctests() {
129130

130131
p.cargo("test --doc --message-format short")
131132
.with_status(101)
132-
.with_stdout_contains("src/lib.rs:2:1: error[E0425]:[..]")
133-
.with_stdout_contains("[..]src/lib.rs - bar (line 1)[..]")
133+
.with_stdout_data(str![[r#"
134+
135+
running 1 test
136+
test src/lib.rs - bar (line 1) ... FAILED
137+
138+
failures:
139+
140+
---- src/lib.rs - bar (line 1) stdout ----
141+
src/lib.rs:2:1: error[E0425]: cannot find function `bar` in this scope
142+
[ERROR] aborting due to 1 previous error
143+
Couldn't compile the test.
144+
145+
failures:
146+
src/lib.rs - bar (line 1)
147+
148+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
149+
150+
151+
"#]])
134152
.run();
135153
}

tests/testsuite/precise_pre_release.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Tests for selecting pre-release versions with `update --precise`.
22
3-
#![allow(deprecated)]
4-
5-
use cargo_test_support::project;
3+
use cargo_test_support::{project, str};
64

75
#[cargo_test]
86
fn requires_nightly_cargo() {
@@ -29,16 +27,17 @@ fn requires_nightly_cargo() {
2927
.with_status(101)
3028
// This error is suffering from #12579 but still demonstrates that updating to
3129
// a pre-release does not work on stable
32-
.with_stderr(
33-
r#"[UPDATING] `dummy-registry` index
30+
.with_stderr_data(str![[r#"
31+
[UPDATING] `dummy-registry` index
3432
[ERROR] failed to select a version for the requirement `my-dependency = "^0.1.1"`
3533
candidate versions found which didn't match: 0.1.2-pre.0
3634
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
3735
required by package `package v0.0.0 ([ROOT]/foo)`
3836
if you are looking for the prerelease package it needs to be specified explicitly
3937
my-dependency = { version = "0.1.2-pre.0" }
40-
perhaps a crate was updated and forgotten to be re-vendored?"#,
41-
)
38+
perhaps a crate was updated and forgotten to be re-vendored?
39+
40+
"#]])
4241
.run()
4342
}
4443

@@ -65,11 +64,11 @@ fn update_pre_release() {
6564

6665
p.cargo("update my-dependency --precise 0.1.2-pre.0 -Zunstable-options")
6766
.masquerade_as_nightly_cargo(&["precise-pre-release"])
68-
.with_stderr(
69-
r#"[UPDATING] `dummy-registry` index
67+
.with_stderr_data(str![[r#"
68+
[UPDATING] `dummy-registry` index
7069
[UPDATING] my-dependency v0.1.1 -> v0.1.2-pre.0
71-
"#,
72-
)
70+
71+
"#]])
7372
.run();
7473
let lockfile = p.read_lockfile();
7574
assert!(lockfile.contains("\nname = \"my-dependency\"\nversion = \"0.1.2-pre.0\""));
@@ -98,20 +97,20 @@ fn update_pre_release_differ() {
9897

9998
p.cargo("update -p my-dependency --precise 0.1.2-pre.0 -Zunstable-options")
10099
.masquerade_as_nightly_cargo(&["precise-pre-release"])
101-
.with_stderr(
102-
r#"[UPDATING] `dummy-registry` index
100+
.with_stderr_data(str![[r#"
101+
[UPDATING] `dummy-registry` index
103102
[DOWNGRADING] my-dependency v0.1.2 -> v0.1.2-pre.0
104-
"#,
105-
)
103+
104+
"#]])
106105
.run();
107106

108107
p.cargo("update -p my-dependency --precise 0.1.2-pre.1 -Zunstable-options")
109108
.masquerade_as_nightly_cargo(&["precise-pre-release"])
110-
.with_stderr(
111-
r#"[UPDATING] `dummy-registry` index
109+
.with_stderr_data(str![[r#"
110+
[UPDATING] `dummy-registry` index
112111
[UPDATING] my-dependency v0.1.2-pre.0 -> v0.1.2-pre.1
113-
"#,
114-
)
112+
113+
"#]])
115114
.run();
116115

117116
let lockfile = p.read_lockfile();

tests/testsuite/verify_project.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
//! Tests for the `cargo verify-project` command.
22
3-
#![allow(deprecated)]
4-
5-
use cargo_test_support::{basic_bin_manifest, main_file, project};
6-
7-
fn verify_project_success_output() -> String {
8-
r#"{"success":"true"}"#.into()
9-
}
3+
use cargo_test_support::{basic_bin_manifest, main_file, project, str};
104

115
#[cargo_test]
126
fn cargo_verify_project_path_to_cargo_toml_relative() {
@@ -17,7 +11,10 @@ fn cargo_verify_project_path_to_cargo_toml_relative() {
1711

1812
p.cargo("verify-project --manifest-path foo/Cargo.toml")
1913
.cwd(p.root().parent().unwrap())
20-
.with_stdout(verify_project_success_output())
14+
.with_stdout_data(str![[r#"
15+
{"success":"true"}
16+
17+
"#]])
2118
.run();
2219
}
2320

@@ -31,7 +28,10 @@ fn cargo_verify_project_path_to_cargo_toml_absolute() {
3128
p.cargo("verify-project --manifest-path")
3229
.arg(p.root().join("Cargo.toml"))
3330
.cwd(p.root().parent().unwrap())
34-
.with_stdout(verify_project_success_output())
31+
.with_stdout_data(str![[r#"
32+
{"success":"true"}
33+
34+
"#]])
3535
.run();
3636
}
3737

@@ -43,7 +43,10 @@ fn cargo_verify_project_cwd() {
4343
.build();
4444

4545
p.cargo("verify-project")
46-
.with_stdout(verify_project_success_output())
46+
.with_stdout_data(str![[r#"
47+
{"success":"true"}
48+
49+
"#]])
4750
.run();
4851
}
4952

@@ -65,11 +68,17 @@ fn cargo_verify_project_honours_unstable_features() {
6568

6669
p.cargo("verify-project")
6770
.masquerade_as_nightly_cargo(&["test-dummy-unstable"])
68-
.with_stdout(verify_project_success_output())
71+
.with_stdout_data(str![[r#"
72+
{"success":"true"}
73+
74+
"#]])
6975
.run();
7076

7177
p.cargo("verify-project")
7278
.with_status(1)
73-
.with_json(r#"{"invalid":"failed to parse manifest at `[CWD]/Cargo.toml`"}"#)
79+
.with_stdout_data(str![[r#"
80+
{"invalid":"failed to parse manifest at `[..]`"}
81+
82+
"#]])
7483
.run();
7584
}

tests/testsuite/version.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
//! Tests for displaying the cargo version.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::{cargo_process, project};
64

75
#[cargo_test]
86
fn simple() {
97
let p = project().build();
108

119
p.cargo("version")
12-
.with_stdout(&format!("cargo {}\n", cargo::version()))
10+
.with_stdout_data(&format!("cargo {}\n", cargo::version()))
1311
.run();
1412

1513
p.cargo("--version")
16-
.with_stdout(&format!("cargo {}\n", cargo::version()))
14+
.with_stdout_data(&format!("cargo {}\n", cargo::version()))
1715
.run();
1816

1917
p.cargo("-V")
20-
.with_stdout(&format!("cargo {}\n", cargo::version()))
18+
.with_stdout_data(&format!("cargo {}\n", cargo::version()))
2119
.run();
2220
}
2321

@@ -53,10 +51,19 @@ fn version_works_with_bad_target_dir() {
5351
fn verbose() {
5452
// This is mainly to check that it doesn't explode.
5553
cargo_process("-vV")
56-
.with_stdout_contains(&format!("cargo {}", cargo::version()))
57-
.with_stdout_contains("host: [..]")
58-
.with_stdout_contains("libgit2: [..]")
59-
.with_stdout_contains("libcurl: [..]")
60-
.with_stdout_contains("os: [..]")
54+
.with_stdout_data(format!(
55+
"\
56+
cargo {}
57+
release: [..]
58+
commit-hash: [..]
59+
commit-date: [..]
60+
host: [HOST_TARGET]
61+
libgit2: [..] (sys:[..] [..])
62+
libcurl: [..] (sys:[..] [..])
63+
...
64+
os: [..]
65+
",
66+
cargo::version()
67+
))
6168
.run();
6269
}

0 commit comments

Comments
 (0)