Skip to content

Commit 6221d87

Browse files
committed
Auto merge of #13322 - weihanglo:pkgid-consistency, r=epage
test(pkgid): keep package ID format in sync
2 parents e01eeb0 + eb9e377 commit 6221d87

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

tests/testsuite/pkgid.rs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tests for the `cargo pkgid` command.
22
33
use cargo_test_support::basic_lib_manifest;
4+
use cargo_test_support::compare;
45
use cargo_test_support::git;
56
use cargo_test_support::project;
67
use cargo_test_support::registry::Package;
@@ -285,3 +286,145 @@ Please re-run this command with one of the following specifications:
285286
// TODO, what should the `-p` value be here?
286287
//p.cargo("update -p")
287288
}
289+
290+
// Keep Package ID format in sync among
291+
//
292+
// * Package ID specifications
293+
// * machine-readable message via `--message-format=json`
294+
// * `cargo metadata` output
295+
#[cargo_test]
296+
fn pkgid_json_message_metadata_consistency() {
297+
let p = project()
298+
.file("Cargo.toml", &basic_lib_manifest("foo"))
299+
.file("src/lib.rs", "fn unused() {}")
300+
.file("build.rs", "fn main() {}")
301+
.build();
302+
303+
p.cargo("generate-lockfile").run();
304+
305+
let output = p.cargo("pkgid").arg("foo").exec_with_output().unwrap();
306+
let pkgid = String::from_utf8(output.stdout).unwrap();
307+
let pkgid = pkgid.trim();
308+
compare::assert_match_exact("path+file://[..]/foo#0.5.0", &pkgid);
309+
310+
p.cargo("check --message-format=json")
311+
.with_json(
312+
&r#"
313+
{
314+
"reason": "compiler-artifact",
315+
"package_id": "$PKGID",
316+
"manifest_path": "[..]",
317+
"target": "{...}",
318+
"profile": "{...}",
319+
"features": [],
320+
"filenames": "{...}",
321+
"executable": null,
322+
"fresh": false
323+
}
324+
325+
{
326+
"reason": "build-script-executed",
327+
"package_id": "$PKGID",
328+
"linked_libs": [],
329+
"linked_paths": [],
330+
"cfgs": [],
331+
"env": [],
332+
"out_dir": "[..]"
333+
}
334+
335+
{
336+
"manifest_path": "[..]",
337+
"message": "{...}",
338+
"package_id": "$PKGID",
339+
"reason": "compiler-message",
340+
"target": "{...}"
341+
}
342+
343+
{
344+
"reason": "compiler-message",
345+
"package_id": "$PKGID",
346+
"manifest_path": "[..]",
347+
"target": "{...}",
348+
"message": "{...}"
349+
}
350+
351+
{
352+
"reason": "compiler-artifact",
353+
"package_id": "$PKGID",
354+
"manifest_path": "[..]",
355+
"target": "{...}",
356+
"profile": "{...}",
357+
"features": [],
358+
"filenames": "{...}",
359+
"executable": null,
360+
"fresh": false
361+
}
362+
363+
{
364+
"reason": "build-finished",
365+
"success": true
366+
}
367+
"#
368+
.replace("$PKGID", pkgid),
369+
)
370+
.run();
371+
372+
p.cargo("metadata")
373+
.with_json(
374+
&r#"
375+
{
376+
"metadata": null,
377+
"packages": [
378+
{
379+
"authors": "{...}",
380+
"categories": [],
381+
"default_run": null,
382+
"dependencies": [],
383+
"description": null,
384+
"documentation": null,
385+
"edition": "2015",
386+
"features": {},
387+
"homepage": null,
388+
"id": "$PKGID",
389+
"keywords": [],
390+
"license": null,
391+
"license_file": null,
392+
"links": null,
393+
"manifest_path": "[..]",
394+
"metadata": null,
395+
"name": "foo",
396+
"publish": null,
397+
"readme": null,
398+
"repository": null,
399+
"rust_version": null,
400+
"source": null,
401+
"targets": "{...}",
402+
"version": "0.5.0"
403+
}
404+
],
405+
"resolve": {
406+
"nodes": [
407+
{
408+
"dependencies": [],
409+
"deps": [],
410+
"features": [],
411+
"id": "$PKGID"
412+
}
413+
],
414+
"root": "$PKGID"
415+
},
416+
"target_directory": "[..]",
417+
"version": 1,
418+
"workspace_default_members": [
419+
"$PKGID"
420+
],
421+
"workspace_members": [
422+
"$PKGID"
423+
],
424+
"workspace_root": "[..]"
425+
}
426+
"#
427+
.replace("$PKGID", pkgid),
428+
)
429+
.run()
430+
}

0 commit comments

Comments
 (0)