@@ -4,11 +4,10 @@ use std::fs;
4
4
5
5
use snapbox:: str;
6
6
7
- use cargo_test_support:: paths:: CargoPathExt ;
8
7
use cargo_test_support:: registry:: RegistryBuilder ;
9
8
use cargo_test_support:: {
10
- basic_bin_manifest, basic_lib_manifest , cargo_test, paths , project, symlink_supported, Execs ,
11
- Project , ProjectBuilder ,
9
+ basic_bin_manifest, cargo_test, project, symlink_supported, Execs ,
10
+ ProjectBuilder ,
12
11
} ;
13
12
14
13
const VALID_LOCKFILE : & str = r#"# Test lockfile
@@ -41,7 +40,7 @@ fn make_basic_command(execs: &mut Execs, lockfile_path_argument: String) -> &mut
41
40
}
42
41
43
42
fn lockfile_must_exist ( command : & str ) -> bool {
44
- return command == "pkgid" || command == "publish" ;
43
+ return command == "pkgid" || command == "publish" || command == "package" ;
45
44
}
46
45
47
46
fn assert_lockfile_created (
@@ -332,7 +331,7 @@ tests!(fetch, "fetch");
332
331
tests ! ( fix, "fix" , make_fix_command, make_basic_project) ;
333
332
tests ! ( generate_lockfile, "generate-lockfile" ) ;
334
333
tests ! ( metadata, "metadata" ) ;
335
- // tests!(package, "package"); // TODO: check why lockfile is not generated
334
+ tests ! ( package, "package" ) ;
336
335
tests ! ( pkgid, "pkgid" ) ;
337
336
tests ! ( publish, "publish" ) ;
338
337
tests ! ( remove, "remove" , make_remove_command, make_remove_project) ;
@@ -343,3 +342,65 @@ tests!(test, "test");
343
342
tests ! ( tree, "tree" ) ;
344
343
tests ! ( update, "update" ) ;
345
344
tests ! ( vendor, "vendor" ) ;
345
+
346
+ #[ cfg( test) ]
347
+ mod package_extra {
348
+ use std:: fs;
349
+ use cargo_test_support:: { cargo_test, project} ;
350
+ use crate :: lockfile_path:: { make_basic_command} ;
351
+
352
+ #[ cargo_test( nightly, reason = "--lockfile-path is unstable" ) ]
353
+ fn assert_respect_pinned_version_from_lockfile_path ( ) {
354
+ const PINNED_VERSION : & str = r#"# This file is automatically @generated by Cargo.
355
+ # It is not intended for manual editing.
356
+ version = 3
357
+
358
+ [[package]]
359
+ name = "hello"
360
+ version = "1.0.2"
361
+ source = "registry+https://github.com/rust-lang/crates.io-index"
362
+ checksum = "2b94f16c310ebbd9efcca5a5a17131d70bd454876f2af007f3da211afadff4fc"
363
+
364
+ [[package]]
365
+ name = "test_foo"
366
+ version = "0.5.0"
367
+ dependencies = [
368
+ "hello",
369
+ ]
370
+ "# ;
371
+ const TOML : & str = r#"#
372
+ [package]
373
+
374
+ name = "test_foo"
375
+ version = "0.5.0"
376
+
377
+ edition = "2015"
378
+
379
+ [[bin]]
380
+
381
+ name = "test_foo"
382
+
383
+ [dependencies]
384
+ hello = "1.0.0"
385
+ "# ;
386
+
387
+ let lockfile_path_argument = "mylockfile/Cargo.lock" ;
388
+ let p = project ( )
389
+ . file ( "Cargo.toml" , TOML )
390
+ . file ( "src/main.rs" , "fn main() {}" )
391
+ . file ( "mylockfile/Cargo.lock" , PINNED_VERSION )
392
+ . build ( ) ;
393
+
394
+ make_basic_command ( & mut p. cargo ( "package" ) , lockfile_path_argument. to_string ( ) ) . run ( ) ;
395
+
396
+ assert ! ( !p. root( ) . join( "Cargo.lock" ) . is_file( ) ) ;
397
+ assert ! ( p. root( ) . join( lockfile_path_argument) . is_file( ) ) ;
398
+
399
+ assert ! ( p. root( ) . join( "target/package/test_foo-0.5.0/Cargo.lock" ) . is_file( ) ) ;
400
+
401
+ let path = p. root ( ) . join ( "target/package/test_foo-0.5.0/Cargo.lock" ) ;
402
+ let contents = fs:: read_to_string ( path) . unwrap ( ) ;
403
+
404
+ assert_eq ! ( contents, PINNED_VERSION ) ;
405
+ }
406
+ }
0 commit comments