Skip to content

Commit d1a62df

Browse files
committed
Auto merge of #14200 - eth3lbert:snapbox-g, r=epage
test: migrate generate_lockfile and glob_targets to snapbox ### What does this PR try to resolve? Part of #14039. Migrate following to snapbox: - `tests/testsuite/generate_lockfile.rs` - `tests/testsuite/glob_targets.rs`
2 parents 1b2828a + 874c05b commit d1a62df

File tree

2 files changed

+276
-302
lines changed

2 files changed

+276
-302
lines changed

tests/testsuite/generate_lockfile.rs

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! Tests for the `cargo generate-lockfile` command.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::registry::{Package, RegistryBuilder};
6-
use cargo_test_support::{basic_manifest, paths, project, ProjectBuilder};
4+
use cargo_test_support::{basic_manifest, paths, project, str, ProjectBuilder};
5+
use snapbox::IntoData;
76
use std::fs;
87

98
#[cargo_test]
@@ -61,15 +60,35 @@ fn adding_and_removing_packages() {
6160
#[cargo_test]
6261
fn no_index_update_sparse() {
6362
let _registry = RegistryBuilder::new().http_index().build();
64-
no_index_update();
63+
no_index_update(
64+
str![[r#"
65+
[UPDATING] `dummy-registry` index
66+
[LOCKING] 2 packages to latest compatible versions
67+
68+
"#]],
69+
str![[r#"
70+
[LOCKING] 2 packages to latest compatible versions
71+
72+
"#]],
73+
);
6574
}
6675

6776
#[cargo_test]
6877
fn no_index_update_git() {
69-
no_index_update();
78+
no_index_update(
79+
str![[r#"
80+
[UPDATING] `dummy-registry` index
81+
[LOCKING] 2 packages to latest compatible versions
82+
83+
"#]],
84+
str![[r#"
85+
[LOCKING] 2 packages to latest compatible versions
86+
87+
"#]],
88+
);
7089
}
7190

72-
fn no_index_update() {
91+
fn no_index_update(expected: impl IntoData, expected_unstable_option: impl IntoData) {
7392
Package::new("serde", "1.0.0").publish();
7493

7594
let p = project()
@@ -89,22 +108,13 @@ fn no_index_update() {
89108
.build();
90109

91110
p.cargo("generate-lockfile")
92-
.with_stderr(
93-
"\
94-
[UPDATING] `[..]` index
95-
[LOCKING] 2 packages to latest compatible versions
96-
",
97-
)
111+
.with_stderr_data(expected)
98112
.run();
99113

100114
p.cargo("generate-lockfile -Zno-index-update")
101115
.masquerade_as_nightly_cargo(&["no-index-update"])
102-
.with_stdout("")
103-
.with_stderr(
104-
"\
105-
[LOCKING] 2 packages to latest compatible versions
106-
",
107-
)
116+
.with_stdout_data("")
117+
.with_stderr_data(expected_unstable_option)
108118
.run();
109119
}
110120

@@ -172,13 +182,13 @@ fn cargo_update_generate_lockfile() {
172182

173183
let lockfile = p.root().join("Cargo.lock");
174184
assert!(!lockfile.is_file());
175-
p.cargo("update").with_stderr("").run();
185+
p.cargo("update").with_stderr_data("").run();
176186
assert!(lockfile.is_file());
177187

178188
fs::remove_file(p.root().join("Cargo.lock")).unwrap();
179189

180190
assert!(!lockfile.is_file());
181-
p.cargo("update").with_stderr("").run();
191+
p.cargo("update").with_stderr_data("").run();
182192
assert!(lockfile.is_file());
183193
}
184194

@@ -215,6 +225,7 @@ fn duplicate_entries_in_lockfile() {
215225
name = "b"
216226
authors = []
217227
version = "0.0.1"
228+
edition = "2015"
218229
219230
[dependencies]
220231
common = {path="common"}
@@ -232,11 +243,10 @@ fn duplicate_entries_in_lockfile() {
232243
// should fail due to a duplicate package `common` in the lock file
233244
b.cargo("build")
234245
.with_status(101)
235-
.with_stderr_contains(
236-
"[..]package collision in the lockfile: packages common [..] and \
237-
common [..] are different, but only one can be written to \
238-
lockfile unambiguously",
239-
)
246+
.with_stderr_data(str![[r#"
247+
[ERROR] package collision in the lockfile: packages common v0.0.1 ([ROOT]/a/common) and common v0.0.1 ([ROOT]/b/common) are different, but only one can be written to lockfile unambiguously
248+
249+
"#]])
240250
.run();
241251
}
242252

@@ -259,19 +269,17 @@ fn generate_lockfile_holds_lock_and_offline() {
259269
.build();
260270

261271
p.cargo("generate-lockfile")
262-
.with_stderr(
263-
"\
264-
[UPDATING] `[..]` index
272+
.with_stderr_data(str![[r#"
273+
[UPDATING] `dummy-registry` index
265274
[LOCKING] 2 packages to latest compatible versions
266-
",
267-
)
275+
276+
"#]])
268277
.run();
269278

270279
p.cargo("generate-lockfile --offline")
271-
.with_stderr_contains(
272-
"\
280+
.with_stderr_data(str![[r#"
273281
[LOCKING] 2 packages to latest compatible versions
274-
",
275-
)
282+
283+
"#]])
276284
.run();
277285
}

0 commit comments

Comments
 (0)