Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate search, source_replacement and standard_lib to snapbox #14151

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions tests/testsuite/search.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Tests for the `cargo search` command.

#![allow(deprecated)]

use cargo::util::cache_lock::CacheLockMode;
use cargo_test_support::cargo_process;
use cargo_test_support::paths;
use cargo_test_support::registry::{RegistryBuilder, Response};
use cargo_test_support::str;
use std::collections::HashSet;

const SEARCH_API_RESPONSE: &[u8] = br#"
Expand Down Expand Up @@ -113,8 +112,8 @@ fn not_update() {

cargo_process("search postgres")
.replace_crates_io(registry.index_url())
.with_stdout_contains(SEARCH_RESULTS)
.with_stderr("") // without "Updating ... index"
.with_stdout_data(SEARCH_RESULTS)
.with_stderr_data("") // without "Updating ... index"
.run();
}

Expand All @@ -124,8 +123,11 @@ fn replace_default() {

cargo_process("search postgres")
.replace_crates_io(registry.index_url())
.with_stdout_contains(SEARCH_RESULTS)
.with_stderr_contains("[..]Updating [..] index")
.with_stdout_data(SEARCH_RESULTS)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index

"#]])
.run();
}

Expand All @@ -135,7 +137,7 @@ fn simple() {

cargo_process("search postgres --index")
.arg(registry.index_url().as_str())
.with_stdout_contains(SEARCH_RESULTS)
.with_stdout_data(SEARCH_RESULTS)
.run();
}

Expand All @@ -145,7 +147,7 @@ fn multiple_query_params() {

cargo_process("search postgres sql --index")
.arg(registry.index_url().as_str())
.with_stdout_contains(SEARCH_RESULTS)
.with_stdout_data(SEARCH_RESULTS)
.run();
}

Expand All @@ -155,10 +157,11 @@ fn ignore_quiet() {

cargo_process("search -q postgres")
.replace_crates_io(registry.index_url())
.with_stdout_contains(SEARCH_RESULTS)
.with_stdout_data(SEARCH_RESULTS)
.run();
}

#[allow(deprecated)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with_stdout_does_not_contain is being used in this function.

#[cargo_test]
fn colored_results() {
let registry = setup().build();
Expand All @@ -170,7 +173,13 @@ fn colored_results() {

cargo_process("search --color=always postgres")
.replace_crates_io(registry.index_url())
.with_stdout_contains("[..]\x1b[[..]")
.with_stdout_data(
"\
...
[..]\x1b[[..]
...
",
)
.run();
}

Expand All @@ -181,7 +190,12 @@ fn auth_required_failure() {
cargo_process("search postgres")
.replace_crates_io(server.index_url())
.with_status(101)
.with_stderr_contains("[ERROR] no token found, please run `cargo login`")
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[ERROR] no token found, please run `cargo login`
or use environment variable CARGO_REGISTRY_TOKEN

"#]])
.run();
}

Expand All @@ -191,6 +205,6 @@ fn auth_required() {

cargo_process("search postgres")
.replace_crates_io(server.index_url())
.with_stdout_contains(SEARCH_RESULTS)
.with_stdout_data(SEARCH_RESULTS)
.run();
}
84 changes: 39 additions & 45 deletions tests/testsuite/source_replacement.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! Tests for `[source]` table (source replacement).

#![allow(deprecated)]

use std::fs;

use cargo_test_support::registry::{Package, RegistryBuilder, TestRegistry};
use cargo_test_support::{cargo_process, paths, project, t};
use cargo_test_support::{cargo_process, paths, project, str, t};

fn setup_replacement(config: &str) -> TestRegistry {
let crates_io = RegistryBuilder::new()
Expand Down Expand Up @@ -52,7 +50,10 @@ fn crates_io_token_not_sent_to_replacement() {

p.cargo("publish --no-verify --registry crates-io")
.replace_crates_io(crates_io.index_url())
.with_stderr_contains("[UPDATING] crates.io index")
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
...
"#]])
.run();
}

Expand All @@ -69,22 +70,20 @@ fn token_sent_to_correct_registry() {

cargo_process("yank [email protected] --registry crates-io")
.replace_crates_io(crates_io.index_url())
.with_stderr(
"\
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[YANK] [email protected]
",
)

"#]])
.run();

cargo_process("yank [email protected] --registry alternative")
.replace_crates_io(crates_io.index_url())
.with_stderr(
"\
.with_stderr_data(str![[r#"
[UPDATING] `alternative` index
[YANK] [email protected]
",
)

"#]])
.run();
}

Expand All @@ -107,12 +106,11 @@ fn ambiguous_registry() {
cargo_process("yank [email protected]")
.replace_crates_io(crates_io.index_url())
.with_status(101)
.with_stderr(
"\
error: crates-io is replaced with remote registry alternative;
.with_stderr_data(str![[r#"
[ERROR] crates-io is replaced with remote registry alternative;
include `--registry alternative` or `--registry crates-io`
",
)

"#]])
.run();
}

Expand All @@ -132,12 +130,11 @@ fn yank_with_default_crates_io() {

cargo_process("yank [email protected]")
.replace_crates_io(crates_io.index_url())
.with_stderr(
"\
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[YANK] [email protected]
",
)

"#]])
.run();
}

Expand All @@ -157,12 +154,11 @@ fn yank_with_default_alternative() {

cargo_process("yank [email protected]")
.replace_crates_io(crates_io.index_url())
.with_stderr(
"\
.with_stderr_data(str![[r#"
[UPDATING] `alternative` index
[YANK] [email protected]
",
)

"#]])
.run();
}

Expand Down Expand Up @@ -209,27 +205,26 @@ fn publish_with_replacement() {
// for the verification step.
p.cargo("publish --registry crates-io")
.replace_crates_io(crates_io.index_url())
.with_stderr(
"\
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[WARNING] manifest has no documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] foo v0.0.1 ([..])
[PACKAGED] [..]
[VERIFYING] foo v0.0.1 ([..])
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[VERIFYING] foo v0.0.1 ([ROOT]/foo)
[UPDATING] `alternative` index
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.0.0 (registry `alternative`)
[COMPILING] bar v1.0.0
[COMPILING] foo v0.0.1 ([..]foo-0.0.1)
[FINISHED] `dev` profile [..]
[UPLOADING] foo v0.0.1 ([..])
[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
[UPLOADED] foo v0.0.1 to registry `crates-io`
[NOTE] waiting for `foo v0.0.1` to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v0.0.1 at registry `crates-io`
",
)

"#]])
.run();
}

Expand All @@ -246,10 +241,10 @@ fn undefined_default() {
cargo_process("yank [email protected]")
.replace_crates_io(crates_io.index_url())
.with_status(101)
.with_stderr(
"[ERROR] registry index was not found in any configuration: `undefined`
",
)
.with_stderr_data(str![[r#"
[ERROR] registry index was not found in any configuration: `undefined`

"#]])
.run();
}

Expand Down Expand Up @@ -286,16 +281,15 @@ fn source_replacement_with_registry_url() {

p.cargo("check")
.replace_crates_io(crates_io.index_url())
.with_stderr(
"\
.with_stderr_data(str![[r#"
[UPDATING] `using-registry-url` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.0.1 (registry `using-registry-url`)
[CHECKING] bar v0.0.1
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] `dev` profile [..]
",
)
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run();
}
Loading