Skip to content

Commit ad6f029

Browse files
committed
test: migrate pkgid to snapbox
1 parent bb1a344 commit ad6f029

File tree

1 file changed

+83
-135
lines changed

1 file changed

+83
-135
lines changed

tests/testsuite/pkgid.rs

Lines changed: 83 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Tests for the `cargo pkgid` command.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::basic_lib_manifest;
64
use cargo_test_support::compare::assert_e2e;
75
use cargo_test_support::git;
6+
use cargo_test_support::prelude::*;
87
use cargo_test_support::project;
98
use cargo_test_support::registry::Package;
109
use cargo_test_support::str;
@@ -40,38 +39,36 @@ fn local() {
4039
p.cargo("generate-lockfile").run();
4140

4241
p.cargo("pkgid foo")
43-
.with_stdout(format!(
44-
"path+file://[..]{}#0.1.0",
45-
p.root().to_str().unwrap()
46-
))
42+
.with_stdout_data(str![[r#"
43+
path+[ROOTURL]/foo#0.1.0
44+
45+
"#]])
4746
.run();
4847

4948
// Bad file URL.
5049
p.cargo("pkgid ./Cargo.toml")
5150
.with_status(101)
52-
.with_stderr(
53-
"\
54-
error: invalid package ID specification: `./Cargo.toml`
51+
.with_stderr_data(str![[r#"
52+
[ERROR] invalid package ID specification: `./Cargo.toml`
5553
5654
Caused by:
57-
package ID specification `./Cargo.toml` looks like a file path, maybe try file://[..]/Cargo.toml
58-
",
59-
)
55+
package ID specification `./Cargo.toml` looks like a file path, maybe try [ROOTURL]/foo/Cargo.toml
56+
57+
"#]])
6058
.run();
6159

6260
// Bad file URL with similar name.
6361
p.cargo("pkgid './bar'")
6462
.with_status(101)
65-
.with_stderr(
66-
"\
67-
error: invalid package ID specification: `./bar`
63+
.with_stderr_data(str![[r#"
64+
[ERROR] invalid package ID specification: `./bar`
6865
69-
<tab>Did you mean `bar`?
66+
Did you mean `bar`?
7067
7168
Caused by:
72-
package ID specification `./bar` looks like a file path, maybe try file://[..]/bar
73-
",
74-
)
69+
package ID specification `./bar` looks like a file path, maybe try [ROOTURL]/foo/bar
70+
71+
"#]])
7572
.run();
7673
}
7774

@@ -98,32 +95,33 @@ fn registry() {
9895
p.cargo("generate-lockfile").run();
9996

10097
p.cargo("pkgid crates-io")
101-
.with_stdout("registry+https://github.com/rust-lang/crates.io-index#[email protected]")
98+
.with_stdout_data(str![[r#"
99+
registry+https://github.com/rust-lang/crates.io-index#[email protected]
100+
101+
"#]])
102102
.run();
103103

104104
// Bad URL.
105105
p.cargo("pkgid https://example.com/crates-io")
106106
.with_status(101)
107-
.with_stderr(
108-
"\
109-
error: package ID specification `https://example.com/crates-io` did not match any packages
107+
.with_stderr_data(str![[r#"
108+
[ERROR] package ID specification `https://example.com/crates-io` did not match any packages
110109
Did you mean one of these?
111110
112111
113-
",
114-
)
112+
113+
"#]])
115114
.run();
116115

117116
// Bad name.
118117
p.cargo("pkgid crates_io")
119118
.with_status(101)
120-
.with_stderr(
121-
"\
122-
error: package ID specification `crates_io` did not match any packages
119+
.with_stderr_data(str![[r#"
120+
[ERROR] package ID specification `crates_io` did not match any packages
123121
124-
<tab>Did you mean `crates-io`?
125-
",
126-
)
122+
Did you mean `crates-io`?
123+
124+
"#]])
127125
.run();
128126
}
129127

@@ -152,56 +150,55 @@ fn multiple_versions() {
152150
p.cargo("generate-lockfile").run();
153151

154152
p.cargo("pkgid two-ver:0.2.0")
155-
.with_stdout("registry+https://github.com/rust-lang/crates.io-index#[email protected]")
153+
.with_stdout_data(str![[r#"
154+
registry+https://github.com/rust-lang/crates.io-index#[email protected]
155+
156+
"#]])
156157
.run();
157158

158159
// Incomplete version.
159160
p.cargo("pkgid two-ver@0")
160161
.with_status(101)
161-
.with_stderr(
162-
"\
163-
error: There are multiple `two-ver` packages in your project, and the specification `two-ver@0` is ambiguous.
162+
.with_stderr_data(str![[r#"
163+
[ERROR] There are multiple `two-ver` packages in your project, and the specification `two-ver@0` is ambiguous.
164164
Please re-run this command with one of the following specifications:
165165
166166
167-
",
168-
)
167+
168+
"#]])
169169
.run();
170170

171171
// Incomplete version.
172172
p.cargo("pkgid [email protected]")
173-
.with_stdout(
174-
"\
173+
.with_stdout_data(str![[r#"
175174
registry+https://github.com/rust-lang/crates.io-index#[email protected]
176-
",
177-
)
175+
176+
"#]])
178177
.run();
179178

180179
// Ambiguous.
181180
p.cargo("pkgid two-ver")
182181
.with_status(101)
183-
.with_stderr(
184-
"\
185-
error: There are multiple `two-ver` packages in your project, and the specification `two-ver` is ambiguous.
182+
.with_stderr_data(str![[r#"
183+
[ERROR] There are multiple `two-ver` packages in your project, and the specification `two-ver` is ambiguous.
186184
Please re-run this command with one of the following specifications:
187185
188186
189-
",
190-
)
187+
188+
"#]])
191189
.run();
192190

193191
// Bad version.
194192
p.cargo("pkgid two-ver:0.3.0")
195193
.with_status(101)
196-
.with_stderr(
197-
"\
198-
error: package ID specification `[email protected]` did not match any packages
194+
.with_stderr_data(str![[r#"
195+
[ERROR] package ID specification `[email protected]` did not match any packages
199196
Did you mean one of these?
200197
201198
202199
203-
",
204-
)
200+
201+
"#]])
205202
.run();
206203
}
207204

@@ -260,12 +257,12 @@ fn multiple_git_same_version() {
260257

261258
p.cargo("check").run();
262259
p.cargo("tree")
263-
.with_stdout(&format!(
260+
.with_stdout_data(&format!(
264261
"\
265-
foo v0.1.0 ([..]/foo)
266-
├── bar v0.1.0 ([..]/foo/bar)
267-
│ └── xyz v0.5.0 (file://[..]/xyz?rev={}#{})
268-
└── xyz v0.5.0 (file://[..]/xyz?rev={}#{})
262+
foo v0.1.0 ([ROOT]/foo)
263+
├── bar v0.1.0 ([ROOT]/foo/bar)
264+
│ └── xyz v0.5.0 ([ROOTURL]/xyz?rev={}#{})
265+
└── xyz v0.5.0 ([ROOTURL]/xyz?rev={}#{})
269266
",
270267
rev2,
271268
&rev2.to_string()[..8],
@@ -277,14 +274,13 @@ foo v0.1.0 ([..]/foo)
277274
// possible pkgids are also ambiguous.
278275
p.cargo("pkgid xyz")
279276
.with_status(101)
280-
.with_stderr(
281-
"\
282-
error: There are multiple `xyz` packages in your project, and the specification `xyz` is ambiguous.
277+
.with_stderr_data(str![[r#"
278+
[ERROR] There are multiple `xyz` packages in your project, and the specification `xyz` is ambiguous.
283279
Please re-run this command with one of the following specifications:
284-
git+file://[..]/xyz?rev=[..]#0.5.0
285-
git+file://[..]/xyz?rev=[..]#0.5.0
286-
",
287-
)
280+
git+[ROOTURL]/xyz?rev=[..]#0.5.0
281+
git+[ROOTURL]/xyz?rev=[..]#0.5.0
282+
283+
"#]])
288284
.run();
289285
// TODO, what should the `-p` value be here?
290286
//p.cargo("update -p")
@@ -311,75 +307,27 @@ fn pkgid_json_message_metadata_consistency() {
311307
assert_e2e().eq(pkgid, str!["path+[ROOTURL]/foo#0.5.0"]);
312308

313309
p.cargo("check --message-format=json")
314-
.with_json(
315-
&r#"
316-
{
317-
"reason": "compiler-artifact",
318-
"package_id": "$PKGID",
319-
"manifest_path": "[..]",
320-
"target": "{...}",
321-
"profile": "{...}",
322-
"features": [],
323-
"filenames": "{...}",
324-
"executable": null,
325-
"fresh": false
326-
}
327-
328-
{
329-
"reason": "build-script-executed",
330-
"package_id": "$PKGID",
331-
"linked_libs": [],
332-
"linked_paths": [],
333-
"cfgs": [],
334-
"env": [],
335-
"out_dir": "[..]"
336-
}
337-
338-
{
339-
"manifest_path": "[..]",
340-
"message": "{...}",
341-
"package_id": "$PKGID",
342-
"reason": "compiler-message",
343-
"target": "{...}"
344-
}
345-
346-
{
347-
"reason": "compiler-message",
348-
"package_id": "$PKGID",
349-
"manifest_path": "[..]",
350-
"target": "{...}",
351-
"message": "{...}"
352-
}
353-
354-
{
355-
"reason": "compiler-artifact",
356-
"package_id": "$PKGID",
357-
"manifest_path": "[..]",
358-
"target": "{...}",
359-
"profile": "{...}",
360-
"features": [],
361-
"filenames": "{...}",
362-
"executable": null,
363-
"fresh": false
364-
}
365-
366-
{
367-
"reason": "build-finished",
368-
"success": true
369-
}
370-
"#
371-
.replace("$PKGID", pkgid),
372-
)
310+
.with_stdout_data(str![[r#"
311+
{"executable":null,"features":[],"filenames":"{...}","fresh":false,"manifest_path":"[ROOT]/foo/Cargo.toml","package_id":"path+[ROOTURL]/foo#0.5.0","profile":"{...}","reason":"compiler-artifact","target":"{...}"}
312+
{"cfgs":[],"env":[],"linked_libs":[],"linked_paths":[],"out_dir":"[ROOT]/foo/target/debug/build/foo-[HASH]/out","package_id":"path+[ROOTURL]/foo#0.5.0","reason":"build-script-executed"}
313+
{"manifest_path":"[ROOT]/foo/Cargo.toml","message":"{...}","package_id":"path+[ROOTURL]/foo#0.5.0","reason":"compiler-message","target":"{...}"}
314+
{"manifest_path":"[ROOT]/foo/Cargo.toml","message":"{...}","package_id":"path+[ROOTURL]/foo#0.5.0","reason":"compiler-message","target":"{...}"}
315+
{"executable":null,"features":[],"filenames":"{...}","fresh":false,"manifest_path":"[ROOT]/foo/Cargo.toml","package_id":"path+[ROOTURL]/foo#0.5.0","profile":"{...}","reason":"compiler-artifact","target":"{...}"}
316+
{"reason":"build-finished","success":true}
317+
318+
"#]].json_lines())
373319
.run();
374320

375321
p.cargo("metadata")
376-
.with_json(
377-
&r#"
322+
.with_stdout_data(
323+
str![[r#"
378324
{
379325
"metadata": null,
380326
"packages": [
381327
{
382-
"authors": "{...}",
328+
"authors": [
329+
330+
],
383331
"categories": [],
384332
"default_run": null,
385333
"dependencies": [],
@@ -388,12 +336,12 @@ fn pkgid_json_message_metadata_consistency() {
388336
"edition": "2015",
389337
"features": {},
390338
"homepage": null,
391-
"id": "$PKGID",
339+
"id": "path+[ROOTURL]/foo#0.5.0",
392340
"keywords": [],
393341
"license": null,
394342
"license_file": null,
395343
"links": null,
396-
"manifest_path": "[..]",
344+
"manifest_path": "[ROOT]/foo/Cargo.toml",
397345
"metadata": null,
398346
"name": "foo",
399347
"publish": null,
@@ -411,23 +359,23 @@ fn pkgid_json_message_metadata_consistency() {
411359
"dependencies": [],
412360
"deps": [],
413361
"features": [],
414-
"id": "$PKGID"
362+
"id": "path+[ROOTURL]/foo#0.5.0"
415363
}
416364
],
417-
"root": "$PKGID"
365+
"root": "path+[ROOTURL]/foo#0.5.0"
418366
},
419-
"target_directory": "[..]",
367+
"target_directory": "[ROOT]/foo/target",
420368
"version": 1,
421369
"workspace_default_members": [
422-
"$PKGID"
370+
"path+[ROOTURL]/foo#0.5.0"
423371
],
424372
"workspace_members": [
425-
"$PKGID"
373+
"path+[ROOTURL]/foo#0.5.0"
426374
],
427-
"workspace_root": "[..]"
375+
"workspace_root": "[ROOT]/foo"
428376
}
429-
"#
430-
.replace("$PKGID", pkgid),
377+
"#]]
378+
.json(),
431379
)
432380
.run()
433381
}

0 commit comments

Comments
 (0)