1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
|
//! Testing self install, uninstall and update
use std::env;
use std::env::consts::EXE_SUFFIX;
use std::fs;
use std::path::Path;
use std::process::Command;
use remove_dir_all::remove_dir_all;
use retry::{
delay::{jitter, Fibonacci},
retry,
};
use rustup::test::{
mock::{
clitools::{self, output_release_file, self_update_setup, Config, Scenario},
dist::calc_hash,
},
this_host_triple, with_saved_path,
};
use rustup::utils::{raw, utils};
use rustup::{for_host, DUP_TOOLS, TOOLS};
use rustup_macros::integration_test as test;
#[cfg(windows)]
use rustup::test::with_saved_reg_value;
const TEST_VERSION: &str = "1.1.1";
pub fn update_setup(f: &dyn Fn(&mut Config, &Path)) {
self_update_setup(f, TEST_VERSION)
}
/// Empty dist server, rustup installed with no toolchain
fn setup_empty_installed(f: &dyn Fn(&mut Config)) {
clitools::test(Scenario::Empty, &|config| {
config.expect_ok(&[
"rustup-init",
"-y",
"--no-modify-path",
"--default-toolchain",
"none",
]);
f(config);
})
}
/// SimpleV3 dist server, rustup installed with default toolchain
fn setup_installed(f: &dyn Fn(&mut Config)) {
clitools::test(Scenario::SimpleV2, &|config| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
f(config);
})
}
#[test]
/// This is the primary smoke test testing the full end to end behavior of the
/// installation code path: everything that is output, the proxy installation,
/// status of the proxies.
fn install_bins_to_cargo_home() {
clitools::test(Scenario::SimpleV2, &|config| {
with_saved_path(&mut || {
config.expect_ok_contains(
&["rustup-init", "-y"],
for_host!(
r"
stable-{0} installed - 1.1.0 (hash-stable-1.1.0)
"
),
for_host!(
r"info: syncing channel updates for 'stable-{0}'
info: latest update on 2015-01-02, rust version 1.1.0 (hash-stable-1.1.0)
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: default toolchain set to 'stable-{0}'
"
),
);
#[cfg(windows)]
fn check(path: &Path) {
assert!(path.exists());
}
#[cfg(not(windows))]
fn check(path: &Path) {
fn is_exe(path: &Path) -> bool {
use std::os::unix::fs::MetadataExt;
let mode = path.metadata().unwrap().mode();
mode & 0o777 == 0o755
}
assert!(is_exe(path));
}
for tool in TOOLS.iter().chain(DUP_TOOLS.iter()) {
let path = &config.cargodir.join(&format!("bin/{tool}{EXE_SUFFIX}"));
check(path);
}
})
});
}
#[test]
fn install_twice() {
clitools::test(Scenario::SimpleV2, &|config| {
with_saved_path(&mut || {
config.expect_ok(&["rustup-init", "-y"]);
config.expect_ok(&["rustup-init", "-y"]);
let rustup = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
assert!(rustup.exists());
})
});
}
#[test]
/// Smoke test for the entire install process when dirs need to be made :
/// depending just on unit tests here could miss subtle dependencies being added
/// earlier in the code, so a black-box test is needed.
fn install_creates_cargo_home() {
clitools::test(Scenario::Empty, &|config| {
remove_dir_all(&config.cargodir).unwrap();
config.rustupdir.remove().unwrap();
config.expect_ok(&[
"rustup-init",
"-y",
"--no-modify-path",
"--default-toolchain",
"none",
]);
assert!(config.cargodir.exists());
});
}
#[test]
/// Functional test needed here - we need to do the full dance where we start
/// with rustup.exe and end up deleting that exe itself.
fn uninstall_deletes_bins() {
setup_empty_installed(&|config| {
// no-modify-path isn't needed here, as the test-dir-path isn't present
// in the registry, so the no-change code path will be triggered.
config.expect_ok(&["rustup", "self", "uninstall", "-y"]);
let rustup = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
let rustc = config.cargodir.join(format!("bin/rustc{EXE_SUFFIX}"));
let rustdoc = config.cargodir.join(format!("bin/rustdoc{EXE_SUFFIX}"));
let cargo = config.cargodir.join(format!("bin/cargo{EXE_SUFFIX}"));
let rust_lldb = config.cargodir.join(format!("bin/rust-lldb{EXE_SUFFIX}"));
let rust_gdb = config.cargodir.join(format!("bin/rust-gdb{EXE_SUFFIX}"));
let rust_gdbgui = config.cargodir.join(format!("bin/rust-gdbgui{EXE_SUFFIX}"));
assert!(!rustup.exists());
assert!(!rustc.exists());
assert!(!rustdoc.exists());
assert!(!cargo.exists());
assert!(!rust_lldb.exists());
assert!(!rust_gdb.exists());
assert!(!rust_gdbgui.exists());
});
}
#[test]
fn uninstall_works_if_some_bins_dont_exist() {
setup_empty_installed(&|config| {
let rustup = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
let rustc = config.cargodir.join(format!("bin/rustc{EXE_SUFFIX}"));
let rustdoc = config.cargodir.join(format!("bin/rustdoc{EXE_SUFFIX}"));
let cargo = config.cargodir.join(format!("bin/cargo{EXE_SUFFIX}"));
let rust_lldb = config.cargodir.join(format!("bin/rust-lldb{EXE_SUFFIX}"));
let rust_gdb = config.cargodir.join(format!("bin/rust-gdb{EXE_SUFFIX}"));
let rust_gdbgui = config.cargodir.join(format!("bin/rust-gdbgui{EXE_SUFFIX}"));
fs::remove_file(&rustc).unwrap();
fs::remove_file(&cargo).unwrap();
config.expect_ok(&["rustup", "self", "uninstall", "-y"]);
assert!(!rustup.exists());
assert!(!rustc.exists());
assert!(!rustdoc.exists());
assert!(!cargo.exists());
assert!(!rust_lldb.exists());
assert!(!rust_gdb.exists());
assert!(!rust_gdbgui.exists());
});
}
#[test]
fn uninstall_deletes_rustup_home() {
setup_empty_installed(&|config| {
config.expect_ok(&["rustup", "self", "uninstall", "-y"]);
assert!(!config.rustupdir.has("."));
});
}
#[test]
fn uninstall_works_if_rustup_home_doesnt_exist() {
setup_empty_installed(&|config| {
config.rustupdir.remove().unwrap();
config.expect_ok(&["rustup", "self", "uninstall", "-y"]);
});
}
#[test]
fn uninstall_deletes_cargo_home() {
setup_empty_installed(&|config| {
config.expect_ok(&["rustup", "self", "uninstall", "-y"]);
assert!(!config.cargodir.exists());
});
}
#[test]
fn uninstall_fails_if_not_installed() {
setup_empty_installed(&|config| {
let rustup = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
fs::remove_file(rustup).unwrap();
config.expect_err(
&["rustup", "self", "uninstall", "-y"],
"rustup is not installed",
);
});
}
// The other tests here just run rustup from a temp directory. This
// does the uninstall by actually invoking the installed binary in
// order to test that it can successfully delete itself.
#[test]
#[cfg_attr(target_os = "macos", ignore)] // FIXME #1515
fn uninstall_self_delete_works() {
setup_empty_installed(&|config| {
let rustup = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
let mut cmd = Command::new(rustup.clone());
cmd.args(["self", "uninstall", "-y"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
println!("out: {}", String::from_utf8(out.stdout).unwrap());
println!("err: {}", String::from_utf8(out.stderr).unwrap());
assert!(out.status.success());
assert!(!rustup.exists());
assert!(!config.cargodir.exists());
let rustc = config.cargodir.join(format!("bin/rustc{EXE_SUFFIX}"));
let rustdoc = config.cargodir.join(format!("bin/rustdoc{EXE_SUFFIX}"));
let cargo = config.cargodir.join(format!("bin/cargo{EXE_SUFFIX}"));
let rust_lldb = config.cargodir.join(format!("bin/rust-lldb{EXE_SUFFIX}"));
let rust_gdb = config.cargodir.join(format!("bin/rust-gdb{EXE_SUFFIX}"));
let rust_gdbgui = config.cargodir.join(format!("bin/rust-gdbgui{EXE_SUFFIX}"));
assert!(!rustc.exists());
assert!(!rustdoc.exists());
assert!(!cargo.exists());
assert!(!rust_lldb.exists());
assert!(!rust_gdb.exists());
assert!(!rust_gdbgui.exists());
});
}
// On windows rustup self uninstall temporarily puts a rustup-gc-$randomnumber.exe
// file in CONFIG.CARGODIR/.. ; check that it doesn't exist.
#[test]
fn uninstall_doesnt_leave_gc_file() {
setup_empty_installed(&|config| {
config.expect_ok(&["rustup", "self", "uninstall", "-y"]);
let parent = config.cargodir.parent().unwrap();
// The gc removal happens after rustup terminates. Typically under
// 100ms, but during the contention of test suites can be substantially
// longer while still succeeding.
let check = || ensure_empty(parent);
match retry(Fibonacci::from_millis(1).map(jitter).take(23), check) {
Ok(_) => (),
Err(e) => panic!("{e}"),
}
})
}
fn ensure_empty(dir: &Path) -> Result<(), GcErr> {
let garbage = fs::read_dir(dir)
.unwrap()
.map(|d| d.unwrap().path().to_string_lossy().to_string())
.collect::<Vec<_>>();
match garbage.len() {
0 => Ok(()),
_ => Err(GcErr(garbage)),
}
}
#[derive(thiserror::Error, Debug)]
#[error("garbage remaining: {:?}", .0)]
struct GcErr(Vec<String>);
#[test]
fn update_exact() {
let version = env!("CARGO_PKG_VERSION");
let expected_output = "info: checking for self-update
info: downloading self-update
"
.to_string();
update_setup(&|config, _| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_ok_ex(
&["rustup", "self", "update"],
&format!(" rustup updated - {version} (from {version})\n\n",),
&expected_output,
);
});
}
#[test]
#[cfg(windows)]
fn update_overwrites_programs_display_version() {
let root = &winreg::RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
let key = r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Rustup";
let name = "DisplayVersion";
const PLACEHOLDER_VERSION: &str = "9.999.99";
let version = env!("CARGO_PKG_VERSION");
update_setup(&|config, _| {
with_saved_reg_value(root, key, name, &mut || {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
root.create_subkey(key)
.unwrap()
.0
.set_value(name, &PLACEHOLDER_VERSION)
.unwrap();
config.expect_ok(&["rustup", "self", "update"]);
assert_eq!(
root.open_subkey(key)
.unwrap()
.get_value::<String, _>(name)
.unwrap(),
version,
);
});
});
}
#[test]
fn update_but_not_installed() {
update_setup(&|config, _| {
config.expect_err_ex(
&["rustup", "self", "update"],
r"",
&format!(
r"error: rustup is not installed at '{}'
",
config.cargodir.display()
),
);
});
}
#[test]
fn update_but_delete_existing_updater_first() {
update_setup(&|config, _| {
// The updater is stored in a known location
let setup = config.cargodir.join(format!("bin/rustup-init{EXE_SUFFIX}"));
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
// If it happens to already exist for some reason it
// should just be deleted.
raw::write_file(&setup, "").unwrap();
config.expect_ok(&["rustup", "self", "update"]);
let rustup = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
assert!(rustup.exists());
});
}
#[test]
fn update_download_404() {
update_setup(&|config, self_dist| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
let trip = this_host_triple();
let dist_dir = self_dist.join(format!("archive/{TEST_VERSION}/{trip}"));
let dist_exe = dist_dir.join(format!("rustup-init{EXE_SUFFIX}"));
fs::remove_file(dist_exe).unwrap();
config.expect_err(&["rustup", "self", "update"], "could not download file");
});
}
#[test]
fn update_bogus_version() {
update_setup(&|config, _| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_err(
&["rustup", "update", "1.0.0-alpha"],
"invalid value '1.0.0-alpha' for '[toolchain]...': invalid toolchain name: '1.0.0-alpha'",
);
});
}
// Check that rustup.exe has changed after the update. This
// is hard for windows because the running process needs to exit
// before the new updater can delete it.
#[test]
fn update_updates_rustup_bin() {
update_setup(&|config, _| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
let bin = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
let before_hash = calc_hash(&bin);
// Running the self update command on the installed binary,
// so that the running binary must be replaced.
let mut cmd = Command::new(&bin);
cmd.args(["self", "update"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
println!("out: {}", String::from_utf8(out.stdout).unwrap());
println!("err: {}", String::from_utf8(out.stderr).unwrap());
assert!(out.status.success());
let after_hash = calc_hash(&bin);
assert_ne!(before_hash, after_hash);
});
}
#[test]
fn update_bad_schema() {
update_setup(&|config, self_dist| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
output_release_file(self_dist, "17", "1.1.1");
config.expect_err(&["rustup", "self", "update"], "unknown schema version");
});
}
#[test]
fn update_no_change() {
let version = env!("CARGO_PKG_VERSION");
update_setup(&|config, self_dist| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
output_release_file(self_dist, "1", version);
config.expect_ok_ex(
&["rustup", "self", "update"],
&format!(
r" rustup unchanged - {version}
"
),
r"info: checking for self-update
",
);
});
}
#[test]
fn rustup_self_updates_trivial() {
update_setup(&|config, _| {
config.expect_ok(&["rustup", "set", "auto-self-update", "enable"]);
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
let bin = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
let before_hash = calc_hash(&bin);
config.expect_ok(&["rustup", "update"]);
let after_hash = calc_hash(&bin);
assert_ne!(before_hash, after_hash);
})
}
#[test]
fn rustup_self_updates_with_specified_toolchain() {
update_setup(&|config, _| {
config.expect_ok(&["rustup", "set", "auto-self-update", "enable"]);
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
let bin = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
let before_hash = calc_hash(&bin);
config.expect_ok(&["rustup", "update", "stable"]);
let after_hash = calc_hash(&bin);
assert_ne!(before_hash, after_hash);
})
}
#[test]
fn rustup_no_self_update_with_specified_toolchain() {
update_setup(&|config, _| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
let bin = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
let before_hash = calc_hash(&bin);
config.expect_ok(&["rustup", "update", "stable"]);
let after_hash = calc_hash(&bin);
assert_eq!(before_hash, after_hash);
})
}
#[test]
fn rustup_self_update_exact() {
update_setup(&|config, _| {
config.expect_ok(&["rustup", "set", "auto-self-update", "enable"]);
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_ok_ex(
&["rustup", "update"],
for_host!(
r"
stable-{0} unchanged - 1.1.0 (hash-stable-1.1.0)
"
),
for_host!(
r"info: syncing channel updates for 'stable-{0}'
info: checking for self-update
info: downloading self-update
info: cleaning up downloads & tmp directories
"
),
);
})
}
// Because self-delete on windows is hard, rustup-init doesn't
// do it. It instead leaves itself installed for cleanup by later
// invocations of rustup.
#[test]
fn updater_leaves_itself_for_later_deletion() {
update_setup(&|config, _| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_ok(&["rustup", "update", "nightly"]);
config.expect_ok(&["rustup", "self", "update"]);
let setup = config.cargodir.join(format!("bin/rustup-init{EXE_SUFFIX}"));
assert!(setup.exists());
});
}
#[test]
fn updater_is_deleted_after_running_rustup() {
update_setup(&|config, _| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_ok(&["rustup", "update", "nightly"]);
config.expect_ok(&["rustup", "self", "update"]);
config.expect_ok(&["rustup", "update", "nightly"]);
let setup = config.cargodir.join(format!("bin/rustup-init{EXE_SUFFIX}"));
assert!(!setup.exists());
});
}
#[test]
fn updater_is_deleted_after_running_rustc() {
update_setup(&|config, _| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_ok(&["rustup", "default", "nightly"]);
config.expect_ok(&["rustup", "self", "update"]);
config.expect_ok(&["rustc", "--version"]);
let setup = config.cargodir.join(format!("bin/rustup-init{EXE_SUFFIX}"));
assert!(!setup.exists());
});
}
#[test]
fn rustup_still_works_after_update() {
update_setup(&|config, _| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_ok(&["rustup", "default", "nightly"]);
config.expect_ok(&["rustup", "self", "update"]);
config.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2");
config.expect_ok(&["rustup", "default", "beta"]);
config.expect_stdout_ok(&["rustc", "--version"], "hash-beta-1.2.0");
});
}
// The installer used to be called rustup-setup. For compatibility it
// still needs to work in that mode.
#[test]
fn as_rustup_setup() {
clitools::test(Scenario::Empty, &|config| {
let init = config.exedir.join(format!("rustup-init{EXE_SUFFIX}"));
let setup = config.exedir.join(format!("rustup-setup{EXE_SUFFIX}"));
fs::copy(init, setup).unwrap();
config.expect_ok(&[
"rustup-setup",
"-y",
"--no-modify-path",
"--default-toolchain",
"none",
]);
});
}
#[test]
fn reinstall_exact() {
setup_empty_installed(&|config| {
config.expect_stderr_ok(
&[
"rustup-init",
"-y",
"--no-update-default-toolchain",
"--no-modify-path",
],
r"info: updating existing rustup installation - leaving toolchains alone",
);
});
}
#[test]
fn reinstall_specifying_toolchain() {
setup_installed(&|config| {
config.expect_stdout_ok(
&[
"rustup-init",
"-y",
"--default-toolchain=stable",
"--no-modify-path",
],
for_host!(r"stable-{0} unchanged - 1.1.0"),
);
});
}
#[test]
fn reinstall_specifying_component() {
setup_installed(&|config| {
config.expect_ok(&["rustup", "component", "add", "rls"]);
config.expect_stdout_ok(
&[
"rustup-init",
"-y",
"--default-toolchain=stable",
"--no-modify-path",
],
for_host!(r"stable-{0} unchanged - 1.1.0"),
);
});
}
#[test]
fn reinstall_specifying_different_toolchain() {
clitools::test(Scenario::SimpleV2, &|config| {
config.expect_stderr_ok(
&[
"rustup-init",
"-y",
"--default-toolchain=nightly",
"--no-modify-path",
],
for_host!(r"info: default toolchain set to 'nightly-{0}'"),
);
});
}
#[test]
fn install_sets_up_stable_unless_a_different_default_is_requested() {
clitools::test(Scenario::SimpleV2, &|config| {
config.expect_ok(&[
"rustup-init",
"-y",
"--default-toolchain",
"nightly",
"--no-modify-path",
]);
config.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2");
});
}
#[test]
fn install_sets_up_stable_unless_there_is_already_a_default() {
setup_installed(&|config| {
config.expect_ok(&["rustup", "default", "nightly"]);
config.expect_ok(&["rustup", "toolchain", "remove", "stable"]);
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2");
config.expect_err(
&["rustup", "run", "stable", "rustc", "--version"],
for_host!("toolchain 'stable-{0}' is not installed"),
);
});
}
#[test]
fn readline_no_stdin() {
clitools::test(Scenario::SimpleV2, &|config| {
config.expect_err(
&["rustup-init", "--no-modify-path"],
"unable to read from stdin for confirmation",
);
});
}
#[test]
fn rustup_init_works_with_weird_names() {
// Browsers often rename bins to e.g. rustup-init(2).exe.
clitools::test(Scenario::SimpleV2, &|config| {
let old = config.exedir.join(format!("rustup-init{EXE_SUFFIX}"));
let new = config.exedir.join(format!("rustup-init(2){EXE_SUFFIX}"));
fs::rename(old, new).unwrap();
config.expect_ok(&["rustup-init(2)", "-y", "--no-modify-path"]);
let rustup = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));
assert!(rustup.exists());
});
}
#[test]
fn install_but_rustup_sh_is_installed() {
clitools::test(Scenario::Empty, &|config| {
config.create_rustup_sh_metadata();
config.expect_stderr_ok(
&[
"rustup-init",
"-y",
"--default-toolchain",
"none",
"--no-modify-path",
],
"cannot install while rustup.sh is installed",
);
});
}
#[test]
fn test_warn_succeed_if_rustup_sh_already_installed_y_flag() {
clitools::test(Scenario::SimpleV2, &|config| {
config.create_rustup_sh_metadata();
let out = config.run("rustup-init", ["-y", "--no-modify-path"], &[]);
assert!(out.ok);
assert!(out
.stderr
.contains("warning: it looks like you have existing rustup.sh metadata"));
assert!(out
.stderr
.contains("error: cannot install while rustup.sh is installed"));
assert!(out.stderr.contains(
"warning: continuing (because the -y flag is set and the error is ignorable)"
));
assert!(!out.stdout.contains("Continue? (y/N)"));
})
}
#[test]
fn test_succeed_if_rustup_sh_already_installed_env_var_set() {
clitools::test(Scenario::SimpleV2, &|config| {
config.create_rustup_sh_metadata();
let out = config.run(
"rustup-init",
["-y", "--no-modify-path"],
&[("RUSTUP_INIT_SKIP_EXISTENCE_CHECKS", "yes")],
);
assert!(out.ok);
assert!(!out
.stderr
.contains("warning: it looks like you have existing rustup.sh metadata"));
assert!(!out
.stderr
.contains("error: cannot install while rustup.sh is installed"));
assert!(!out.stderr.contains(
"warning: continuing (because the -y flag is set and the error is ignorable)"
));
assert!(!out.stdout.contains("Continue? (y/N)"));
})
}
#[test]
fn rls_proxy_set_up_after_install() {
clitools::test(Scenario::None, &|config| {
config.with_scenario(Scenario::SimpleV2, &|config| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
});
config.expect_err(
&["rls", "--version"],
&format!(
"'rls{}' is not installed for the toolchain 'stable-{}'",
EXE_SUFFIX,
this_host_triple(),
),
);
config.expect_ok(&["rustup", "component", "add", "rls"]);
config.expect_ok(&["rls", "--version"]);
});
}
#[test]
fn rls_proxy_set_up_after_update() {
update_setup(&|config, _| {
let rls_path = config.cargodir.join(format!("bin/rls{EXE_SUFFIX}"));
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
fs::remove_file(&rls_path).unwrap();
config.expect_ok(&["rustup", "self", "update"]);
assert!(rls_path.exists());
});
}
#[test]
fn update_does_not_overwrite_rustfmt() {
update_setup(&|config, self_dist| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
let version = env!("CARGO_PKG_VERSION");
output_release_file(self_dist, "1", version);
// Since we just did a fresh install rustfmt will exist. Let's emulate
// it not existing in this test though by removing it just after our
// installation.
let rustfmt_path = config.cargodir.join(format!("bin/rustfmt{EXE_SUFFIX}"));
assert!(rustfmt_path.exists());
fs::remove_file(&rustfmt_path).unwrap();
raw::write_file(&rustfmt_path, "").unwrap();
assert_eq!(utils::file_size(&rustfmt_path).unwrap(), 0);
// Ok, now a self-update should complain about `rustfmt` not looking
// like rustup and the user should take some action.
config.expect_stderr_ok(
&["rustup", "self", "update"],
"`rustfmt` is already installed",
);
assert!(rustfmt_path.exists());
assert_eq!(utils::file_size(&rustfmt_path).unwrap(), 0);
// Now simulate us removing the rustfmt executable and rerunning a self
// update, this should install the rustup shim. Note that we don't run
// `rustup` here but rather the rustup we've actually installed, this'll
// help reproduce bugs related to having that file being opened by the
// current process.
fs::remove_file(&rustfmt_path).unwrap();
let installed_rustup = config.cargodir.join("bin/rustup");
config.expect_ok(&[installed_rustup.to_str().unwrap(), "self", "update"]);
assert!(rustfmt_path.exists());
assert!(utils::file_size(&rustfmt_path).unwrap() > 0);
});
}
#[test]
fn update_installs_clippy_cargo_and() {
update_setup(&|config, self_dist| {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
let version = env!("CARGO_PKG_VERSION");
output_release_file(self_dist, "1", version);
let cargo_clippy_path = config
.cargodir
.join(format!("bin/cargo-clippy{EXE_SUFFIX}"));
assert!(cargo_clippy_path.exists());
});
}
#[test]
fn install_with_components_and_targets() {
clitools::test(Scenario::SimpleV2, &|config| {
config.expect_ok(&[
"rustup-init",
"--default-toolchain",
"nightly",
"-y",
"-c",
"rls",
"-t",
clitools::CROSS_ARCH1,
"--no-modify-path",
]);
config.expect_stdout_ok(
&["rustup", "target", "list"],
&format!("{} (installed)", clitools::CROSS_ARCH1),
);
config.expect_stdout_ok(
&["rustup", "component", "list"],
&format!("rls-{} (installed)", this_host_triple()),
);
})
}
#[test]
fn install_minimal_profile() {
clitools::test(Scenario::SimpleV2, &|config| {
config.expect_ok(&[
"rustup-init",
"-y",
"--profile",
"minimal",
"--no-modify-path",
]);
config.expect_component_executable("rustup");
config.expect_component_executable("rustc");
config.expect_component_not_executable("cargo");
});
}
|