Skip to content

Commit

Permalink
Add misbehaving tests.
Browse files Browse the repository at this point in the history
jneem committed Aug 7, 2024
1 parent 94977cb commit 010db83
Showing 1 changed file with 353 additions and 0 deletions.
353 changes: 353 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
@@ -5943,3 +5943,356 @@ fn workspace_with_local_and_remote_deps() {
)
.run();
}

#[cargo_test]
fn registry_not_in_publish_list() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
license = "MIT"
description = "foo"
publish = [
"test"
]
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("package --registry alternative -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] registry index was not found in any configuration: `alternative`
"#]])
.run();
}

#[cargo_test]
fn registry_inferred_from_unique_option() {
let _registry = registry::RegistryBuilder::new()
.http_api()
.http_index()
.alternative()
.build();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["dep", "main"]
"#,
)
.file(
"main/Cargo.toml",
r#"
[package]
name = "main"
version = "0.0.1"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"
publish = ["alternative"]
[dependencies]
dep = { path = "../dep", version = "0.1.0", registry = "alternative" }
"#,
)
.file("main/src/main.rs", "fn main() {}")
.file(
"dep/Cargo.toml",
r#"
[package]
name = "dep"
version = "0.1.0"
edition = "2015"
authors = []
license = "MIT"
description = "dep"
repository = "bar"
publish = ["alternative"]
"#,
)
.file("dep/src/lib.rs", "")
.build();

p.cargo("package -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(101)
.with_stderr_data(str![[r#"
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
[UPDATING] `alternative` index
[ERROR] failed to prepare local package for uploading
Caused by:
no matching package named `dep` found
location searched: registry `alternative`
required by package `main v0.0.1 ([ROOT]/foo/main)`
"#]])
.run();
}

#[cargo_test]
fn registry_not_inferred_because_of_conflict() {
let alt_reg = registry::RegistryBuilder::new()
.http_api()
.http_index()
.alternative()
.build();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["dep", "main"]
"#,
)
.file(
"main/Cargo.toml",
r#"
[package]
name = "main"
version = "0.0.1"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"
publish = ["alternative"]
[dependencies]
dep = { path = "../dep", version = "0.1.0", registry = "alternative" }
"#,
)
.file("main/src/main.rs", "fn main() {}")
.file(
"dep/Cargo.toml",
r#"
[package]
name = "dep"
version = "0.1.0"
edition = "2015"
authors = []
license = "MIT"
description = "dep"
repository = "bar"
publish = ["alternative2"]
"#,
)
.file("dep/src/lib.rs", "")
.build();

p.cargo("package -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] `dep` cannot be packaged.
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
"#]])
.run();

p.cargo("package -Zpackage-workspace --registry=alternative")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] `dep` cannot be packaged.
The registry `alternative` is not listed in the `package.publish` value in Cargo.toml.
"#]])
.run();

p.cargo(&format!(
"package --index {} -Zpackage-workspace",
alt_reg.index_url()
))
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] `dep` cannot be packaged.
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
"#]])
.run();
}

#[cargo_test]
fn registry_not_inferred_because_of_multiple_options() {
let _alt_reg = registry::RegistryBuilder::new()
.http_api()
.http_index()
.alternative()
.build();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["dep", "main"]
"#,
)
.file(
"main/Cargo.toml",
r#"
[package]
name = "main"
version = "0.0.1"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"
publish = ["alternative", "alternative2"]
[dependencies]
dep = { path = "../dep", version = "0.1.0", registry = "alternative" }
"#,
)
.file("main/src/main.rs", "fn main() {}")
.file(
"dep/Cargo.toml",
r#"
[package]
name = "dep"
version = "0.1.0"
edition = "2015"
authors = []
license = "MIT"
description = "dep"
repository = "bar"
publish = ["alternative", "alternative2"]
"#,
)
.file("dep/src/lib.rs", "")
.build();

p.cargo("package -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] `dep` cannot be packaged.
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
"#]])
.run();

p.cargo("package -Zpackage-workspace --registry=alternative")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_stderr_data(str![[r#"
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
[UPDATING] `alternative` index
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[VERIFYING] dep v0.1.0 ([ROOT]/foo/dep)
[COMPILING] dep v0.1.0 ([ROOT]/foo/target/package/dep-0.1.0)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[VERIFYING] main v0.0.1 ([ROOT]/foo/main)
[UPDATING] `alternative` index
[UNPACKING] dep v0.1.0 (registry `[ROOT]/foo/target/package/tmp-registry`)
[COMPILING] dep v0.1.0 (registry `alternative`)
[COMPILING] main v0.0.1 ([ROOT]/foo/target/package/main-0.0.1)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

#[cargo_test]
fn registry_not_inferred_because_of_mismatch() {
let _alt_reg = registry::RegistryBuilder::new()
.http_api()
.http_index()
.alternative()
.build();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["dep", "main"]
"#,
)
.file(
"main/Cargo.toml",
r#"
[package]
name = "main"
version = "0.0.1"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"
publish = ["alternative"]
[dependencies]
dep = { path = "../dep", version = "0.1.0", registry = "alternative" }
"#,
)
.file("main/src/main.rs", "fn main() {}")
// No `publish` field means "any registry", but the presence of this package
// will stop us from inferring a registry.
.file(
"dep/Cargo.toml",
r#"
[package]
name = "dep"
version = "0.1.0"
edition = "2015"
authors = []
license = "MIT"
description = "dep"
repository = "bar"
"#,
)
.file("dep/src/lib.rs", "")
.build();

p.cargo("package -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] `main` cannot be packaged.
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
"#]])
.run();

p.cargo("package -Zpackage-workspace --registry=alternative")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_stderr_data(str![[r#"
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
[UPDATING] `alternative` index
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[VERIFYING] dep v0.1.0 ([ROOT]/foo/dep)
[COMPILING] dep v0.1.0 ([ROOT]/foo/target/package/dep-0.1.0)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[VERIFYING] main v0.0.1 ([ROOT]/foo/main)
[UPDATING] `alternative` index
[UNPACKING] dep v0.1.0 (registry `[ROOT]/foo/target/package/tmp-registry`)
[COMPILING] dep v0.1.0 (registry `alternative`)
[COMPILING] main v0.0.1 ([ROOT]/foo/target/package/main-0.0.1)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

0 comments on commit 010db83

Please sign in to comment.