Skip to content

Commit abe43b7

Browse files
committed
test: migrate generate_lockfile to snapbox
1 parent a495ed8 commit abe43b7

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

tests/testsuite/generate_lockfile.rs

Lines changed: 41 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

@@ -233,11 +243,10 @@ fn duplicate_entries_in_lockfile() {
233243
// should fail due to a duplicate package `common` in the lock file
234244
b.cargo("build")
235245
.with_status(101)
236-
.with_stderr_contains(
237-
"[..]package collision in the lockfile: packages common [..] and \
238-
common [..] are different, but only one can be written to \
239-
lockfile unambiguously",
240-
)
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+
"#]])
241250
.run();
242251
}
243252

@@ -260,19 +269,17 @@ fn generate_lockfile_holds_lock_and_offline() {
260269
.build();
261270

262271
p.cargo("generate-lockfile")
263-
.with_stderr(
264-
"\
265-
[UPDATING] `[..]` index
272+
.with_stderr_data(str![[r#"
273+
[UPDATING] `dummy-registry` index
266274
[LOCKING] 2 packages to latest compatible versions
267-
",
268-
)
275+
276+
"#]])
269277
.run();
270278

271279
p.cargo("generate-lockfile --offline")
272-
.with_stderr_contains(
273-
"\
280+
.with_stderr_data(str![[r#"
274281
[LOCKING] 2 packages to latest compatible versions
275-
",
276-
)
282+
283+
"#]])
277284
.run();
278285
}

0 commit comments

Comments
 (0)