Skip to content

Commit 8009105

Browse files
committed
Auto merge of #14158 - eth3lbert:snapbox-l, r=epage
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`
2 parents 6ed64a7 + 8a3787e commit 8009105

File tree

5 files changed

+276
-225
lines changed

5 files changed

+276
-225
lines changed

tests/testsuite/local_registry.rs

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Tests for local-registry sources.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::paths::{self, CargoPathExt};
4+
use cargo_test_support::prelude::*;
65
use cargo_test_support::registry::{registry_path, Package};
7-
use cargo_test_support::{basic_manifest, project, t};
6+
use cargo_test_support::{basic_manifest, project, str, t};
87
use std::fs;
98

109
fn setup() {
@@ -52,17 +51,21 @@ fn simple() {
5251
.build();
5352

5453
p.cargo("build")
55-
.with_stderr(
56-
"\
54+
.with_stderr_data(str![[r#"
5755
[LOCKING] 2 packages to latest compatible versions
58-
[UNPACKING] bar v0.0.1 ([..])
56+
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
5957
[COMPILING] bar v0.0.1
60-
[COMPILING] foo v0.0.1 ([CWD])
61-
[FINISHED] [..]
62-
",
63-
)
58+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
59+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
60+
61+
"#]])
62+
.run();
63+
p.cargo("build")
64+
.with_stderr_data(str![[r#"
65+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
66+
67+
"#]])
6468
.run();
65-
p.cargo("build").with_stderr("[FINISHED] [..]").run();
6669
p.cargo("test").run();
6770
}
6871

@@ -95,13 +98,12 @@ fn not_found() {
9598

9699
p.cargo("check")
97100
.with_status(101)
98-
.with_stderr(
99-
"\
101+
.with_stderr_data(str![[r#"
100102
[ERROR] no matching package named `baz` found
101103
location searched: registry `crates-io`
102-
required by package `foo v0.0.1 ([..]/foo)`
103-
",
104-
)
104+
required by package `foo v0.0.1 ([ROOT]/foo)`
105+
106+
"#]])
105107
.run();
106108
}
107109

@@ -137,11 +139,10 @@ fn depend_on_yanked() {
137139
.publish();
138140

139141
p.cargo("check")
140-
.with_stderr(
141-
"\
142-
[FINISHED] [..]
143-
",
144-
)
142+
.with_stderr_data(str![[r#"
143+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
144+
145+
"#]])
145146
.run();
146147
}
147148

@@ -175,15 +176,14 @@ fn multiple_versions() {
175176
.build();
176177

177178
p.cargo("check")
178-
.with_stderr(
179-
"\
179+
.with_stderr_data(str![[r#"
180180
[LOCKING] 2 packages to latest compatible versions
181-
[UNPACKING] bar v0.1.0 ([..])
181+
[UNPACKING] bar v0.1.0 (registry `[ROOT]/registry`)
182182
[CHECKING] bar v0.1.0
183-
[CHECKING] foo v0.0.1 ([CWD])
184-
[FINISHED] [..]
185-
",
186-
)
183+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
184+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
185+
186+
"#]])
187187
.run();
188188

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

194194
p.cargo("update")
195-
.with_stderr(
196-
"\
195+
.with_stderr_data(str![[r#"
197196
[LOCKING] 1 package to latest compatible version
198-
[UPDATING] bar v0.1.0 -> v0.2.0",
199-
)
197+
[UPDATING] bar v0.1.0 -> v0.2.0
198+
199+
"#]])
200200
.run();
201201
}
202202

@@ -241,16 +241,18 @@ fn multiple_names() {
241241
.build();
242242

243243
p.cargo("check")
244-
.with_stderr(
245-
"\
244+
.with_stderr_data(
245+
str![[r#"
246246
[LOCKING] 3 packages to latest compatible versions
247-
[UNPACKING] [..]
248-
[UNPACKING] [..]
249-
[CHECKING] [..]
250-
[CHECKING] [..]
251-
[CHECKING] foo v0.0.1 ([CWD])
252-
[FINISHED] [..]
253-
",
247+
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
248+
[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`)
249+
[CHECKING] bar v0.0.1
250+
[CHECKING] baz v0.1.0
251+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
252+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
253+
254+
"#]]
255+
.unordered(),
254256
)
255257
.run();
256258
}
@@ -297,17 +299,16 @@ fn interdependent() {
297299
.build();
298300

299301
p.cargo("check")
300-
.with_stderr(
301-
"\
302+
.with_stderr_data(str![[r#"
302303
[LOCKING] 3 packages to latest compatible versions
303-
[UNPACKING] [..]
304-
[UNPACKING] [..]
304+
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
305+
[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`)
305306
[CHECKING] bar v0.0.1
306307
[CHECKING] baz v0.1.0
307-
[CHECKING] foo v0.0.1 ([CWD])
308-
[FINISHED] [..]
309-
",
310-
)
308+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
309+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
310+
311+
"#]])
311312
.run();
312313
}
313314

@@ -368,17 +369,16 @@ fn path_dep_rewritten() {
368369
.build();
369370

370371
p.cargo("check")
371-
.with_stderr(
372-
"\
372+
.with_stderr_data(str![[r#"
373373
[LOCKING] 3 packages to latest compatible versions
374-
[UNPACKING] [..]
375-
[UNPACKING] [..]
374+
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
375+
[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`)
376376
[CHECKING] bar v0.0.1
377377
[CHECKING] baz v0.1.0
378-
[CHECKING] foo v0.0.1 ([CWD])
379-
[FINISHED] [..]
380-
",
381-
)
378+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
379+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
380+
381+
"#]])
382382
.run();
383383
}
384384

@@ -415,9 +415,8 @@ fn invalid_dir_bad() {
415415

416416
p.cargo("check")
417417
.with_status(101)
418-
.with_stderr(
419-
"\
420-
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]`
418+
.with_stderr_data(str![[r#"
419+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
421420
422421
Caused by:
423422
failed to load source for dependency `bar`
@@ -430,8 +429,8 @@ Caused by:
430429
431430
Caused by:
432431
local registry path is not a directory: [..]path[..]to[..]nowhere
433-
",
434-
)
432+
433+
"#]])
435434
.run();
436435
}
437436

@@ -478,8 +477,7 @@ fn different_directory_replacing_the_registry_is_bad() {
478477

479478
p.cargo("check")
480479
.with_status(101)
481-
.with_stderr(
482-
"\
480+
.with_stderr_data(str![[r#"
483481
[ERROR] checksum for `bar v0.0.1` changed between lock files
484482
485483
this could be indicative of a few possible errors:
@@ -490,8 +488,8 @@ this could be indicative of a few possible errors:
490488
491489
unable to verify that `bar v0.0.1` is the same as when the lockfile was generated
492490
493-
",
494-
)
491+
492+
"#]])
495493
.run();
496494
}
497495

@@ -536,16 +534,20 @@ fn crates_io_registry_url_is_optional() {
536534
.build();
537535

538536
p.cargo("build")
539-
.with_stderr(
540-
"\
537+
.with_stderr_data(str![[r#"
541538
[LOCKING] 2 packages to latest compatible versions
542-
[UNPACKING] bar v0.0.1 ([..])
539+
[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`)
543540
[COMPILING] bar v0.0.1
544-
[COMPILING] foo v0.0.1 ([CWD])
545-
[FINISHED] [..]
546-
",
547-
)
541+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
542+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
543+
544+
"#]])
545+
.run();
546+
p.cargo("build")
547+
.with_stderr_data(str![[r#"
548+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
549+
550+
"#]])
548551
.run();
549-
p.cargo("build").with_stderr("[FINISHED] [..]").run();
550552
p.cargo("test").run();
551553
}

tests/testsuite/locate_project.rs

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
//! Tests for the `cargo locate-project` command.
22
3-
#![allow(deprecated)]
4-
3+
use cargo_test_support::prelude::*;
54
use cargo_test_support::project;
5+
use cargo_test_support::str;
66

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

1111
p.cargo("locate-project")
12-
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
12+
.with_stdout_data(
13+
str![[r#"
14+
{
15+
"root": "[ROOT]/foo/Cargo.toml"
16+
}
17+
"#]]
18+
.json(),
19+
)
1320
.run();
1421
}
1522

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

2027
p.cargo("locate-project --message-format plain")
21-
.with_stdout("[ROOT]/foo/Cargo.toml")
28+
.with_stdout_data(str![[r#"
29+
[ROOT]/foo/Cargo.toml
30+
31+
"#]])
2232
.run();
2333

2434
p.cargo("locate-project --message-format json")
25-
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
35+
.with_stdout_data(
36+
str![[r#"
37+
{
38+
"root": "[ROOT]/foo/Cargo.toml"
39+
}
40+
"#]]
41+
.json(),
42+
)
2643
.run();
2744

2845
p.cargo("locate-project --message-format cryptic")
29-
.with_stderr("error: invalid message format specifier: `cryptic`")
46+
.with_stderr_data(str![[r#"
47+
[ERROR] invalid message format specifier: `cryptic`
48+
49+
"#]])
3050
.with_status(101)
3151
.run();
3252
}
@@ -57,22 +77,49 @@ fn workspace() {
5777
.file("inner/src/lib.rs", "")
5878
.build();
5979

60-
let outer_manifest = r#"{"root": "[ROOT]/foo/Cargo.toml"}"#;
61-
let inner_manifest = r#"{"root": "[ROOT]/foo/inner/Cargo.toml"}"#;
62-
63-
p.cargo("locate-project").with_json(outer_manifest).run();
80+
p.cargo("locate-project")
81+
.with_stdout_data(
82+
str![[r#"
83+
{
84+
"root": "[ROOT]/foo/Cargo.toml"
85+
}
86+
"#]]
87+
.json(),
88+
)
89+
.run();
6490

6591
p.cargo("locate-project")
6692
.cwd("inner")
67-
.with_json(inner_manifest)
93+
.with_stdout_data(
94+
str![[r#"
95+
{
96+
"root": "[ROOT]/foo/inner/Cargo.toml"
97+
}
98+
"#]]
99+
.json(),
100+
)
68101
.run();
69102

70103
p.cargo("locate-project --workspace")
71-
.with_json(outer_manifest)
104+
.with_stdout_data(
105+
str![[r#"
106+
{
107+
"root": "[ROOT]/foo/Cargo.toml"
108+
}
109+
"#]]
110+
.json(),
111+
)
72112
.run();
73113

74114
p.cargo("locate-project --workspace")
75115
.cwd("inner")
76-
.with_json(outer_manifest)
116+
.with_stdout_data(
117+
str![[r#"
118+
{
119+
"root": "[ROOT]/foo/Cargo.toml"
120+
}
121+
"#]]
122+
.json(),
123+
)
77124
.run();
78125
}

0 commit comments

Comments
 (0)