Skip to content

Commit

Permalink
Auto merge of #14158 - eth3lbert:snapbox-l, r=epage
Browse files Browse the repository at this point in the history
test: migrate some files to snapbox

### What does this PR try to resolve?

Part of #14039.

Migrate following to snapbox:

- `tests/testsuite/local_registry.rs`
- `tests/testsuite/locate_project.rs`
- `tests/testsuite/lockfile_compat.rs`
- `tests/testsuite/login.rs`
- `tests/testsuite/logout.rs`
  • Loading branch information
bors committed Jun 28, 2024
2 parents 6ed64a7 + 8a3787e commit 8009105
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 225 deletions.
150 changes: 76 additions & 74 deletions tests/testsuite/local_registry.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Tests for local-registry sources.
#![allow(deprecated)]

use cargo_test_support::paths::{self, CargoPathExt};
use cargo_test_support::prelude::*;
use cargo_test_support::registry::{registry_path, Package};
use cargo_test_support::{basic_manifest, project, t};
use cargo_test_support::{basic_manifest, project, str, t};
use std::fs;

fn setup() {
Expand Down Expand Up @@ -52,17 +51,21 @@ fn simple() {
.build();

p.cargo("build")
.with_stderr(
"\
.with_stderr_data(str![[r#"
[LOCKING] 2 packages to latest compatible versions
[UNPACKING] bar v0.0.1 ([..])
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
[COMPILING] bar v0.0.1
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] [..]
",
)
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
p.cargo("build")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
p.cargo("build").with_stderr("[FINISHED] [..]").run();
p.cargo("test").run();
}

Expand Down Expand Up @@ -95,13 +98,12 @@ fn not_found() {

p.cargo("check")
.with_status(101)
.with_stderr(
"\
.with_stderr_data(str![[r#"
[ERROR] no matching package named `baz` found
location searched: registry `crates-io`
required by package `foo v0.0.1 ([..]/foo)`
",
)
required by package `foo v0.0.1 ([ROOT]/foo)`
"#]])
.run();
}

Expand Down Expand Up @@ -137,11 +139,10 @@ fn depend_on_yanked() {
.publish();

p.cargo("check")
.with_stderr(
"\
[FINISHED] [..]
",
)
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down Expand Up @@ -175,15 +176,14 @@ fn multiple_versions() {
.build();

p.cargo("check")
.with_stderr(
"\
.with_stderr_data(str![[r#"
[LOCKING] 2 packages to latest compatible versions
[UNPACKING] bar v0.1.0 ([..])
[UNPACKING] bar v0.1.0 (registry `[ROOT]/registry`)
[CHECKING] bar v0.1.0
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] [..]
",
)
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();

Package::new("bar", "0.2.0")
Expand All @@ -192,11 +192,11 @@ fn multiple_versions() {
.publish();

p.cargo("update")
.with_stderr(
"\
.with_stderr_data(str![[r#"
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.1.0 -> v0.2.0",
)
[UPDATING] bar v0.1.0 -> v0.2.0
"#]])
.run();
}

Expand Down Expand Up @@ -241,16 +241,18 @@ fn multiple_names() {
.build();

p.cargo("check")
.with_stderr(
"\
.with_stderr_data(
str![[r#"
[LOCKING] 3 packages to latest compatible versions
[UNPACKING] [..]
[UNPACKING] [..]
[CHECKING] [..]
[CHECKING] [..]
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] [..]
",
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`)
[CHECKING] bar v0.0.1
[CHECKING] baz v0.1.0
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]]
.unordered(),
)
.run();
}
Expand Down Expand Up @@ -297,17 +299,16 @@ fn interdependent() {
.build();

p.cargo("check")
.with_stderr(
"\
.with_stderr_data(str![[r#"
[LOCKING] 3 packages to latest compatible versions
[UNPACKING] [..]
[UNPACKING] [..]
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`)
[CHECKING] bar v0.0.1
[CHECKING] baz v0.1.0
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] [..]
",
)
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down Expand Up @@ -368,17 +369,16 @@ fn path_dep_rewritten() {
.build();

p.cargo("check")
.with_stderr(
"\
.with_stderr_data(str![[r#"
[LOCKING] 3 packages to latest compatible versions
[UNPACKING] [..]
[UNPACKING] [..]
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`)
[CHECKING] bar v0.0.1
[CHECKING] baz v0.1.0
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] [..]
",
)
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down Expand Up @@ -415,9 +415,8 @@ fn invalid_dir_bad() {

p.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]`
.with_stderr_data(str![[r#"
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
Caused by:
failed to load source for dependency `bar`
Expand All @@ -430,8 +429,8 @@ Caused by:
Caused by:
local registry path is not a directory: [..]path[..]to[..]nowhere
",
)
"#]])
.run();
}

Expand Down Expand Up @@ -478,8 +477,7 @@ fn different_directory_replacing_the_registry_is_bad() {

p.cargo("check")
.with_status(101)
.with_stderr(
"\
.with_stderr_data(str![[r#"
[ERROR] checksum for `bar v0.0.1` changed between lock files
this could be indicative of a few possible errors:
Expand All @@ -490,8 +488,8 @@ this could be indicative of a few possible errors:
unable to verify that `bar v0.0.1` is the same as when the lockfile was generated
",
)
"#]])
.run();
}

Expand Down Expand Up @@ -536,16 +534,20 @@ fn crates_io_registry_url_is_optional() {
.build();

p.cargo("build")
.with_stderr(
"\
.with_stderr_data(str![[r#"
[LOCKING] 2 packages to latest compatible versions
[UNPACKING] bar v0.0.1 ([..])
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
[COMPILING] bar v0.0.1
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] [..]
",
)
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
p.cargo("build")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
p.cargo("build").with_stderr("[FINISHED] [..]").run();
p.cargo("test").run();
}
73 changes: 60 additions & 13 deletions tests/testsuite/locate_project.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
//! Tests for the `cargo locate-project` command.
#![allow(deprecated)]

use cargo_test_support::prelude::*;
use cargo_test_support::project;
use cargo_test_support::str;

#[cargo_test]
fn simple() {
let p = project().build();

p.cargo("locate-project")
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
.with_stdout_data(
str![[r#"
{
"root": "[ROOT]/foo/Cargo.toml"
}
"#]]
.json(),
)
.run();
}

Expand All @@ -18,15 +25,28 @@ fn message_format() {
let p = project().build();

p.cargo("locate-project --message-format plain")
.with_stdout("[ROOT]/foo/Cargo.toml")
.with_stdout_data(str![[r#"
[ROOT]/foo/Cargo.toml
"#]])
.run();

p.cargo("locate-project --message-format json")
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
.with_stdout_data(
str![[r#"
{
"root": "[ROOT]/foo/Cargo.toml"
}
"#]]
.json(),
)
.run();

p.cargo("locate-project --message-format cryptic")
.with_stderr("error: invalid message format specifier: `cryptic`")
.with_stderr_data(str![[r#"
[ERROR] invalid message format specifier: `cryptic`
"#]])
.with_status(101)
.run();
}
Expand Down Expand Up @@ -57,22 +77,49 @@ fn workspace() {
.file("inner/src/lib.rs", "")
.build();

let outer_manifest = r#"{"root": "[ROOT]/foo/Cargo.toml"}"#;
let inner_manifest = r#"{"root": "[ROOT]/foo/inner/Cargo.toml"}"#;

p.cargo("locate-project").with_json(outer_manifest).run();
p.cargo("locate-project")
.with_stdout_data(
str![[r#"
{
"root": "[ROOT]/foo/Cargo.toml"
}
"#]]
.json(),
)
.run();

p.cargo("locate-project")
.cwd("inner")
.with_json(inner_manifest)
.with_stdout_data(
str![[r#"
{
"root": "[ROOT]/foo/inner/Cargo.toml"
}
"#]]
.json(),
)
.run();

p.cargo("locate-project --workspace")
.with_json(outer_manifest)
.with_stdout_data(
str![[r#"
{
"root": "[ROOT]/foo/Cargo.toml"
}
"#]]
.json(),
)
.run();

p.cargo("locate-project --workspace")
.cwd("inner")
.with_json(outer_manifest)
.with_stdout_data(
str![[r#"
{
"root": "[ROOT]/foo/Cargo.toml"
}
"#]]
.json(),
)
.run();
}
Loading

0 comments on commit 8009105

Please sign in to comment.