Skip to content

Commit 027ac51

Browse files
authored
Merge pull request #1290 from mog422/master
Display helpful advices even with -y.
2 parents 771319a + a75ef65 commit 027ac51

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

src/rustup-cli/self_update.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -302,30 +302,29 @@ pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result<
302302
process::exit(1);
303303
}
304304

305-
// More helpful advice, skip if -y
306-
if !no_prompt {
307-
let cargo_home = try!(canonical_cargo_home());
308-
let msg = if !opts.no_modify_path {
309-
if cfg!(unix) {
310-
format!(post_install_msg_unix!(), cargo_home = cargo_home)
311-
} else {
312-
format!(post_install_msg_win!(), cargo_home = cargo_home)
313-
}
305+
let cargo_home = try!(canonical_cargo_home());
306+
let msg = if !opts.no_modify_path {
307+
if cfg!(unix) {
308+
format!(post_install_msg_unix!(), cargo_home = cargo_home)
314309
} else {
315-
if cfg!(unix) {
316-
format!(
317-
post_install_msg_unix_no_modify_path!(),
318-
cargo_home = cargo_home
319-
)
320-
} else {
321-
format!(
322-
post_install_msg_win_no_modify_path!(),
323-
cargo_home = cargo_home
324-
)
325-
}
326-
};
327-
term2::stdout().md(msg);
310+
format!(post_install_msg_win!(), cargo_home = cargo_home)
311+
}
312+
} else {
313+
if cfg!(unix) {
314+
format!(
315+
post_install_msg_unix_no_modify_path!(),
316+
cargo_home = cargo_home
317+
)
318+
} else {
319+
format!(
320+
post_install_msg_win_no_modify_path!(),
321+
cargo_home = cargo_home
322+
)
323+
}
324+
};
325+
term2::stdout().md(msg);
328326

327+
if !no_prompt {
329328
// On windows, where installation happens in a console
330329
// that may have opened just for this purpose, require
331330
// the user to press a key to continue.

src/rustup-mock/src/clitools.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ pub fn expect_err_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str)
238238
}
239239
}
240240

241+
pub fn expect_ok_contains(config: &Config, args: &[&str],
242+
stdout: &str, stderr: &str) {
243+
let out = run(config, args[0], &args[1..], &[]);
244+
if !out.ok || !out.stdout.contains(stdout) || !out.stderr.contains(stderr) {
245+
print_command(args, &out);
246+
println!("expected.ok: {}", true);
247+
print_indented("expected.stdout.contains", stdout);
248+
print_indented("expected.stderr.contains", stderr);
249+
panic!();
250+
}
251+
}
252+
241253
pub fn expect_timeout_ok(config: &Config, timeout: Duration, args: &[&str]) {
242254
let mut child = cmd(config, args[0], &args[1..])
243255
.stdout(Stdio::null())

tests/cli-self-upd.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use std::path::Path;
2525
use std::fs;
2626
use std::process::Command;
2727
use remove_dir_all::remove_dir_all;
28-
use rustup_mock::clitools::{self, expect_err, expect_err_ex, expect_ok, expect_ok_ex,
29-
expect_stderr_ok, expect_stdout_ok, this_host_triple, Config, Scenario};
28+
use rustup_mock::clitools::{self, expect_err, expect_err_ex, expect_ok, expect_ok_contains,
29+
expect_ok_ex, expect_stderr_ok, expect_stdout_ok, this_host_triple,
30+
Config, Scenario};
3031
use rustup_mock::dist::calc_hash;
3132
use rustup_mock::{get_path, restore_path};
3233
use rustup_utils::{raw, utils};
@@ -813,10 +814,8 @@ fn as_rustup_setup() {
813814
#[test]
814815
fn first_install_exact() {
815816
setup(&|config| {
816-
expect_ok_ex(
817-
config,
818-
&["rustup-init", "-y"],
819-
r"
817+
expect_ok_contains(config, &["rustup-init", "-y"],
818+
r"
820819
stable installed - 1.1.0 (hash-s-2)
821820
822821
",
@@ -842,14 +841,10 @@ info: default toolchain set to 'stable'
842841
fn reinstall_exact() {
843842
setup(&|config| {
844843
expect_ok(config, &["rustup-init", "-y"]);
845-
expect_ok_ex(
846-
config,
847-
&["rustup-init", "-y"],
848-
r"
849-
",
850-
r"info: updating existing rustup installation
851-
",
852-
);
844+
expect_stderr_ok(config, &["rustup-init", "-y"],
845+
r"info: updating existing rustup installation
846+
"
847+
);
853848
});
854849
}
855850

0 commit comments

Comments
 (0)