Skip to content

Commit e6033fa

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

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

tests/testsuite/generate_lockfile.rs

Lines changed: 41 additions & 36 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(e1: impl IntoData, e2: impl IntoData) {
7392
Package::new("serde", "1.0.0").publish();
7493

7594
let p = project()
@@ -88,23 +107,12 @@ fn no_index_update() {
88107
.file("src/main.rs", "fn main() {}")
89108
.build();
90109

91-
p.cargo("generate-lockfile")
92-
.with_stderr(
93-
"\
94-
[UPDATING] `[..]` index
95-
[LOCKING] 2 packages to latest compatible versions
96-
",
97-
)
98-
.run();
110+
p.cargo("generate-lockfile").with_stderr_data(e1).run();
99111

100112
p.cargo("generate-lockfile -Zno-index-update")
101113
.masquerade_as_nightly_cargo(&["no-index-update"])
102-
.with_stdout("")
103-
.with_stderr(
104-
"\
105-
[LOCKING] 2 packages to latest compatible versions
106-
",
107-
)
114+
.with_stdout_data("")
115+
.with_stderr_data(e2)
108116
.run();
109117
}
110118

@@ -172,13 +180,13 @@ fn cargo_update_generate_lockfile() {
172180

173181
let lockfile = p.root().join("Cargo.lock");
174182
assert!(!lockfile.is_file());
175-
p.cargo("update").with_stderr("").run();
183+
p.cargo("update").with_stderr_data("").run();
176184
assert!(lockfile.is_file());
177185

178186
fs::remove_file(p.root().join("Cargo.lock")).unwrap();
179187

180188
assert!(!lockfile.is_file());
181-
p.cargo("update").with_stderr("").run();
189+
p.cargo("update").with_stderr_data("").run();
182190
assert!(lockfile.is_file());
183191
}
184192

@@ -233,11 +241,10 @@ fn duplicate_entries_in_lockfile() {
233241
// should fail due to a duplicate package `common` in the lock file
234242
b.cargo("build")
235243
.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-
)
244+
.with_stderr_data(str![[r#"
245+
[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
246+
247+
"#]])
241248
.run();
242249
}
243250

@@ -260,19 +267,17 @@ fn generate_lockfile_holds_lock_and_offline() {
260267
.build();
261268

262269
p.cargo("generate-lockfile")
263-
.with_stderr(
264-
"\
265-
[UPDATING] `[..]` index
270+
.with_stderr_data(str![[r#"
271+
[UPDATING] `dummy-registry` index
266272
[LOCKING] 2 packages to latest compatible versions
267-
",
268-
)
273+
274+
"#]])
269275
.run();
270276

271277
p.cargo("generate-lockfile --offline")
272-
.with_stderr_contains(
273-
"\
278+
.with_stderr_data(str![[r#"
274279
[LOCKING] 2 packages to latest compatible versions
275-
",
276-
)
280+
281+
"#]])
277282
.run();
278283
}

0 commit comments

Comments
 (0)