diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index 6b854855c..d4a4a7ee6 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -1011,6 +1011,7 @@ impl HttpServer { pub fn check_authorized_publish(&self, req: &Request) -> Response { if let Some(body) = &req.body { + // Save the body to a file so we can inspect it in the test. let path = self.api_path.join("api/v1/crates/new"); t!(fs::create_dir_all(path.parent().unwrap())); t!(fs::write(&path, body)); diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 4106ef65b..d9bbf47d2 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -439,7 +439,7 @@ fn publish_to_alt_registry() { let _reg = RegistryBuilder::new() .http_api() .http_index() - .alternative_named("alternative") + .alternative() .build(); let p = project().file("src/main.rs", "fn main() {}").build(); @@ -471,7 +471,7 @@ fn publish_with_crates_io_dep() { let _alt_reg = RegistryBuilder::new() .http_api() .http_index() - .alternative_named("alternative") + .alternative() .build(); let p = project() .file( diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index 01f5a7c56..3e60b51c5 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -2,7 +2,7 @@ //! the new `dep = { artifact = "bin", … }` syntax in manifests. use cargo_test_support::compare::match_exact; -use cargo_test_support::registry::Package; +use cargo_test_support::registry::{Package, RegistryBuilder}; use cargo_test_support::{ basic_bin_manifest, basic_manifest, cross_compile, project, publish, registry, rustc_host, Project, @@ -1872,8 +1872,7 @@ fn env_vars_and_build_products_for_various_build_targets() { #[cargo_test] fn publish_artifact_dep() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); Package::new("bar", "1.0.0").publish(); Package::new("baz", "1.0.0").publish(); @@ -1903,15 +1902,6 @@ fn publish_artifact_dep() { .file("src/lib.rs", "") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.1.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish -Z bindeps --no-verify") .replace_crates_io(registry.index_url()) .masquerade_as_nightly_cargo(&["bindeps"]) diff --git a/tests/testsuite/cargo_features.rs b/tests/testsuite/cargo_features.rs index aa1ef4ae0..720d221fe 100644 --- a/tests/testsuite/cargo_features.rs +++ b/tests/testsuite/cargo_features.rs @@ -635,7 +635,7 @@ fn publish_allowed() { .masquerade_as_nightly_cargo(&["test-dummy-unstable"]) .with_stderr( "\ -[UPDATING] crates.io index +[UPDATING] [..] [WARNING] [..] [..] [PACKAGING] a v0.0.1 [..] @@ -644,7 +644,7 @@ fn publish_allowed() { [FINISHED] [..] [PACKAGED] [..] [UPLOADING] a v0.0.1 [..] -[UPDATING] crates.io index +[UPDATING] [..] ", ) .run(); diff --git a/tests/testsuite/features_namespaced.rs b/tests/testsuite/features_namespaced.rs index f7c29feef..26c4d0ac5 100644 --- a/tests/testsuite/features_namespaced.rs +++ b/tests/testsuite/features_namespaced.rs @@ -1,7 +1,7 @@ //! Tests for namespaced features. use super::features2::switch_to_resolver_2; -use cargo_test_support::registry::{self, Dependency, Package}; +use cargo_test_support::registry::{Dependency, Package, RegistryBuilder}; use cargo_test_support::{project, publish}; #[cargo_test] @@ -858,8 +858,7 @@ bar v1.0.0 #[cargo_test] fn publish_no_implicit() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); // Does not include implicit features or dep: syntax on publish. Package::new("opt-dep1", "1.0.0").publish(); @@ -887,15 +886,6 @@ fn publish_no_implicit() { .file("src/lib.rs", "") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.1.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish --no-verify") .replace_crates_io(registry.index_url()) .with_stderr( @@ -984,8 +974,7 @@ feat = ["opt-dep1"] #[cargo_test] fn publish() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); // Publish behavior with explicit dep: syntax. Package::new("bar", "1.0.0").publish(); @@ -1012,15 +1001,6 @@ fn publish() { .file("src/lib.rs", "") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.1.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) .with_stderr( @@ -1028,6 +1008,7 @@ fn publish() { [UPDATING] [..] [PACKAGING] foo v0.1.0 [..] [VERIFYING] foo v0.1.0 [..] +[UPDATING] [..] [COMPILING] foo v0.1.0 [..] [FINISHED] [..] [PACKAGED] [..] diff --git a/tests/testsuite/inheritable_workspace_fields.rs b/tests/testsuite/inheritable_workspace_fields.rs index 72de2e4ad..314ad2b86 100644 --- a/tests/testsuite/inheritable_workspace_fields.rs +++ b/tests/testsuite/inheritable_workspace_fields.rs @@ -1,5 +1,5 @@ //! Tests for inheriting Cargo.toml fields with field.workspace = true -use cargo_test_support::registry::{Dependency, Package}; +use cargo_test_support::registry::{Dependency, Package, RegistryBuilder}; use cargo_test_support::{ basic_lib_manifest, basic_manifest, git, path2url, paths, project, publish, registry, }; @@ -107,7 +107,7 @@ Caused by: #[cargo_test] fn inherit_own_workspace_fields() { - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project().build(); @@ -160,18 +160,23 @@ fn inherit_own_workspace_fields() { .file("bar.txt", "") // should be included when packaging .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "1.2.3") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) + .with_stderr( + "\ +[UPDATING] [..] +[WARNING] [..] +[..] +[VERIFYING] foo v1.2.3 [..] +[COMPILING] foo v1.2.3 [..] +[FINISHED] [..] +[PACKAGED] [..] +[UPLOADING] foo v1.2.3 [..] +[UPDATING] [..] +", + ) .run(); + publish::validate_upload_with_contents( r#" { @@ -242,7 +247,7 @@ repository = "https://gitlab.com/rust-lang/rust" #[cargo_test] fn inherit_own_dependencies() { - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project() .file( "Cargo.toml", @@ -297,18 +302,26 @@ fn inherit_own_dependencies() { assert!(lockfile.contains("dep-dev")); assert!(lockfile.contains("dep-build")); - // HACK: Inject `bar` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("bar", "0.2.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) + .with_stderr( + "\ +[UPDATING] [..] +[WARNING] [..] +[..] +[PACKAGING] bar v0.2.0 [..] +[UPDATING] [..] +[VERIFYING] bar v0.2.0 [..] +[COMPILING] dep v0.1.2 +[COMPILING] bar v0.2.0 [..] +[FINISHED] [..] +[PACKAGED] [..] +[UPLOADING] bar v0.2.0 [..] +[UPDATING] [..] +", + ) .run(); + publish::validate_upload_with_contents( r#" { @@ -387,7 +400,7 @@ version = "0.8" #[cargo_test] fn inherit_own_detailed_dependencies() { - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project() .file( "Cargo.toml", @@ -431,18 +444,26 @@ fn inherit_own_detailed_dependencies() { let lockfile = p.read_lockfile(); assert!(lockfile.contains("dep")); - // HACK: Inject `bar` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("bar", "0.2.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) + .with_stderr( + "\ +[UPDATING] [..] +[WARNING] [..] +[..] +[PACKAGING] bar v0.2.0 [..] +[UPDATING] [..] +[VERIFYING] bar v0.2.0 [..] +[COMPILING] dep v0.1.2 +[COMPILING] bar v0.2.0 [..] +[FINISHED] [..] +[PACKAGED] [..] +[UPLOADING] bar v0.2.0 [..] +[UPDATING] [..] +", + ) .run(); + publish::validate_upload_with_contents( r#" { @@ -593,7 +614,7 @@ fn inherited_dependencies_union_features() { #[cargo_test] fn inherit_workspace_fields() { - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project().build(); @@ -657,19 +678,28 @@ fn inherit_workspace_fields() { .file("bar/bar.txt", "") // should be included when packaging .build(); - // HACK: Inject `bar` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("bar", "1.2.3") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) .cwd("bar") + .with_stderr( + "\ +[UPDATING] [..] +[WARNING] [..] +[..] +[VERIFYING] bar v1.2.3 [..] +[WARNING] [..] +[..] +[..] +[..] +[COMPILING] bar v1.2.3 [..] +[FINISHED] [..] +[PACKAGED] [..] +[UPLOADING] bar v1.2.3 [..] +[UPDATING] [..] +", + ) .run(); + publish::validate_upload_with_contents( r#" { @@ -746,7 +776,7 @@ repository = "https://gitlab.com/rust-lang/rust" #[cargo_test] fn inherit_dependencies() { - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project() .file( "Cargo.toml", @@ -802,19 +832,27 @@ fn inherit_dependencies() { assert!(lockfile.contains("dep-dev")); assert!(lockfile.contains("dep-build")); - // HACK: Inject `bar` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("bar", "0.2.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) .cwd("bar") + .with_stderr( + "\ +[UPDATING] [..] +[WARNING] [..] +[..] +[PACKAGING] bar v0.2.0 [..] +[UPDATING] [..] +[VERIFYING] bar v0.2.0 [..] +[COMPILING] dep v0.1.2 +[COMPILING] bar v0.2.0 [..] +[FINISHED] [..] +[PACKAGED] [..] +[UPLOADING] bar v0.2.0 [..] +[UPDATING] [..] +", + ) .run(); + publish::validate_upload_with_contents( r#" { diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 5d868127a..e3f86905d 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -2,7 +2,7 @@ use cargo_test_support::git::{self, repo}; use cargo_test_support::paths; -use cargo_test_support::registry::{self, Package, Response}; +use cargo_test_support::registry::{self, Package, RegistryBuilder, Response}; use cargo_test_support::{basic_manifest, no_such_file_err_msg, project, publish}; use std::fs; use std::sync::{Arc, Mutex}; @@ -87,8 +87,7 @@ fn validate_upload_li() { #[cargo_test] fn simple() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project() .file( @@ -105,15 +104,6 @@ fn simple() { .file("src/main.rs", "fn main() {}") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.0.1") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish --no-verify") .replace_crates_io(registry.index_url()) .with_stderr( @@ -782,8 +772,11 @@ fn publish_empty_list() { #[cargo_test] fn publish_allowed_registry() { - // HACK below allows us to use a local registry - registry::alt_init(); + let _registry = RegistryBuilder::new() + .http_api() + .http_index() + .alternative() + .build(); let p = project().build(); @@ -806,16 +799,6 @@ fn publish_allowed_registry() { .file("src/main.rs", "fn main() {}") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.0.1") - .file("src/lib.rs", "") - .alternative(true) - .publish(); - p.cargo("publish --registry alternative") .with_stderr( "\ @@ -846,8 +829,11 @@ fn publish_allowed_registry() { #[cargo_test] fn publish_implicitly_to_only_allowed_registry() { - // HACK below allows us to use a local registry - registry::alt_init(); + let _registry = RegistryBuilder::new() + .http_api() + .http_index() + .alternative() + .build(); let p = project().build(); @@ -870,16 +856,6 @@ fn publish_implicitly_to_only_allowed_registry() { .file("src/main.rs", "fn main() {}") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.0.1") - .file("src/lib.rs", "") - .alternative(true) - .publish(); - p.cargo("publish") .with_stderr( "\ @@ -1157,8 +1133,7 @@ fn publish_with_no_default_features() { #[cargo_test] fn publish_with_patch() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); Package::new("bar", "1.0.0").publish(); let p = project() @@ -1201,15 +1176,6 @@ fn publish_with_patch() { // Remove the usage of new functionality and try again. p.change_file("src/main.rs", "extern crate bar; pub fn main() {}"); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.0.1") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) .with_stderr( @@ -1218,6 +1184,7 @@ fn publish_with_patch() { [..] [..] [..] +[UPDATING] crates.io index [VERIFYING] foo v0.0.1 ([CWD]) [..] [..] @@ -1366,8 +1333,7 @@ include `--registry crates-io` to use crates.io // A dependency with both `git` and `version`. #[cargo_test] fn publish_git_with_version() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); Package::new("dep1", "1.0.1") .file("src/lib.rs", "pub fn f() -> i32 {1}") @@ -1410,15 +1376,6 @@ fn publish_git_with_version() { p.cargo("run").with_stdout("2").run(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.1.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish --no-verify") .replace_crates_io(registry.index_url()) .with_stderr( @@ -1428,6 +1385,7 @@ fn publish_git_with_version() { [..] [..] [..] +[..] [UPLOADING] foo v0.1.0 ([CWD]) [UPDATING] crates.io index ", @@ -1515,8 +1473,7 @@ fn publish_git_with_version() { #[cargo_test] fn publish_dev_dep_no_version() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project() .file( @@ -1541,15 +1498,6 @@ fn publish_dev_dep_no_version() { .file("bar/src/lib.rs", "") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.1.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish --no-verify") .replace_crates_io(registry.index_url()) .with_stderr( @@ -2023,8 +1971,7 @@ Caused by: #[cargo_test] fn in_package_workspace() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project() .file( @@ -2052,13 +1999,6 @@ fn in_package_workspace() { .file("li/src/main.rs", "fn main() {}") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("li", "0.0.1").file("src/lib.rs", "").publish(); - p.cargo("publish -p li --no-verify") .replace_crates_io(registry.index_url()) .with_stderr( @@ -2131,8 +2071,7 @@ fn with_duplicate_spec_in_members() { #[cargo_test] fn in_package_workspace_with_members_with_features_old() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); let p = project() .file( @@ -2159,13 +2098,6 @@ fn in_package_workspace_with_members_with_features_old() { .file("li/src/main.rs", "fn main() {}") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("li", "0.0.1").file("src/lib.rs", "").publish(); - p.cargo("publish -p li --no-verify") .replace_crates_io(registry.index_url()) .with_stderr( diff --git a/tests/testsuite/weak_dep_features.rs b/tests/testsuite/weak_dep_features.rs index 4e3cd8dcb..dfc1e6b79 100644 --- a/tests/testsuite/weak_dep_features.rs +++ b/tests/testsuite/weak_dep_features.rs @@ -2,7 +2,7 @@ use super::features2::switch_to_resolver_2; use cargo_test_support::paths::CargoPathExt; -use cargo_test_support::registry::{self, Dependency, Package}; +use cargo_test_support::registry::{Dependency, Package, RegistryBuilder}; use cargo_test_support::{project, publish}; use std::fmt::Write; @@ -523,8 +523,7 @@ bar v1.0.0 #[cargo_test] fn publish() { - // HACK below allows us to use a local registry - let registry = registry::init(); + let registry = RegistryBuilder::new().http_api().http_index().build(); // Publish behavior with /? syntax. Package::new("bar", "1.0.0").feature("feat", &[]).publish(); @@ -550,15 +549,6 @@ fn publish() { .file("src/lib.rs", "") .build(); - // HACK: Inject `foo` directly into the index so `publish` won't block for it to be in - // the index. - // - // This is to ensure we can verify the Summary we post to the registry as doing so precludes - // the registry from processing the publish. - Package::new("foo", "0.1.0") - .file("src/lib.rs", "") - .publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) .with_stderr( @@ -566,6 +556,7 @@ fn publish() { [UPDATING] [..] [PACKAGING] foo v0.1.0 [..] [VERIFYING] foo v0.1.0 [..] +[UPDATING] [..] [COMPILING] foo v0.1.0 [..] [FINISHED] [..] [PACKAGED] [..]