Skip to content

Commit

Permalink
Merge pull request #3209 from hi-rustin/rustin-patch-rust-init-sh-ui
Browse files Browse the repository at this point in the history
Add ui test for the rustup-init.sh
  • Loading branch information
Rustin170506 authored Feb 19, 2023
2 parents 7659519 00c930f commit 26fea62
Show file tree
Hide file tree
Showing 48 changed files with 93 additions and 20 deletions.
24 changes: 13 additions & 11 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 22,30 @@ set -u
# If RUSTUP_UPDATE_ROOT is unset or empty, default it.
RUSTUP_UPDATE_ROOT="${RUSTUP_UPDATE_ROOT:-https://static.rust-lang.org/rustup}"

#XXX: If you change anything here, please make the same changes in setup_mode.rs
# NOTICE: If you change anything here, please make the same changes in setup_mode.rs
usage() {
cat 1>&2 <<EOF
cat <<EOF
rustup-init 1.25.2 (8c4dad73d 2023-02-01)
The installer for rustup
USAGE:
rustup-init [FLAGS] [OPTIONS]
FLAGS:
-v, --verbose Enable verbose output
-q, --quiet Disable progress output
-y Disable confirmation prompt.
--no-modify-path Don't configure the PATH environment variable
-h, --help Prints help information
-V, --version Prints version information
-v, --verbose Enable verbose output
-q, --quiet Disable progress output
-y Disable confirmation prompt.
--no-update-default-toolchain Don't update any existing default toolchain after install
--no-modify-path Don't configure the PATH environment variable
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--default-host <default-host> Choose a default host triple
--default-toolchain <default-toolchain> Choose a default toolchain to install
--default-toolchain none Do not install any toolchains
--profile [minimal|default|complete] Choose a profile
--default-toolchain <default-toolchain>
Choose a default toolchain to install. Use 'none' to not install any toolchains at all
--profile <profile> [default: default] [possible values: minimal, default, complete]
-c, --component <components>... Component name to also install
-t, --target <targets>... Target name to also install
EOF
Expand Down
4 changes: 2 additions & 2 deletions src/cli/setup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,7 @@ pub fn main() -> Result<utils::ExitCode> {
return Ok(utils::ExitCode(0));
}

// XXX: If you change anything here, please make the same changes in rustup-init.sh
// NOTICE: If you change anything here, please make the same changes in rustup-init.sh.
let cli = App::new("rustup-init")
.version(common::version())
.about("The installer for rustup")
Expand Down Expand Up @@ -55,7 55,7 @@ pub fn main() -> Result<utils::ExitCode> {
Arg::with_name("default-toolchain")
.long("default-toolchain")
.takes_value(true)
.help("Choose a default toolchain to install"),
.help("Choose a default toolchain to install. Use 'none' to not install any toolchains at all"),
)
.arg(
Arg::with_name("profile")
Expand Down
52 changes: 46 additions & 6 deletions tests/cli-ui.rs
Original file line number Diff line number Diff line change
@@ -1,18 1,58 @@
use std::fs;
use std::{fs, path::PathBuf};

#[test]
fn ui_doc_text_tests() {
fn rustup_ui_doc_text_tests() {
let t = trycmd::TestCases::new();
let rustup_init = trycmd::cargo::cargo_bin("rustup-init");
let rustup = trycmd::cargo::cargo_bin("rustup");
t.register_bin("rustup-init", &rustup_init);
// Copy rustup-init to rustup so that the tests can run it.
fs::copy(&rustup_init, &rustup).unwrap();
t.register_bin("rustup", &rustup);
t.case("tests/cli-ui/*.toml");
t.case("tests/cli-ui/rustup/*.toml");
#[cfg(target_os = "windows")]
{
// On windows, we don't have man command, so skip the tests.
t.skip("tests/cli-ui/rustup_man_cmd_help_flag_stdout.toml");
// On windows, we don't have man command, so skip the test.
t.skip("tests/cli-ui/rustup/rustup_man_cmd_help_flag_stdout.toml");
}
}

#[test]
fn rustup_init_ui_doc_text_tests() {
let t = trycmd::TestCases::new();
let rustup_init = trycmd::cargo::cargo_bin("rustup-init");
let project_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
t.register_bin("rustup-init", &rustup_init);
t.register_bin("rustup-init.sh", &project_root.join("rustup-init.sh"));
t.case("tests/cli-ui/rustup-init/*.toml");
#[cfg(target_os = "windows")]
{
// On non-windows, we don't use rustup-init.sh, so skip the test.
t.skip("tests/cli-ui/rustup-init/rustup-init_sh_help_flag_stdout.toml");
}

// On non-windows, we don't use rustup-init.sh, so skip the test.
#[cfg(not(target_os = "windows"))]
{
let rustup_init_help_toml =
project_root.join("tests/cli-ui/rustup-init/rustup-init_help_flag_stdout.toml");
let rustup_init_sh_help_toml =
project_root.join("tests/cli-ui/rustup-init/rustup-init_sh_help_flag_stdout.toml");

#[derive(Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
struct Stdout {
#[serde(default)]
pub(crate) stdout: Option<String>,
}
let rustup_init_help_std_out: Stdout =
toml::from_str(fs::read_to_string(rustup_init_help_toml).unwrap().as_str()).unwrap();
let rustup_init_sh_help_std_out: Stdout = toml::from_str(
fs::read_to_string(rustup_init_sh_help_toml)
.unwrap()
.as_str(),
)
.unwrap();

// Make sure that the help output of rustup-init and rustup-init.sh are the same.
assert!(rustup_init_help_std_out == rustup_init_sh_help_std_out)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 19,9 @@ FLAGS:
OPTIONS:
--default-host <default-host> Choose a default host triple
--default-toolchain <default-toolchain> Choose a default toolchain to install
--default-toolchain <default-toolchain>
Choose a default toolchain to install. Use 'none' to not install any toolchains at all
--profile <profile> [default: default] [possible values: minimal, default, complete]
-c, --component <components>... Component name to also install
-t, --target <targets>... Target name to also install
Expand Down
29 changes: 29 additions & 0 deletions tests/cli-ui/rustup-init/rustup-init_sh_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 1,29 @@
bin.name = "rustup-init.sh"
args = ["--help"]
status.code = 0
stdout = """
rustup-init [..]
The installer for rustup
USAGE:
rustup-init[EXE] [FLAGS] [OPTIONS]
FLAGS:
-v, --verbose Enable verbose output
-q, --quiet Disable progress output
-y Disable confirmation prompt.
--no-update-default-toolchain Don't update any existing default toolchain after install
--no-modify-path Don't configure the PATH environment variable
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--default-host <default-host> Choose a default host triple
--default-toolchain <default-toolchain>
Choose a default toolchain to install. Use 'none' to not install any toolchains at all
--profile <profile> [default: default] [possible values: minimal, default, complete]
-c, --component <components>... Component name to also install
-t, --target <targets>... Target name to also install
"""
stderr = ""
File renamed without changes.
File renamed without changes.

0 comments on commit 26fea62

Please sign in to comment.