1
1
//! Tests for the `cargo pkgid` command.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: basic_lib_manifest;
6
4
use cargo_test_support:: compare:: assert_e2e;
7
5
use cargo_test_support:: git;
6
+ use cargo_test_support:: prelude:: * ;
8
7
use cargo_test_support:: project;
9
8
use cargo_test_support:: registry:: Package ;
10
9
use cargo_test_support:: str;
@@ -40,38 +39,36 @@ fn local() {
40
39
p. cargo ( "generate-lockfile" ) . run ( ) ;
41
40
42
41
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
+ "# ] ] )
47
46
. run ( ) ;
48
47
49
48
// Bad file URL.
50
49
p. cargo ( "pkgid ./Cargo.toml" )
51
50
. 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`
55
53
56
54
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
+ "# ] ] )
60
58
. run ( ) ;
61
59
62
60
// Bad file URL with similar name.
63
61
p. cargo ( "pkgid './bar'" )
64
62
. 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`
68
65
69
- <tab> Did you mean `bar`?
66
+ Did you mean `bar`?
70
67
71
68
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
+ "# ] ] )
75
72
. run ( ) ;
76
73
}
77
74
@@ -98,32 +95,33 @@ fn registry() {
98
95
p. cargo ( "generate-lockfile" ) . run ( ) ;
99
96
100
97
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
+ "# ] ] )
102
102
. run ( ) ;
103
103
104
104
// Bad URL.
105
105
p. cargo ( "pkgid https://example.com/crates-io" )
106
106
. 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
110
109
Did you mean one of these?
111
110
112
111
113
- " ,
114
- )
112
+
113
+ "# ] ] )
115
114
. run ( ) ;
116
115
117
116
// Bad name.
118
117
p. cargo ( "pkgid crates_io" )
119
118
. 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
123
121
124
- <tab> Did you mean `crates-io`?
125
- " ,
126
- )
122
+ Did you mean `crates-io`?
123
+
124
+ "# ] ] )
127
125
. run ( ) ;
128
126
}
129
127
@@ -152,56 +150,55 @@ fn multiple_versions() {
152
150
p. cargo ( "generate-lockfile" ) . run ( ) ;
153
151
154
152
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
+ "# ] ] )
156
157
. run ( ) ;
157
158
158
159
// Incomplete version.
159
160
p. cargo ( "pkgid two-ver@0" )
160
161
. 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.
164
164
Please re-run this command with one of the following specifications:
165
165
166
166
167
- " ,
168
- )
167
+
168
+ "# ] ] )
169
169
. run ( ) ;
170
170
171
171
// Incomplete version.
172
172
p
. cargo ( "pkgid [email protected] " )
173
- . with_stdout (
174
- "\
173
+ . with_stdout_data ( str![ [ r#"
175
174
registry+https://github.com/rust-lang/crates.io-index#[email protected]
176
- " ,
177
- )
175
+
176
+ "# ] ] )
178
177
. run ( ) ;
179
178
180
179
// Ambiguous.
181
180
p. cargo ( "pkgid two-ver" )
182
181
. 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.
186
184
Please re-run this command with one of the following specifications:
187
185
188
186
189
- " ,
190
- )
187
+
188
+ "# ] ] )
191
189
. run ( ) ;
192
190
193
191
// Bad version.
194
192
p. cargo ( "pkgid two-ver:0.3.0" )
195
193
. 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
199
196
Did you mean one of these?
200
197
201
198
202
199
203
- " ,
204
- )
200
+
201
+ "# ] ] )
205
202
. run ( ) ;
206
203
}
207
204
@@ -260,12 +257,12 @@ fn multiple_git_same_version() {
260
257
261
258
p. cargo ( "check" ) . run ( ) ;
262
259
p. cargo ( "tree" )
263
- . with_stdout ( & format ! (
260
+ . with_stdout_data ( & format ! (
264
261
"\
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={}#{})
269
266
" ,
270
267
rev2,
271
268
& rev2. to_string( ) [ ..8 ] ,
@@ -277,14 +274,13 @@ foo v0.1.0 ([..]/foo)
277
274
// possible pkgids are also ambiguous.
278
275
p. cargo ( "pkgid xyz" )
279
276
. 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.
283
279
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
+ "# ] ] )
288
284
. run ( ) ;
289
285
// TODO, what should the `-p` value be here?
290
286
//p.cargo("update -p")
@@ -311,75 +307,27 @@ fn pkgid_json_message_metadata_consistency() {
311
307
assert_e2e ( ) . eq ( pkgid, str![ "path+[ROOTURL]/foo#0.5.0" ] ) ;
312
308
313
309
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 ( ) )
373
319
. run ( ) ;
374
320
375
321
p. cargo ( "metadata" )
376
- . with_json (
377
- & r#"
322
+ . with_stdout_data (
323
+ str! [ [ r#"
378
324
{
379
325
"metadata": null,
380
326
"packages": [
381
327
{
382
- "authors": "{...}",
328
+ "authors": [
329
+
330
+ ],
383
331
"categories": [],
384
332
"default_run": null,
385
333
"dependencies": [],
@@ -388,12 +336,12 @@ fn pkgid_json_message_metadata_consistency() {
388
336
"edition": "2015",
389
337
"features": {},
390
338
"homepage": null,
391
- "id": "$PKGID ",
339
+ "id": "path+[ROOTURL]/foo#0.5.0 ",
392
340
"keywords": [],
393
341
"license": null,
394
342
"license_file": null,
395
343
"links": null,
396
- "manifest_path": "[..] ",
344
+ "manifest_path": "[ROOT]/foo/Cargo.toml ",
397
345
"metadata": null,
398
346
"name": "foo",
399
347
"publish": null,
@@ -411,23 +359,23 @@ fn pkgid_json_message_metadata_consistency() {
411
359
"dependencies": [],
412
360
"deps": [],
413
361
"features": [],
414
- "id": "$PKGID "
362
+ "id": "path+[ROOTURL]/foo#0.5.0 "
415
363
}
416
364
],
417
- "root": "$PKGID "
365
+ "root": "path+[ROOTURL]/foo#0.5.0 "
418
366
},
419
- "target_directory": "[..] ",
367
+ "target_directory": "[ROOT]/foo/target ",
420
368
"version": 1,
421
369
"workspace_default_members": [
422
- "$PKGID "
370
+ "path+[ROOTURL]/foo#0.5.0 "
423
371
],
424
372
"workspace_members": [
425
- "$PKGID "
373
+ "path+[ROOTURL]/foo#0.5.0 "
426
374
],
427
- "workspace_root": "[..] "
375
+ "workspace_root": "[ROOT]/foo "
428
376
}
429
- "#
430
- . replace ( "$PKGID" , pkgid ) ,
377
+ "# ] ]
378
+ . json ( ) ,
431
379
)
432
380
. run ( )
433
381
}
0 commit comments