@@ -395,6 +395,167 @@ fn update_precise() {
395
395
. run ( ) ;
396
396
}
397
397
398
+ // cargo update should respect its arguments even without a lockfile.
399
+ // See issue "Running cargo update without a Cargo.lock ignores arguments"
400
+ // at <https://github.com/rust-lang/cargo/issues/6872>.
401
+ #[ test]
402
+ fn update_precise_first_run ( ) {
403
+ Package :: new ( "serde" , "0.1.0" ) . publish ( ) ;
404
+ Package :: new ( "serde" , "0.2.0" ) . publish ( ) ;
405
+ Package :: new ( "serde" , "0.2.1" ) . publish ( ) ;
406
+
407
+ let p = project ( )
408
+ . file (
409
+ "Cargo.toml" ,
410
+ r#"
411
+ [package]
412
+ name = "bar"
413
+ version = "0.0.1"
414
+
415
+ [dependencies]
416
+ serde = "0.2"
417
+ "# ,
418
+ )
419
+ . file ( "src/lib.rs" , "" )
420
+ . build ( ) ;
421
+
422
+ p. cargo ( "update -p serde --precise 0.2.0" )
423
+ . with_stderr (
424
+ "\
425
+ [UPDATING] `[..]` index
426
+ " ,
427
+ )
428
+ . run ( ) ;
429
+
430
+ // Assert `cargo metadata` shows serde 0.2.0
431
+ p. cargo ( "metadata" )
432
+ . with_json (
433
+ r#"{
434
+ "packages": [
435
+ {
436
+ "authors": [],
437
+ "categories": [],
438
+ "dependencies": [],
439
+ "description": null,
440
+ "edition": "2015",
441
+ "features": {},
442
+ "id": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
443
+ "keywords": [],
444
+ "license": null,
445
+ "license_file": null,
446
+ "links": null,
447
+ "manifest_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/Cargo.toml",
448
+ "metadata": null,
449
+ "name": "serde",
450
+ "readme": null,
451
+ "repository": null,
452
+ "source": "registry+https://github.com/rust-lang/crates.io-index",
453
+ "targets": [
454
+ {
455
+ "crate_types": [
456
+ "lib"
457
+ ],
458
+ "edition": "2015",
459
+ "kind": [
460
+ "lib"
461
+ ],
462
+ "name": "serde",
463
+ "src_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/src/lib.rs"
464
+ }
465
+ ],
466
+ "version": "0.2.0"
467
+ },
468
+ {
469
+ "authors": [],
470
+ "categories": [],
471
+ "dependencies": [
472
+ {
473
+ "features": [],
474
+ "kind": null,
475
+ "name": "serde",
476
+ "optional": false,
477
+ "registry": null,
478
+ "rename": null,
479
+ "req": "^0.2",
480
+ "source": "registry+https://github.com/rust-lang/crates.io-index",
481
+ "target": null,
482
+ "uses_default_features": true
483
+ }
484
+ ],
485
+ "description": null,
486
+ "edition": "2015",
487
+ "features": {},
488
+ "id": "bar 0.0.1 (path+file://[..]/foo)",
489
+ "keywords": [],
490
+ "license": null,
491
+ "license_file": null,
492
+ "links": null,
493
+ "manifest_path": "[..]/foo/Cargo.toml",
494
+ "metadata": null,
495
+ "name": "bar",
496
+ "readme": null,
497
+ "repository": null,
498
+ "source": null,
499
+ "targets": [
500
+ {
501
+ "crate_types": [
502
+ "lib"
503
+ ],
504
+ "edition": "2015",
505
+ "kind": [
506
+ "lib"
507
+ ],
508
+ "name": "bar",
509
+ "src_path": "[..]/foo/src/lib.rs"
510
+ }
511
+ ],
512
+ "version": "0.0.1"
513
+ }
514
+ ],
515
+ "resolve": {
516
+ "nodes": [
517
+ {
518
+ "dependencies": [
519
+ "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
520
+ ],
521
+ "deps": [
522
+ {
523
+ "name": "serde",
524
+ "pkg": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
525
+ }
526
+ ],
527
+ "features": [],
528
+ "id": "bar 0.0.1 (path+file://[..]/foo)"
529
+ },
530
+ {
531
+ "dependencies": [],
532
+ "deps": [],
533
+ "features": [],
534
+ "id": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
535
+ }
536
+ ],
537
+ "root": "bar 0.0.1 (path+file://[..]/foo)"
538
+ },
539
+ "target_directory": "[..]/foo/target",
540
+ "version": 1,
541
+ "workspace_members": [
542
+ "bar 0.0.1 (path+file://[..]/foo)"
543
+ ],
544
+ "workspace_root": "[..]/foo"
545
+ }"# ,
546
+ )
547
+ . run ( ) ;
548
+
549
+ p. cargo ( "update -p serde --precise 0.2.0" )
550
+ . with_stderr (
551
+ "\
552
+ [UPDATING] `[..]` index
553
+ " ,
554
+ )
555
+ . run ( ) ;
556
+
557
+ }
558
+
398
559
#[ test]
399
560
fn preserve_top_comment ( ) {
400
561
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
0 commit comments