@@ -395,6 +395,168 @@ fn update_precise() {
395395 . run ( ) ;
396396}
397397
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+ [UPDATING] serde v0.2.1 -> v0.2.0
427+ " ,
428+ )
429+ . run ( ) ;
430+
431+ // Assert `cargo metadata` shows serde 0.2.0
432+ p. cargo ( "metadata" )
433+ . with_json (
434+ r#"{
435+ "packages": [
436+ {
437+ "authors": [],
438+ "categories": [],
439+ "dependencies": [],
440+ "description": null,
441+ "edition": "2015",
442+ "features": {},
443+ "id": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
444+ "keywords": [],
445+ "license": null,
446+ "license_file": null,
447+ "links": null,
448+ "manifest_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/Cargo.toml",
449+ "metadata": null,
450+ "name": "serde",
451+ "readme": null,
452+ "repository": null,
453+ "source": "registry+https://github.com/rust-lang/crates.io-index",
454+ "targets": [
455+ {
456+ "crate_types": [
457+ "lib"
458+ ],
459+ "edition": "2015",
460+ "kind": [
461+ "lib"
462+ ],
463+ "name": "serde",
464+ "src_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/src/lib.rs"
465+ }
466+ ],
467+ "version": "0.2.0"
468+ },
469+ {
470+ "authors": [],
471+ "categories": [],
472+ "dependencies": [
473+ {
474+ "features": [],
475+ "kind": null,
476+ "name": "serde",
477+ "optional": false,
478+ "registry": null,
479+ "rename": null,
480+ "req": "^0.2",
481+ "source": "registry+https://github.com/rust-lang/crates.io-index",
482+ "target": null,
483+ "uses_default_features": true
484+ }
485+ ],
486+ "description": null,
487+ "edition": "2015",
488+ "features": {},
489+ "id": "bar 0.0.1 (path+file://[..]/foo)",
490+ "keywords": [],
491+ "license": null,
492+ "license_file": null,
493+ "links": null,
494+ "manifest_path": "[..]/foo/Cargo.toml",
495+ "metadata": null,
496+ "name": "bar",
497+ "readme": null,
498+ "repository": null,
499+ "source": null,
500+ "targets": [
501+ {
502+ "crate_types": [
503+ "lib"
504+ ],
505+ "edition": "2015",
506+ "kind": [
507+ "lib"
508+ ],
509+ "name": "bar",
510+ "src_path": "[..]/foo/src/lib.rs"
511+ }
512+ ],
513+ "version": "0.0.1"
514+ }
515+ ],
516+ "resolve": {
517+ "nodes": [
518+ {
519+ "dependencies": [
520+ "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
521+ ],
522+ "deps": [
523+ {
524+ "name": "serde",
525+ "pkg": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
526+ }
527+ ],
528+ "features": [],
529+ "id": "bar 0.0.1 (path+file://[..]/foo)"
530+ },
531+ {
532+ "dependencies": [],
533+ "deps": [],
534+ "features": [],
535+ "id": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
536+ }
537+ ],
538+ "root": "bar 0.0.1 (path+file://[..]/foo)"
539+ },
540+ "target_directory": "[..]/foo/target",
541+ "version": 1,
542+ "workspace_members": [
543+ "bar 0.0.1 (path+file://[..]/foo)"
544+ ],
545+ "workspace_root": "[..]/foo"
546+ }"# ,
547+ )
548+ . run ( ) ;
549+
550+ p. cargo ( "update -p serde --precise 0.2.0" )
551+ . with_stderr (
552+ "\
553+ [UPDATING] `[..]` index
554+ " ,
555+ )
556+ . run ( ) ;
557+
558+ }
559+
398560#[ test]
399561fn preserve_top_comment ( ) {
400562 let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
0 commit comments