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 ( e1 : impl IntoData , e2 : impl IntoData ) {
73
92
Package :: new ( "serde" , "1.0.0" ) . publish ( ) ;
74
93
75
94
let p = project ( )
@@ -88,23 +107,12 @@ fn no_index_update() {
88
107
. file ( "src/main.rs" , "fn main() {}" )
89
108
. build ( ) ;
90
109
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 ( ) ;
99
111
100
112
p. cargo ( "generate-lockfile -Zno-index-update" )
101
113
. 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)
108
116
. run ( ) ;
109
117
}
110
118
@@ -172,13 +180,13 @@ fn cargo_update_generate_lockfile() {
172
180
173
181
let lockfile = p. root ( ) . join ( "Cargo.lock" ) ;
174
182
assert ! ( !lockfile. is_file( ) ) ;
175
- p. cargo ( "update" ) . with_stderr ( "" ) . run ( ) ;
183
+ p. cargo ( "update" ) . with_stderr_data ( "" ) . run ( ) ;
176
184
assert ! ( lockfile. is_file( ) ) ;
177
185
178
186
fs:: remove_file ( p. root ( ) . join ( "Cargo.lock" ) ) . unwrap ( ) ;
179
187
180
188
assert ! ( !lockfile. is_file( ) ) ;
181
- p. cargo ( "update" ) . with_stderr ( "" ) . run ( ) ;
189
+ p. cargo ( "update" ) . with_stderr_data ( "" ) . run ( ) ;
182
190
assert ! ( lockfile. is_file( ) ) ;
183
191
}
184
192
@@ -233,11 +241,10 @@ fn duplicate_entries_in_lockfile() {
233
241
// should fail due to a duplicate package `common` in the lock file
234
242
b. cargo ( "build" )
235
243
. 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
+ "# ] ] )
241
248
. run ( ) ;
242
249
}
243
250
@@ -260,19 +267,17 @@ fn generate_lockfile_holds_lock_and_offline() {
260
267
. build ( ) ;
261
268
262
269
p. cargo ( "generate-lockfile" )
263
- . with_stderr (
264
- "\
265
- [UPDATING] `[..]` index
270
+ . with_stderr_data ( str![ [ r#"
271
+ [UPDATING] `dummy-registry` index
266
272
[LOCKING] 2 packages to latest compatible versions
267
- " ,
268
- )
273
+
274
+ "# ] ] )
269
275
. run ( ) ;
270
276
271
277
p. cargo ( "generate-lockfile --offline" )
272
- . with_stderr_contains (
273
- "\
278
+ . with_stderr_data ( str![ [ r#"
274
279
[LOCKING] 2 packages to latest compatible versions
275
- " ,
276
- )
280
+
281
+ "# ] ] )
277
282
. run ( ) ;
278
283
}
0 commit comments