From 0c513e414783fa661c7d1c1050fdeabccbc5ad74 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 15 Feb 2023 10:12:34 +0800 Subject: [PATCH] Make some blocking tests non-blocking --- tests/testsuite/alt_registry.rs | 123 ++++++++++---------------- tests/testsuite/cargo_features.rs | 12 +-- tests/testsuite/credential_process.rs | 18 ++-- 3 files changed, 57 insertions(+), 96 deletions(-) diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 6f0d3f7119e1..938d9f3895b7 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -287,7 +287,12 @@ fn cannot_publish_to_crates_io_with_registry_dependency() { #[cargo_test] fn publish_with_registry_dependency() { - registry::alt_init(); + let _reg = RegistryBuilder::new() + .http_api() + .http_index() + .alternative_named("alternative") + .build(); + let p = project() .file( "Cargo.toml", @@ -307,46 +312,26 @@ fn publish_with_registry_dependency() { Package::new("bar", "0.0.1").alternative(true).publish(); - // Login so that we have the token available - p.cargo("login --registry alternative TOKEN").run(); - - p.cargo("publish --registry alternative").run(); - - validate_alt_upload( - r#"{ - "authors": [], - "badges": {}, - "categories": [], - "deps": [ - { - "default_features": true, - "features": [], - "kind": "normal", - "name": "bar", - "optional": false, - "target": null, - "version_req": "^0.0.1" - } - ], - "description": null, - "documentation": null, - "features": {}, - "homepage": null, - "keywords": [], - "license": null, - "license_file": null, - "links": null, - "name": "foo", - "readme": null, - "readme_file": null, - "repository": null, - "homepage": null, - "documentation": null, - "vers": "0.0.1" - }"#, - "foo-0.0.1.crate", - &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - ); + p.cargo("publish --registry alternative") + .with_stderr( + "\ +[UPDATING] `alternative` index +[WARNING] [..] +[..] +[PACKAGING] foo v0.0.1 [..] +[UPDATING] `alternative` index +[VERIFYING] foo v0.0.1 [..] +[DOWNLOADING] [..] +[DOWNLOADED] bar v0.0.1 (registry `alternative`) +[COMPILING] bar v0.0.1 (registry `alternative`) +[COMPILING] foo v0.0.1 [..] +[FINISHED] [..] +[PACKAGED] [..] +[UPLOADING] foo v0.0.1 [..] +[UPDATING] `alternative` index +", + ) + .run(); } #[cargo_test] @@ -415,43 +400,31 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN", #[cargo_test] fn publish_to_alt_registry() { - registry::alt_init(); - let p = project().file("src/main.rs", "fn main() {}").build(); - - // Setup the registry by publishing a package - Package::new("bar", "0.0.1").alternative(true).publish(); + let _reg = RegistryBuilder::new() + .http_api() + .http_index() + .alternative_named("alternative") + .build(); - // Login so that we have the token available - p.cargo("login --registry alternative TOKEN").run(); + let p = project().file("src/main.rs", "fn main() {}").build(); // Now perform the actual publish - p.cargo("publish --registry alternative").run(); - - validate_alt_upload( - r#"{ - "authors": [], - "badges": {}, - "categories": [], - "deps": [], - "description": null, - "documentation": null, - "features": {}, - "homepage": null, - "keywords": [], - "license": null, - "license_file": null, - "links": null, - "name": "foo", - "readme": null, - "readme_file": null, - "repository": null, - "homepage": null, - "documentation": null, - "vers": "0.0.1" - }"#, - "foo-0.0.1.crate", - &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - ); + p.cargo("publish --registry alternative") + .with_stderr( + "\ +[UPDATING] `alternative` index +[WARNING] [..] +[..] +[PACKAGING] foo v0.0.1 [..] +[VERIFYING] foo v0.0.1 [..] +[COMPILING] foo v0.0.1 [..] +[FINISHED] [..] +[PACKAGED] [..] +[UPLOADING] foo v0.0.1 [..] +[UPDATING] `alternative` index +", + ) + .run(); } #[cargo_test] diff --git a/tests/testsuite/cargo_features.rs b/tests/testsuite/cargo_features.rs index 46bafb111aa7..b9b317a1236c 100644 --- a/tests/testsuite/cargo_features.rs +++ b/tests/testsuite/cargo_features.rs @@ -610,7 +610,10 @@ fn z_flags_rejected() { #[cargo_test] fn publish_allowed() { - let registry = registry::init(); + let registry = registry::RegistryBuilder::new() + .http_api() + .http_index() + .build(); let p = project() .file( @@ -627,13 +630,6 @@ fn publish_allowed() { .file("src/lib.rs", "") .build(); - // HACK: Inject `a` 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("a", "0.0.1").file("src/lib.rs", "").publish(); - p.cargo("publish") .replace_crates_io(registry.index_url()) .masquerade_as_nightly_cargo(&["test-dummy-unstable"]) diff --git a/tests/testsuite/credential_process.rs b/tests/testsuite/credential_process.rs index cd1794bda93c..0d174b6e3796 100644 --- a/tests/testsuite/credential_process.rs +++ b/tests/testsuite/credential_process.rs @@ -1,6 +1,6 @@ //! Tests for credential-process. -use cargo_test_support::registry::{Package, TestRegistry}; +use cargo_test_support::registry::TestRegistry; use cargo_test_support::{basic_manifest, cargo_process, paths, project, registry, Project}; use std::fs::{self, read_to_string}; @@ -69,6 +69,8 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN fn warn_both_token_and_process() { // Specifying both credential-process and a token in config should issue a warning. let _server = registry::RegistryBuilder::new() + .http_api() + .http_index() .alternative() .no_configure_token() .build(); @@ -77,7 +79,7 @@ fn warn_both_token_and_process() { ".cargo/config", r#" [registries.alternative] - token = "sekrit" + token = "alternative-sekrit" credential-process = "false" "#, ) @@ -96,16 +98,6 @@ fn warn_both_token_and_process() { .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", "") - .alternative(true) - .publish(); - p.cargo("publish --no-verify --registry alternative -Z credential-process") .masquerade_as_nightly_cargo(&["credential-process"]) .with_status(101) @@ -127,7 +119,7 @@ Only one of these values may be set, remove one or the other to proceed. credential-process = "false" [registries.alternative] - token = "sekrit" + token = "alternative-sekrit" "#, ); p.cargo("publish --no-verify --registry alternative -Z credential-process")