From 6351472a80f0e86bbdf17618a65019d2490cce95 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sun, 21 Nov 2021 12:16:50 +0800 Subject: [PATCH] Add --message-format for install Signed-off-by: hi-rustin --- src/bin/cargo/commands/install.rs | 1 + tests/testsuite/install.rs | 77 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 56ea10c39..798a08d8d 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -71,6 +71,7 @@ pub fn cli() -> App { .requires("crate") .conflicts_with_all(&["git", "path", "index"]), ) + .arg_message_format() .after_help("Run `cargo help install` for more detailed information.\n") } diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index abdd861f8..b28b3743c 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -54,6 +54,83 @@ fn simple() { assert_has_not_installed_exe(cargo_home(), "foo"); } +#[cargo_test] +fn simple_with_message_format() { + pkg("foo", "0.0.1"); + + cargo_process("install foo --message-format=json") + .with_stderr( + "\ +[UPDATING] `[..]` index +[DOWNLOADING] crates ... +[DOWNLOADED] foo v0.0.1 (registry [..]) +[INSTALLING] foo v0.0.1 +[COMPILING] foo v0.0.1 +[FINISHED] release [optimized] target(s) in [..] +[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE] +[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`) +[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries +", + ) + .with_json( + r#" + { + "reason": "compiler-artifact", + "package_id": "foo 0.0.1 ([..])", + "manifest_path": "[..]", + "target": { + "kind": [ + "lib" + ], + "crate_types": [ + "lib" + ], + "name": "foo", + "src_path": "[..]/foo-0.0.1/src/lib.rs", + "edition": "2015", + "doc": true, + "doctest": true, + "test": true + }, + "profile": "{...}", + "features": [], + "filenames": "{...}", + "executable": null, + "fresh": false + } + + { + "reason": "compiler-artifact", + "package_id": "foo 0.0.1 ([..])", + "manifest_path": "[..]", + "target": { + "kind": [ + "bin" + ], + "crate_types": [ + "bin" + ], + "name": "foo", + "src_path": "[..]/foo-0.0.1/src/main.rs", + "edition": "2015", + "doc": true, + "doctest": false, + "test": true + }, + "profile": "{...}", + "features": [], + "filenames": "{...}", + "executable": "[..]", + "fresh": false + } + + {"reason":"build-finished","success":true} + "#, + ) + .run(); + assert_has_installed_exe(cargo_home(), "foo"); +} + #[cargo_test] fn with_index() { pkg("foo", "0.0.1");