@@ -7,15 +7,64 @@ use snapbox::str;
77use cargo_test_support:: compare:: assert_e2e;
88use cargo_test_support:: registry:: { Package , RegistryBuilder } ;
99use cargo_test_support:: {
10- basic_bin_manifest, cargo_test, project, symlink_supported, Execs , ProjectBuilder ,
10+ basic_bin_manifest, cargo_test, project, symlink_supported, ProjectBuilder ,
1111} ;
1212
13+ ///////////////////////////////
14+ //// Unstable feature tests start
15+ ///////////////////////////////
16+
17+ #[ cargo_test]
18+ fn must_have_unstable_options ( ) {
19+ let lockfile_path = "mylockfile/is/burried/Cargo.lock" ;
20+ let p = make_project ( ) . build ( ) ;
21+
22+ p. cargo ( "generate-lockfile" )
23+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
24+ . arg ( "--lockfile-path" )
25+ . arg ( lockfile_path)
26+ . with_stderr_data ( str![ [
27+ r#"[ERROR] the `--lockfile-path` flag is unstable, pass `-Z unstable-options` to enable it
28+ See https://github.com/rust-lang/cargo/issues/5707 for more information about the `--lockfile-path` flag.
29+
30+ "# ] ] )
31+ . with_status ( 101 )
32+ . run ( ) ;
33+ }
34+
35+ #[ cargo_test]
36+ fn must_be_nightly ( ) {
37+ let lockfile_path = "mylockfile/is/burried/Cargo.lock" ;
38+ let p = make_project ( ) . build ( ) ;
39+
40+ p. cargo ( "generate-lockfile" )
41+ . arg ( "-Zunstable-options" )
42+ . arg ( "--lockfile-path" )
43+ . arg ( lockfile_path)
44+ . with_stderr_data ( str![ [
45+ r#"[ERROR] the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
46+ See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
47+
48+ "# ] ] )
49+ . with_status ( 101 )
50+ . run ( ) ;
51+ }
52+
53+ ///////////////////////////////
54+ //// Unstable feature tests end
55+ ///////////////////////////////
56+
1357#[ cargo_test]
1458fn basic_lockfile_created ( ) {
1559 let lockfile_path = "mylockfile/is/burried/Cargo.lock" ;
1660 let p = make_project ( ) . build ( ) ;
1761
18- make_execs ( & mut p. cargo ( "generate-lockfile" ) , lockfile_path) . run ( ) ;
62+ p. cargo ( "generate-lockfile" )
63+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
64+ . arg ( "-Zunstable-options" )
65+ . arg ( "--lockfile-path" )
66+ . arg ( lockfile_path)
67+ . run ( ) ;
1968 assert ! ( !p. root( ) . join( "Cargo.lock" ) . exists( ) ) ;
2069 assert ! ( p. root( ) . join( lockfile_path) . is_file( ) ) ;
2170}
@@ -25,7 +74,12 @@ fn basic_lockfile_read() {
2574 let lockfile_path = "mylockfile/Cargo.lock" ;
2675 let p = make_project ( ) . file ( lockfile_path, VALID_LOCKFILE ) . build ( ) ;
2776
28- make_execs ( & mut p. cargo ( "generate-lockfile" ) , lockfile_path) . run ( ) ;
77+ p. cargo ( "generate-lockfile" )
78+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
79+ . arg ( "-Zunstable-options" )
80+ . arg ( "--lockfile-path" )
81+ . arg ( lockfile_path)
82+ . run ( ) ;
2983
3084 assert ! ( !p. root( ) . join( "Cargo.lock" ) . exists( ) ) ;
3185 assert ! ( p. root( ) . join( lockfile_path) . is_file( ) ) ;
@@ -38,7 +92,12 @@ fn basic_lockfile_override() {
3892 . file ( "Cargo.lock" , "This is an invalid lock file!" )
3993 . build ( ) ;
4094
41- make_execs ( & mut p. cargo ( "generate-lockfile" ) , lockfile_path) . run ( ) ;
95+ p. cargo ( "generate-lockfile" )
96+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
97+ . arg ( "-Zunstable-options" )
98+ . arg ( "--lockfile-path" )
99+ . arg ( lockfile_path)
100+ . run ( ) ;
42101
43102 assert ! ( p. root( ) . join( lockfile_path) . is_file( ) ) ;
44103}
@@ -62,7 +121,12 @@ fn symlink_in_path() {
62121 fs:: create_dir ( p. root ( ) . join ( "dst" ) ) . unwrap ( ) ;
63122 assert ! ( p. root( ) . join( src) . is_dir( ) ) ;
64123
65- make_execs ( & mut p. cargo ( "generate-lockfile" ) , lockfile_path. as_str ( ) ) . run ( ) ;
124+ p. cargo ( "generate-lockfile" )
125+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
126+ . arg ( "-Zunstable-options" )
127+ . arg ( "--lockfile-path" )
128+ . arg ( lockfile_path. as_str ( ) )
129+ . run ( ) ;
66130
67131 assert ! ( p. root( ) . join( lockfile_path) . is_file( ) ) ;
68132 assert ! ( p. root( ) . join( dst) . join( "Cargo.lock" ) . is_file( ) ) ;
@@ -85,7 +149,12 @@ fn symlink_lockfile() {
85149
86150 assert ! ( p. root( ) . join( src) . is_file( ) ) ;
87151
88- make_execs ( & mut p. cargo ( "generate-lockfile" ) , lockfile_path) . run ( ) ;
152+ p. cargo ( "generate-lockfile" )
153+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
154+ . arg ( "-Zunstable-options" )
155+ . arg ( "--lockfile-path" )
156+ . arg ( lockfile_path)
157+ . run ( ) ;
89158
90159 assert ! ( !p. root( ) . join( "Cargo.lock" ) . exists( ) ) ;
91160}
@@ -103,7 +172,11 @@ fn broken_symlink() {
103172 let p = make_project ( ) . symlink_dir ( invalid_dst, src) . build ( ) ;
104173 assert ! ( !p. root( ) . join( src) . is_dir( ) ) ;
105174
106- make_execs ( & mut p. cargo ( "generate-lockfile" ) , lockfile_path. as_str ( ) )
175+ p. cargo ( "generate-lockfile" )
176+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
177+ . arg ( "-Zunstable-options" )
178+ . arg ( "--lockfile-path" )
179+ . arg ( lockfile_path)
107180 . with_status ( 101 )
108181 . with_stderr_data ( str![ [
109182 r#"[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
@@ -131,7 +204,11 @@ fn loop_symlink() {
131204 . build ( ) ;
132205 assert ! ( !p. root( ) . join( src) . is_dir( ) ) ;
133206
134- make_execs ( & mut p. cargo ( "generate-lockfile" ) , lockfile_path. as_str ( ) )
207+ p. cargo ( "generate-lockfile" )
208+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
209+ . arg ( "-Zunstable-options" )
210+ . arg ( "--lockfile-path" )
211+ . arg ( lockfile_path)
135212 . with_status ( 101 )
136213 . with_stderr_data ( str![ [
137214 r#"[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
@@ -158,7 +235,11 @@ fn add_lockfile_override() {
158235 let p = make_project ( )
159236 . file ( "Cargo.lock" , "This is an invalid lock file!" )
160237 . build ( ) ;
161- make_execs ( & mut p. cargo ( "add" ) , lockfile_path)
238+ p. cargo ( "add" )
239+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
240+ . arg ( "-Zunstable-options" )
241+ . arg ( "--lockfile-path" )
242+ . arg ( lockfile_path)
162243 . arg ( "--path" )
163244 . arg ( "../bar" )
164245 . run ( ) ;
@@ -172,7 +253,11 @@ fn clean_lockfile_override() {
172253 let p = make_project ( )
173254 . file ( "Cargo.lock" , "This is an invalid lock file!" )
174255 . build ( ) ;
175- make_execs ( & mut p. cargo ( "clean" ) , lockfile_path)
256+ p. cargo ( "clean" )
257+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
258+ . arg ( "-Zunstable-options" )
259+ . arg ( "--lockfile-path" )
260+ . arg ( lockfile_path)
176261 . arg ( "--package" )
177262 . arg ( "test_foo" )
178263 . run ( ) ;
@@ -186,7 +271,11 @@ fn fix_lockfile_override() {
186271 let p = make_project ( )
187272 . file ( "Cargo.lock" , "This is an invalid lock file!" )
188273 . build ( ) ;
189- make_execs ( & mut p. cargo ( "fix" ) , lockfile_path)
274+ p. cargo ( "fix" )
275+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
276+ . arg ( "-Zunstable-options" )
277+ . arg ( "--lockfile-path" )
278+ . arg ( lockfile_path)
190279 . arg ( "--package" )
191280 . arg ( "test_foo" )
192281 . arg ( "--allow-no-vcs" )
@@ -201,7 +290,11 @@ fn publish_lockfile_read() {
201290 let p = make_project ( ) . file ( lockfile_path, VALID_LOCKFILE ) . build ( ) ;
202291 let registry = RegistryBuilder :: new ( ) . http_api ( ) . http_index ( ) . build ( ) ;
203292
204- make_execs ( & mut p. cargo ( "publish" ) , lockfile_path)
293+ p. cargo ( "publish" )
294+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
295+ . arg ( "-Zunstable-options" )
296+ . arg ( "--lockfile-path" )
297+ . arg ( lockfile_path)
205298 . replace_crates_io ( registry. index_url ( ) )
206299 . run ( ) ;
207300
@@ -239,7 +332,11 @@ fn remove_lockfile_override() {
239332 . file ( "src/main.rs" , "fn main() {}" )
240333 . file ( "Cargo.lock" , "This is an invalid lock file!" )
241334 . build ( ) ;
242- make_execs ( & mut p. cargo ( "remove" ) , lockfile_path)
335+ p. cargo ( "remove" )
336+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
337+ . arg ( "-Zunstable-options" )
338+ . arg ( "--lockfile-path" )
339+ . arg ( lockfile_path)
243340 . arg ( "test_bar" )
244341 . run ( ) ;
245342
@@ -272,15 +369,25 @@ bar = "0.1.0"
272369 . build ( ) ;
273370
274371 Package :: new ( "bar" , "0.1.0" ) . publish ( ) ;
275- make_execs ( & mut p. cargo ( "generate-lockfile" ) , lockfile_path) . run ( ) ;
372+ p. cargo ( "generate-lockfile" )
373+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
374+ . arg ( "-Zunstable-options" )
375+ . arg ( "--lockfile-path" )
376+ . arg ( lockfile_path)
377+ . run ( ) ;
276378
277379 assert ! ( !p. root( ) . join( "Cargo.lock" ) . exists( ) ) ;
278380 assert ! ( p. root( ) . join( lockfile_path) . is_file( ) ) ;
279381
280382 let lockfile_original = fs:: read_to_string ( p. root ( ) . join ( lockfile_path) ) . unwrap ( ) ;
281383
282384 Package :: new ( "bar" , "0.1.1" ) . publish ( ) ;
283- make_execs ( & mut p. cargo ( "package" ) , lockfile_path) . run ( ) ;
385+ p. cargo ( "package" )
386+ . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
387+ . arg ( "-Zunstable-options" )
388+ . arg ( "--lockfile-path" )
389+ . arg ( lockfile_path)
390+ . run ( ) ;
284391
285392 assert ! ( p
286393 . root( )
@@ -353,11 +460,3 @@ fn make_project() -> ProjectBuilder {
353460 . file ( "Cargo.toml" , & basic_bin_manifest ( "test_foo" ) )
354461 . file ( "src/main.rs" , "fn main() {}" )
355462}
356-
357- fn make_execs < ' a > ( execs : & ' a mut Execs , lockfile_path_argument : & str ) -> & ' a mut Execs {
358- execs
359- . masquerade_as_nightly_cargo ( & [ "lockfile-path" ] )
360- . arg ( "-Zunstable-options" )
361- . arg ( "--lockfile-path" )
362- . arg ( lockfile_path_argument)
363- }
0 commit comments