@@ -8,9 +8,36 @@ use hamcrest::assert_that;
88
99#[ test]
1010fn oldest_lockfile_still_works ( ) {
11+ let cargo_commands = vec ! [
12+ "build" ,
13+ "update"
14+ ] ;
15+ for cargo_command in cargo_commands {
16+ oldest_lockfile_still_works_with_command ( cargo_command) ;
17+ }
18+ }
19+
20+ fn oldest_lockfile_still_works_with_command ( cargo_command : & str ) {
1121 Package :: new ( "foo" , "0.1.0" ) . publish ( ) ;
1222
13- let lockfile = r#"
23+ let expected_lockfile =
24+ r#"[[package]]
25+ name = "bar"
26+ version = "0.0.1"
27+ dependencies = [
28+ "foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
29+ ]
30+
31+ [[package]]
32+ name = "foo"
33+ version = "0.1.0"
34+ source = "registry+https://github.com/rust-lang/crates.io-index"
35+
36+ [metadata]
37+ "checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "[..]"
38+ "# ;
39+
40+ let old_lockfile = r#"
1441[root]
1542name = "bar"
1643version = "0.0.1"
@@ -35,14 +62,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
3562 foo = "0.1.0"
3663 "# )
3764 . file ( "src/lib.rs" , "" )
38- . file ( "Cargo.lock" , lockfile) ;
65+ . file ( "Cargo.lock" , old_lockfile) ;
66+
3967 p. build ( ) ;
4068
41- assert_that ( p. cargo ( "build" ) ,
69+ assert_that ( p. cargo ( cargo_command ) ,
4270 execs ( ) . with_status ( 0 ) ) ;
4371
4472 let lock = p. read_lockfile ( ) ;
45- assert ! ( lock. starts_with( lockfile. trim( ) ) ) ;
73+ for ( l, r) in expected_lockfile. lines ( ) . zip ( lock. lines ( ) ) {
74+ assert ! ( lines_match( l, r) , "Lines differ:\n {}\n \n {}" , l, r) ;
75+ }
76+
77+ assert_eq ! ( lock. lines( ) . count( ) , expected_lockfile. lines( ) . count( ) ) ;
4678}
4779
4880#[ test]
@@ -61,7 +93,7 @@ fn totally_wild_checksums_works() {
6193 "# )
6294 . file ( "src/lib.rs" , "" )
6395 . file ( "Cargo.lock" , r#"
64- [root ]
96+ [[package] ]
6597name = "bar"
6698version = "0.0.1"
6799dependencies = [
@@ -85,7 +117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
85117
86118 let lock = p. read_lockfile ( ) ;
87119 assert ! ( lock. starts_with( r#"
88- [root ]
120+ [[package] ]
89121name = "bar"
90122version = "0.0.1"
91123dependencies = [
@@ -117,7 +149,7 @@ fn wrong_checksum_is_an_error() {
117149 "# )
118150 . file ( "src/lib.rs" , "" )
119151 . file ( "Cargo.lock" , r#"
120- [root ]
152+ [[package] ]
121153name = "bar"
122154version = "0.0.1"
123155dependencies = [
@@ -170,7 +202,7 @@ fn unlisted_checksum_is_bad_if_we_calculate() {
170202 "# )
171203 . file ( "src/lib.rs" , "" )
172204 . file ( "Cargo.lock" , r#"
173- [root ]
205+ [[package] ]
174206name = "bar"
175207version = "0.0.1"
176208dependencies = [
@@ -230,7 +262,7 @@ fn listed_checksum_bad_if_we_cannot_compute() {
230262 "# , git. url( ) ) )
231263 . file ( "src/lib.rs" , "" )
232264 . file ( "Cargo.lock" , & format ! ( r#"
233- [root ]
265+ [[package] ]
234266name = "bar"
235267version = "0.0.1"
236268dependencies = [
@@ -287,7 +319,7 @@ fn current_lockfile_format() {
287319 let actual = p. read_lockfile ( ) ;
288320
289321 let expected = "\
290- [root ]
322+ [[package] ]
291323name = \" bar\"
292324version = \" 0.0.1\"
293325dependencies = [
0 commit comments