@@ -332,7 +332,7 @@ Caused by:
332
332
}
333
333
334
334
#[ cargo_test]
335
- fn update_offline ( ) {
335
+ fn update_offline_not_cached ( ) {
336
336
let p = project ( )
337
337
. file (
338
338
"Cargo.toml" ,
@@ -350,7 +350,15 @@ fn update_offline() {
350
350
. build ( ) ;
351
351
p. cargo ( "update --offline" )
352
352
. with_status ( 101 )
353
- . with_stderr ( "error: you can't update in the offline mode[..]" )
353
+ . with_stderr (
354
+ "\
355
+ [ERROR] no matching package named `bar` found
356
+ location searched: registry `[..]`
357
+ required by package `foo v0.0.1 ([..]/foo)`
358
+ As a reminder, you're using offline mode (--offline) which can sometimes cause \
359
+ surprising resolution failures, if this error is too confusing you may wish to \
360
+ retry without the offline flag.",
361
+ )
354
362
. run ( ) ;
355
363
}
356
364
@@ -562,3 +570,118 @@ fn offline_with_all_patched() {
562
570
563
571
p. cargo ( "check --offline" ) . run ( ) ;
564
572
}
573
+
574
+ #[ cargo_test]
575
+ fn update_offline_cached ( ) {
576
+ // Cache a few versions to update against
577
+ let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
578
+ let versions = [ "1.2.3" , "1.2.5" , "1.2.9" ] ;
579
+ for vers in versions. iter ( ) {
580
+ Package :: new ( "present_dep" , vers)
581
+ . file ( "Cargo.toml" , & basic_manifest ( "present_dep" , vers) )
582
+ . file (
583
+ "src/lib.rs" ,
584
+ format ! ( r#"pub fn get_version()->&'static str {{ "{}" }}"# , vers) . as_str ( ) ,
585
+ )
586
+ . publish ( ) ;
587
+ // make package cached
588
+ p. change_file (
589
+ "Cargo.toml" ,
590
+ format ! (
591
+ r#"
592
+ [project]
593
+ name = "foo"
594
+ version = "0.1.0"
595
+
596
+ [dependencies]
597
+ present_dep = "={}"
598
+ "# ,
599
+ vers
600
+ )
601
+ . as_str ( ) ,
602
+ ) ;
603
+ p. cargo ( "build" ) . run ( ) ;
604
+ }
605
+
606
+ let p2 = project ( )
607
+ . file (
608
+ "Cargo.toml" ,
609
+ r#"
610
+ [project]
611
+ name = "foo"
612
+ version = "0.1.0"
613
+
614
+ [dependencies]
615
+ present_dep = "1.2"
616
+ "# ,
617
+ )
618
+ . file (
619
+ "src/main.rs" ,
620
+ "\
621
+ extern crate present_dep;
622
+ fn main(){
623
+ println!(\" {}\" , present_dep::get_version());
624
+ }" ,
625
+ )
626
+ . build ( ) ;
627
+
628
+ p2. cargo ( "build --offline" )
629
+ . with_stderr (
630
+ "\
631
+ [COMPILING] present_dep v1.2.9
632
+ [COMPILING] foo v0.1.0 ([CWD])
633
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
634
+ " ,
635
+ )
636
+ . run ( ) ;
637
+ p2. rename_run ( "foo" , "with_1_2_9" )
638
+ . with_stdout ( "1.2.9" )
639
+ . run ( ) ;
640
+ // updates happen without updating the index
641
+ p2. cargo ( "update -p present_dep --precise 1.2.3 --offline" )
642
+ . with_status ( 0 )
643
+ . with_stderr (
644
+ "\
645
+ [UPDATING] present_dep v1.2.9 -> v1.2.3
646
+ " ,
647
+ )
648
+ . run ( ) ;
649
+
650
+ p2. cargo ( "build --offline" )
651
+ . with_stderr (
652
+ "\
653
+ [COMPILING] present_dep v1.2.3
654
+ [COMPILING] foo v0.1.0 ([CWD])
655
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
656
+ " ,
657
+ )
658
+ . run ( ) ;
659
+ p2. rename_run ( "foo" , "with_1_2_3" )
660
+ . with_stdout ( "1.2.3" )
661
+ . run ( ) ;
662
+
663
+ // Offline update should only print package details and not index updating
664
+ p2. cargo ( "update --offline" )
665
+ . with_status ( 0 )
666
+ . with_stderr (
667
+ "\
668
+ [UPDATING] present_dep v1.2.3 -> v1.2.9
669
+ " ,
670
+ )
671
+ . run ( ) ;
672
+
673
+ // No v1.2.8 loaded into the cache so expect failure.
674
+ p2. cargo ( "update -p present_dep --precise 1.2.8 --offline" )
675
+ . with_status ( 101 )
676
+ . with_stderr (
677
+ "\
678
+ [ERROR] no matching package named `present_dep` found
679
+ location searched: registry `[..]`
680
+ required by package `foo v0.1.0 ([..]/foo)`
681
+ As a reminder, you're using offline mode (--offline) which can sometimes cause \
682
+ surprising resolution failures, if this error is too confusing you may wish to \
683
+ retry without the offline flag.
684
+ " ,
685
+ )
686
+ . run ( ) ;
687
+ }
0 commit comments