@@ -144,6 +144,8 @@ fn cargo_compile_with_downloaded_dependency_with_offline() {
144
144
145
145
#[ cargo_test]
146
146
fn cargo_compile_offline_not_try_update ( ) {
147
+ // When --offline needs to download the registry, provide a reasonable
148
+ // error hint to run without --offline.
147
149
let p = project ( )
148
150
. at ( "bar" )
149
151
. file (
@@ -160,28 +162,23 @@ fn cargo_compile_offline_not_try_update() {
160
162
. file ( "src/lib.rs" , "" )
161
163
. build ( ) ;
162
164
165
+ let msg = "\
166
+ [ERROR] no matching package named `not_cached_dep` found
167
+ location searched: registry `https://github.com/rust-lang/crates.io-index`
168
+ required by package `bar v0.1.0 ([..]/bar)`
169
+ As a reminder, you're using offline mode (--offline) which can sometimes cause \
170
+ surprising resolution failures, if this error is too confusing you may wish to \
171
+ retry without the offline flag.
172
+ " ;
173
+
163
174
p. cargo ( "build --offline" )
164
175
. with_status ( 101 )
165
- . with_stderr (
166
- "\
167
- [ERROR] failed to load source for a dependency on `not_cached_dep`
168
-
169
- Caused by:
170
- Unable to update registry `https://github.com/rust-lang/crates.io-index`
171
-
172
- Caused by:
173
- unable to fetch registry `https://github.com/rust-lang/crates.io-index` in offline mode
174
- Try running without the offline flag, or try running `cargo fetch` within your \
175
- project directory before going offline.
176
- " ,
177
- )
176
+ . with_stderr ( msg)
178
177
. run ( ) ;
179
178
179
+ // While we're here, also check the config works.
180
180
p. change_file ( ".cargo/config" , "net.offline = true" ) ;
181
- p. cargo ( "build" )
182
- . with_status ( 101 )
183
- . with_stderr_contains ( "[..]Unable to update registry[..]" )
184
- . run ( ) ;
181
+ p. cargo ( "build" ) . with_status ( 101 ) . with_stderr ( msg) . run ( ) ;
185
182
}
186
183
187
184
#[ cargo_test]
@@ -536,3 +533,29 @@ retry without the offline flag.
536
533
" )
537
534
. run ( ) ;
538
535
}
536
+
537
+ #[ cargo_test]
538
+ fn offline_with_all_patched ( ) {
539
+ // Offline works if everything is patched.
540
+ let p = project ( )
541
+ . file (
542
+ "Cargo.toml" ,
543
+ r#"
544
+ [package]
545
+ name = "foo"
546
+ version = "0.1.0"
547
+
548
+ [dependencies]
549
+ dep = "1.0"
550
+
551
+ [patch.crates-io]
552
+ dep = {path = "dep"}
553
+ "# ,
554
+ )
555
+ . file ( "src/lib.rs" , "pub fn f() { dep::foo(); }" )
556
+ . file ( "dep/Cargo.toml" , & basic_manifest ( "dep" , "1.0.0" ) )
557
+ . file ( "dep/src/lib.rs" , "pub fn foo() {}" )
558
+ . build ( ) ;
559
+
560
+ p. cargo ( "check --offline" ) . run ( ) ;
561
+ }
0 commit comments