1
1
//! Tests for the `cargo generate-lockfile` command.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
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 ;
7
6
use std:: fs;
8
7
9
8
#[ cargo_test]
@@ -61,15 +60,35 @@ fn adding_and_removing_packages() {
61
60
#[ cargo_test]
62
61
fn no_index_update_sparse ( ) {
63
62
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
+ ) ;
65
74
}
66
75
67
76
#[ cargo_test]
68
77
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
+ ) ;
70
89
}
71
90
72
- fn no_index_update ( ) {
91
+ fn no_index_update ( expected : impl IntoData , expected_unstable_option : impl IntoData ) {
73
92
Package :: new ( "serde" , "1.0.0" ) . publish ( ) ;
74
93
75
94
let p = project ( )
@@ -89,22 +108,13 @@ fn no_index_update() {
89
108
. build ( ) ;
90
109
91
110
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)
98
112
. run ( ) ;
99
113
100
114
p. cargo ( "generate-lockfile -Zno-index-update" )
101
115
. 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)
108
118
. run ( ) ;
109
119
}
110
120
@@ -172,13 +182,13 @@ fn cargo_update_generate_lockfile() {
172
182
173
183
let lockfile = p. root ( ) . join ( "Cargo.lock" ) ;
174
184
assert ! ( !lockfile. is_file( ) ) ;
175
- p. cargo ( "update" ) . with_stderr ( "" ) . run ( ) ;
185
+ p. cargo ( "update" ) . with_stderr_data ( "" ) . run ( ) ;
176
186
assert ! ( lockfile. is_file( ) ) ;
177
187
178
188
fs:: remove_file ( p. root ( ) . join ( "Cargo.lock" ) ) . unwrap ( ) ;
179
189
180
190
assert ! ( !lockfile. is_file( ) ) ;
181
- p. cargo ( "update" ) . with_stderr ( "" ) . run ( ) ;
191
+ p. cargo ( "update" ) . with_stderr_data ( "" ) . run ( ) ;
182
192
assert ! ( lockfile. is_file( ) ) ;
183
193
}
184
194
@@ -233,11 +243,10 @@ fn duplicate_entries_in_lockfile() {
233
243
// should fail due to a duplicate package `common` in the lock file
234
244
b. cargo ( "build" )
235
245
. 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
+ "# ] ] )
241
250
. run ( ) ;
242
251
}
243
252
@@ -260,19 +269,17 @@ fn generate_lockfile_holds_lock_and_offline() {
260
269
. build ( ) ;
261
270
262
271
p. cargo ( "generate-lockfile" )
263
- . with_stderr (
264
- "\
265
- [UPDATING] `[..]` index
272
+ . with_stderr_data ( str![ [ r#"
273
+ [UPDATING] `dummy-registry` index
266
274
[LOCKING] 2 packages to latest compatible versions
267
- " ,
268
- )
275
+
276
+ "# ] ] )
269
277
. run ( ) ;
270
278
271
279
p. cargo ( "generate-lockfile --offline" )
272
- . with_stderr_contains (
273
- "\
280
+ . with_stderr_data ( str![ [ r#"
274
281
[LOCKING] 2 packages to latest compatible versions
275
- " ,
276
- )
282
+
283
+ "# ] ] )
277
284
. run ( ) ;
278
285
}
0 commit comments