Skip to content

Commit 010db83

Browse files
committed
Add misbehaving tests.
1 parent 94977cb commit 010db83

File tree

1 file changed

+353
-0
lines changed

1 file changed

+353
-0
lines changed

tests/testsuite/package.rs

Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5943,3 +5943,356 @@ fn workspace_with_local_and_remote_deps() {
59435943
)
59445944
.run();
59455945
}
5946+
5947+
#[cargo_test]
5948+
fn registry_not_in_publish_list() {
5949+
let p = project()
5950+
.file(
5951+
"Cargo.toml",
5952+
r#"
5953+
[package]
5954+
name = "foo"
5955+
version = "0.0.1"
5956+
edition = "2015"
5957+
authors = []
5958+
license = "MIT"
5959+
description = "foo"
5960+
publish = [
5961+
"test"
5962+
]
5963+
"#,
5964+
)
5965+
.file("src/main.rs", "fn main() {}")
5966+
.build();
5967+
5968+
p.cargo("package --registry alternative -Zpackage-workspace")
5969+
.masquerade_as_nightly_cargo(&["package-workspace"])
5970+
.with_status(101)
5971+
.with_stderr_data(str![[r#"
5972+
[ERROR] registry index was not found in any configuration: `alternative`
5973+
5974+
"#]])
5975+
.run();
5976+
}
5977+
5978+
#[cargo_test]
5979+
fn registry_inferred_from_unique_option() {
5980+
let _registry = registry::RegistryBuilder::new()
5981+
.http_api()
5982+
.http_index()
5983+
.alternative()
5984+
.build();
5985+
5986+
let p = project()
5987+
.file(
5988+
"Cargo.toml",
5989+
r#"
5990+
[workspace]
5991+
members = ["dep", "main"]
5992+
"#,
5993+
)
5994+
.file(
5995+
"main/Cargo.toml",
5996+
r#"
5997+
[package]
5998+
name = "main"
5999+
version = "0.0.1"
6000+
edition = "2015"
6001+
authors = []
6002+
license = "MIT"
6003+
description = "main"
6004+
repository = "bar"
6005+
publish = ["alternative"]
6006+
6007+
[dependencies]
6008+
dep = { path = "../dep", version = "0.1.0", registry = "alternative" }
6009+
"#,
6010+
)
6011+
.file("main/src/main.rs", "fn main() {}")
6012+
.file(
6013+
"dep/Cargo.toml",
6014+
r#"
6015+
[package]
6016+
name = "dep"
6017+
version = "0.1.0"
6018+
edition = "2015"
6019+
authors = []
6020+
license = "MIT"
6021+
description = "dep"
6022+
repository = "bar"
6023+
publish = ["alternative"]
6024+
"#,
6025+
)
6026+
.file("dep/src/lib.rs", "")
6027+
.build();
6028+
6029+
p.cargo("package -Zpackage-workspace")
6030+
.masquerade_as_nightly_cargo(&["package-workspace"])
6031+
.with_status(101)
6032+
.with_stderr_data(str![[r#"
6033+
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
6034+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6035+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
6036+
[UPDATING] `alternative` index
6037+
[ERROR] failed to prepare local package for uploading
6038+
6039+
Caused by:
6040+
no matching package named `dep` found
6041+
location searched: registry `alternative`
6042+
required by package `main v0.0.1 ([ROOT]/foo/main)`
6043+
6044+
"#]])
6045+
.run();
6046+
}
6047+
6048+
#[cargo_test]
6049+
fn registry_not_inferred_because_of_conflict() {
6050+
let alt_reg = registry::RegistryBuilder::new()
6051+
.http_api()
6052+
.http_index()
6053+
.alternative()
6054+
.build();
6055+
6056+
let p = project()
6057+
.file(
6058+
"Cargo.toml",
6059+
r#"
6060+
[workspace]
6061+
members = ["dep", "main"]
6062+
"#,
6063+
)
6064+
.file(
6065+
"main/Cargo.toml",
6066+
r#"
6067+
[package]
6068+
name = "main"
6069+
version = "0.0.1"
6070+
edition = "2015"
6071+
authors = []
6072+
license = "MIT"
6073+
description = "main"
6074+
repository = "bar"
6075+
publish = ["alternative"]
6076+
6077+
[dependencies]
6078+
dep = { path = "../dep", version = "0.1.0", registry = "alternative" }
6079+
"#,
6080+
)
6081+
.file("main/src/main.rs", "fn main() {}")
6082+
.file(
6083+
"dep/Cargo.toml",
6084+
r#"
6085+
[package]
6086+
name = "dep"
6087+
version = "0.1.0"
6088+
edition = "2015"
6089+
authors = []
6090+
license = "MIT"
6091+
description = "dep"
6092+
repository = "bar"
6093+
publish = ["alternative2"]
6094+
"#,
6095+
)
6096+
.file("dep/src/lib.rs", "")
6097+
.build();
6098+
6099+
p.cargo("package -Zpackage-workspace")
6100+
.masquerade_as_nightly_cargo(&["package-workspace"])
6101+
.with_status(101)
6102+
.with_stderr_data(str![[r#"
6103+
[ERROR] `dep` cannot be packaged.
6104+
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
6105+
6106+
"#]])
6107+
.run();
6108+
6109+
p.cargo("package -Zpackage-workspace --registry=alternative")
6110+
.masquerade_as_nightly_cargo(&["package-workspace"])
6111+
.with_status(101)
6112+
.with_stderr_data(str![[r#"
6113+
[ERROR] `dep` cannot be packaged.
6114+
The registry `alternative` is not listed in the `package.publish` value in Cargo.toml.
6115+
6116+
"#]])
6117+
.run();
6118+
6119+
p.cargo(&format!(
6120+
"package --index {} -Zpackage-workspace",
6121+
alt_reg.index_url()
6122+
))
6123+
.masquerade_as_nightly_cargo(&["package-workspace"])
6124+
.with_status(101)
6125+
.with_stderr_data(str![[r#"
6126+
[ERROR] `dep` cannot be packaged.
6127+
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
6128+
6129+
"#]])
6130+
.run();
6131+
}
6132+
6133+
#[cargo_test]
6134+
fn registry_not_inferred_because_of_multiple_options() {
6135+
let _alt_reg = registry::RegistryBuilder::new()
6136+
.http_api()
6137+
.http_index()
6138+
.alternative()
6139+
.build();
6140+
6141+
let p = project()
6142+
.file(
6143+
"Cargo.toml",
6144+
r#"
6145+
[workspace]
6146+
members = ["dep", "main"]
6147+
"#,
6148+
)
6149+
.file(
6150+
"main/Cargo.toml",
6151+
r#"
6152+
[package]
6153+
name = "main"
6154+
version = "0.0.1"
6155+
edition = "2015"
6156+
authors = []
6157+
license = "MIT"
6158+
description = "main"
6159+
repository = "bar"
6160+
publish = ["alternative", "alternative2"]
6161+
6162+
[dependencies]
6163+
dep = { path = "../dep", version = "0.1.0", registry = "alternative" }
6164+
"#,
6165+
)
6166+
.file("main/src/main.rs", "fn main() {}")
6167+
.file(
6168+
"dep/Cargo.toml",
6169+
r#"
6170+
[package]
6171+
name = "dep"
6172+
version = "0.1.0"
6173+
edition = "2015"
6174+
authors = []
6175+
license = "MIT"
6176+
description = "dep"
6177+
repository = "bar"
6178+
publish = ["alternative", "alternative2"]
6179+
"#,
6180+
)
6181+
.file("dep/src/lib.rs", "")
6182+
.build();
6183+
6184+
p.cargo("package -Zpackage-workspace")
6185+
.masquerade_as_nightly_cargo(&["package-workspace"])
6186+
.with_status(101)
6187+
.with_stderr_data(str![[r#"
6188+
[ERROR] `dep` cannot be packaged.
6189+
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
6190+
6191+
"#]])
6192+
.run();
6193+
6194+
p.cargo("package -Zpackage-workspace --registry=alternative")
6195+
.masquerade_as_nightly_cargo(&["package-workspace"])
6196+
.with_stderr_data(str![[r#"
6197+
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
6198+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6199+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
6200+
[UPDATING] `alternative` index
6201+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6202+
[VERIFYING] dep v0.1.0 ([ROOT]/foo/dep)
6203+
[COMPILING] dep v0.1.0 ([ROOT]/foo/target/package/dep-0.1.0)
6204+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6205+
[VERIFYING] main v0.0.1 ([ROOT]/foo/main)
6206+
[UPDATING] `alternative` index
6207+
[UNPACKING] dep v0.1.0 (registry `[ROOT]/foo/target/package/tmp-registry`)
6208+
[COMPILING] dep v0.1.0 (registry `alternative`)
6209+
[COMPILING] main v0.0.1 ([ROOT]/foo/target/package/main-0.0.1)
6210+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6211+
6212+
"#]])
6213+
.run();
6214+
}
6215+
6216+
#[cargo_test]
6217+
fn registry_not_inferred_because_of_mismatch() {
6218+
let _alt_reg = registry::RegistryBuilder::new()
6219+
.http_api()
6220+
.http_index()
6221+
.alternative()
6222+
.build();
6223+
6224+
let p = project()
6225+
.file(
6226+
"Cargo.toml",
6227+
r#"
6228+
[workspace]
6229+
members = ["dep", "main"]
6230+
"#,
6231+
)
6232+
.file(
6233+
"main/Cargo.toml",
6234+
r#"
6235+
[package]
6236+
name = "main"
6237+
version = "0.0.1"
6238+
edition = "2015"
6239+
authors = []
6240+
license = "MIT"
6241+
description = "main"
6242+
repository = "bar"
6243+
publish = ["alternative"]
6244+
6245+
[dependencies]
6246+
dep = { path = "../dep", version = "0.1.0", registry = "alternative" }
6247+
"#,
6248+
)
6249+
.file("main/src/main.rs", "fn main() {}")
6250+
// No `publish` field means "any registry", but the presence of this package
6251+
// will stop us from inferring a registry.
6252+
.file(
6253+
"dep/Cargo.toml",
6254+
r#"
6255+
[package]
6256+
name = "dep"
6257+
version = "0.1.0"
6258+
edition = "2015"
6259+
authors = []
6260+
license = "MIT"
6261+
description = "dep"
6262+
repository = "bar"
6263+
"#,
6264+
)
6265+
.file("dep/src/lib.rs", "")
6266+
.build();
6267+
6268+
p.cargo("package -Zpackage-workspace")
6269+
.masquerade_as_nightly_cargo(&["package-workspace"])
6270+
.with_status(101)
6271+
.with_stderr_data(str![[r#"
6272+
[ERROR] `main` cannot be packaged.
6273+
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
6274+
6275+
"#]])
6276+
.run();
6277+
6278+
p.cargo("package -Zpackage-workspace --registry=alternative")
6279+
.masquerade_as_nightly_cargo(&["package-workspace"])
6280+
.with_stderr_data(str![[r#"
6281+
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
6282+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6283+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
6284+
[UPDATING] `alternative` index
6285+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6286+
[VERIFYING] dep v0.1.0 ([ROOT]/foo/dep)
6287+
[COMPILING] dep v0.1.0 ([ROOT]/foo/target/package/dep-0.1.0)
6288+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6289+
[VERIFYING] main v0.0.1 ([ROOT]/foo/main)
6290+
[UPDATING] `alternative` index
6291+
[UNPACKING] dep v0.1.0 (registry `[ROOT]/foo/target/package/tmp-registry`)
6292+
[COMPILING] dep v0.1.0 (registry `alternative`)
6293+
[COMPILING] main v0.0.1 ([ROOT]/foo/target/package/main-0.0.1)
6294+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6295+
6296+
"#]])
6297+
.run();
6298+
}

0 commit comments

Comments
 (0)