@@ -7,7 +7,7 @@ use cargo_test_support::publish::validate_crate_contents;
7
7
use cargo_test_support:: registry:: { self , Package } ;
8
8
use cargo_test_support:: {
9
9
basic_manifest, cargo_process, git, path2url, paths, project, rustc_host, symlink_supported, t,
10
- ProjectBuilder ,
10
+ Project , ProjectBuilder ,
11
11
} ;
12
12
use flate2:: read:: GzDecoder ;
13
13
use std:: fs:: { self , read_to_string, File } ;
@@ -5038,3 +5038,303 @@ path = "examples/z.rs"
5038
5038
) ] ,
5039
5039
) ;
5040
5040
}
5041
+
5042
+ #[ cargo_test]
5043
+ fn workspace_with_local_deps ( ) {
5044
+ let crates_io = registry:: init ( ) ;
5045
+ let p = build_workspace_with_local_deps ( None ) ;
5046
+
5047
+ p. cargo ( "package" )
5048
+ . replace_crates_io ( crates_io. index_url ( ) )
5049
+ . with_status ( 101 )
5050
+ . with_stdout ( "" )
5051
+ . with_stderr (
5052
+ "\
5053
+ [PACKAGING] level1 v0.0.1 ([CWD]/level1)
5054
+ [UPDATING] crates.io index
5055
+ error: failed to prepare local package for uploading
5056
+
5057
+ Caused by:
5058
+ no matching package named `level2` found
5059
+ location searched: registry `crates-io`
5060
+ required by package `level1 v0.0.1 [..]
5061
+ " ,
5062
+ )
5063
+ . run ( ) ;
5064
+ }
5065
+
5066
+ #[ cargo_test]
5067
+ fn workspace_with_local_deps_packaging_one_fails ( ) {
5068
+ let crates_io = registry:: init ( ) ;
5069
+ let p = build_workspace_with_local_deps ( None ) ;
5070
+
5071
+ p. cargo ( "package -p level2" )
5072
+ . replace_crates_io ( crates_io. index_url ( ) )
5073
+ . with_status ( 101 )
5074
+ . with_stdout ( "" )
5075
+ . with_stderr (
5076
+ "\
5077
+ [PACKAGING] level2 v0.0.1 ([CWD]/level2)
5078
+ [PACKAGED] 3 files, [..] ([..] compressed)
5079
+ [VERIFYING] level2 v0.0.1 ([CWD]/level2)
5080
+ [UPDATING] crates.io index
5081
+ [ERROR] failed to verify package tarball
5082
+
5083
+ Caused by:
5084
+ no matching package named `level3` found
5085
+ location searched: registry `crates-io`
5086
+ required by package `level2 v0.0.1 ([CWD]/target/package/level2-0.0.1)`
5087
+ " ,
5088
+ )
5089
+ . run ( ) ;
5090
+ }
5091
+
5092
+ #[ cargo_test]
5093
+ fn workspace_with_local_deps_packaging_one_with_needed_deps ( ) {
5094
+ let crates_io = registry:: init ( ) ;
5095
+ let p = build_workspace_with_local_deps ( None ) ;
5096
+
5097
+ p. cargo ( "package -p level2 -p level3" )
5098
+ . replace_crates_io ( crates_io. index_url ( ) )
5099
+ . with_status ( 101 )
5100
+ . with_stdout ( "" )
5101
+ . with_stderr (
5102
+ "\
5103
+ [PACKAGING] level2 v0.0.1 ([CWD]/level2)
5104
+ [PACKAGED] 3 files, [..] ([..] compressed)
5105
+ [VERIFYING] level2 v0.0.1 ([CWD]/level2)
5106
+ [UPDATING] crates.io index
5107
+ [ERROR] failed to verify package tarball
5108
+
5109
+ Caused by:
5110
+ no matching package named `level3` found
5111
+ location searched: registry `crates-io`
5112
+ required by package `level2 v0.0.1 [..]
5113
+ " ,
5114
+ )
5115
+ . run ( ) ;
5116
+ }
5117
+
5118
+ #[ cargo_test]
5119
+ fn workspace_with_local_deps_list ( ) {
5120
+ let crates_io = registry:: init ( ) ;
5121
+ let p = build_workspace_with_local_deps ( None ) ;
5122
+
5123
+ p. cargo ( "package --list" )
5124
+ . replace_crates_io ( crates_io. index_url ( ) )
5125
+ . with_stdout (
5126
+ // This looks like it could be improved. See
5127
+ // https://github.com/rust-lang/cargo/issues/13953
5128
+ "\
5129
+ Cargo.lock
5130
+ Cargo.toml
5131
+ Cargo.toml.orig
5132
+ src/main.rs
5133
+ Cargo.toml
5134
+ Cargo.toml.orig
5135
+ src/lib.rs
5136
+ Cargo.toml
5137
+ Cargo.toml.orig
5138
+ src/lib.rs
5139
+ " ,
5140
+ )
5141
+ . with_stderr ( "" )
5142
+ . run ( ) ;
5143
+ }
5144
+
5145
+ #[ cargo_test]
5146
+ fn workspace_with_local_deps_index_mismatch ( ) {
5147
+ let alt_reg = registry:: RegistryBuilder :: new ( )
5148
+ . http_api ( )
5149
+ . http_index ( )
5150
+ . alternative ( )
5151
+ . build ( ) ;
5152
+ // We're publishing to an alternate index, but the manifests don't specify it.
5153
+ // The intra-workspace deps won't be found.
5154
+ let p = build_workspace_with_local_deps ( None ) ;
5155
+ p. cargo ( & format ! ( "package --index {}" , alt_reg. index_url( ) ) )
5156
+ . with_status ( 1 )
5157
+ . with_stdout ( "" )
5158
+ . with_stderr (
5159
+ "\
5160
+ error: unexpected argument '--index' found
5161
+
5162
+ Usage: cargo package [OPTIONS]
5163
+
5164
+ For more information, try '--help'.
5165
+ " ,
5166
+ )
5167
+ . run ( ) ;
5168
+ }
5169
+
5170
+ #[ cargo_test]
5171
+ fn workspace_with_local_deps_alternative_index ( ) {
5172
+ let alt_reg = registry:: RegistryBuilder :: new ( )
5173
+ . http_api ( )
5174
+ . http_index ( )
5175
+ . alternative ( )
5176
+ . build ( ) ;
5177
+ let p = build_workspace_with_local_deps ( Some ( "alternative" ) ) ;
5178
+
5179
+ p. cargo ( & format ! ( "package --index {}" , alt_reg. index_url( ) ) )
5180
+ . with_status ( 1 )
5181
+ . with_stdout ( "" )
5182
+ . with_stderr (
5183
+ "\
5184
+ error: unexpected argument '--index' found
5185
+
5186
+ Usage: cargo package [OPTIONS]
5187
+
5188
+ For more information, try '--help'.
5189
+ " ,
5190
+ )
5191
+ . run ( ) ;
5192
+ }
5193
+
5194
+ /// level1 -> level2 checks that we handle local dependencies.
5195
+ /// level2 -> level3 checks that we handle dependencies with local dependencies.
5196
+ fn build_workspace_with_local_deps ( registry : Option < & str > ) -> Project {
5197
+ let registry = match registry {
5198
+ Some ( r) => format ! ( r#", registry = "{r}""# ) ,
5199
+ None => "" . to_owned ( ) ,
5200
+ } ;
5201
+ project ( )
5202
+ . file (
5203
+ "Cargo.toml" ,
5204
+ & format ! ( r#"
5205
+ [workspace]
5206
+ members = ["level1", "level2", "level3"]
5207
+
5208
+ # Let one of the deps be inherited from the workspace, for the added test coverage when resolving.
5209
+ [workspace.dependencies]
5210
+ level2 = {{ path = "level2", version = "0.0.1" {registry} }}
5211
+ "# ) ,
5212
+ )
5213
+ . file (
5214
+ "level1/Cargo.toml" ,
5215
+ r#"
5216
+ [package]
5217
+ name = "level1"
5218
+ version = "0.0.1"
5219
+ edition = "2015"
5220
+ authors = []
5221
+ license = "MIT"
5222
+ description = "level1"
5223
+ repository = "bar"
5224
+
5225
+ [dependencies]
5226
+ # Let one dependency also specify features, for the added test coverage when generating package files.
5227
+ level2 = { workspace = true, features = ["foo"] }
5228
+ "# ,
5229
+ )
5230
+ . file ( "level1/src/main.rs" , "fn main() {}" )
5231
+ . file (
5232
+ "level2/Cargo.toml" ,
5233
+ & format ! ( r#"
5234
+ [package]
5235
+ name = "level2"
5236
+ version = "0.0.1"
5237
+ edition = "2015"
5238
+ authors = []
5239
+ license = "MIT"
5240
+ description = "level2"
5241
+ repository = "bar"
5242
+
5243
+ [features]
5244
+ foo = []
5245
+
5246
+ [dependencies]
5247
+ level3 = {{ path = "../level3", version = "0.0.1" {registry} }}
5248
+ "# ) ,
5249
+ )
5250
+ . file ( "level2/src/lib.rs" , "" )
5251
+ . file (
5252
+ "level3/Cargo.toml" ,
5253
+ r#"
5254
+ [package]
5255
+ name = "level3"
5256
+ version = "0.0.1"
5257
+ edition = "2015"
5258
+ authors = []
5259
+ license = "MIT"
5260
+ description = "level3"
5261
+ repository = "bar"
5262
+ "# ,
5263
+ )
5264
+ . file ( "level3/src/lib.rs" , "" )
5265
+ . build ( )
5266
+ }
5267
+
5268
+ #[ cargo_test]
5269
+ fn workspace_with_local_and_remote_deps ( ) {
5270
+ let reg = registry:: init ( ) ;
5271
+
5272
+ Package :: new ( "dep" , "0.0.1" ) . publish ( ) ;
5273
+
5274
+ let p = project ( )
5275
+ . file (
5276
+ "Cargo.toml" ,
5277
+ r#"
5278
+ [workspace]
5279
+ members = ["dep", "main"]
5280
+ "# ,
5281
+ )
5282
+ . file (
5283
+ "main/Cargo.toml" ,
5284
+ r#"
5285
+ [package]
5286
+ name = "main"
5287
+ version = "0.0.1"
5288
+ edition = "2015"
5289
+ authors = []
5290
+ license = "MIT"
5291
+ description = "main"
5292
+ repository = "bar"
5293
+
5294
+ [dependencies]
5295
+ dep = { path = "../dep", version = "0.1.0" }
5296
+ old_dep = { package = "dep", version = "0.0.1" }
5297
+ "# ,
5298
+ )
5299
+ . file ( "main/src/main.rs" , "fn main() {}" )
5300
+ . file (
5301
+ "dep/Cargo.toml" ,
5302
+ & format ! (
5303
+ r#"
5304
+ [package]
5305
+ name = "dep"
5306
+ version = "0.1.0"
5307
+ edition = "2015"
5308
+ authors = []
5309
+ license = "MIT"
5310
+ description = "dep"
5311
+ repository = "bar"
5312
+ "#
5313
+ ) ,
5314
+ )
5315
+ . file ( "dep/src/lib.rs" , "" )
5316
+ . build ( ) ;
5317
+
5318
+ p. cargo ( "package" )
5319
+ . replace_crates_io ( reg. index_url ( ) )
5320
+ . with_status ( 101 )
5321
+ . with_stderr (
5322
+ "\
5323
+ [PACKAGING] dep v0.1.0 ([CWD]/dep)
5324
+ [PACKAGED] 3 files, [..] ([..] compressed)
5325
+ [VERIFYING] dep v0.1.0 ([CWD]/dep)
5326
+ [COMPILING] dep v0.1.0 ([..])
5327
+ [FINISHED] [..]
5328
+ [PACKAGING] main v0.0.1 ([CWD]/main)
5329
+ [UPDATING] crates.io index
5330
+ [ERROR] failed to prepare local package for uploading
5331
+
5332
+ Caused by:
5333
+ failed to select a version for the requirement `dep = \" ^0.1.0\" `
5334
+ candidate versions found which didn't match: 0.0.1
5335
+ location searched: crates.io index
5336
+ required by package `main v0.0.1 [..]`
5337
+ " ,
5338
+ )
5339
+ . run ( ) ;
5340
+ }
0 commit comments