Skip to content

Commit cbadeef

Browse files
committed
Add ui test for the rustup-init.sh
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent 49023e1 commit cbadeef

File tree

48 files changed

+84
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+84
-17
lines changed

rustup-init.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ set -u
2222
# If RUSTUP_UPDATE_ROOT is unset or empty, default it.
2323
RUSTUP_UPDATE_ROOT="${RUSTUP_UPDATE_ROOT:-https://static.rust-lang.org/rustup}"
2424

25-
#XXX: If you change anything here, please make the same changes in setup_mode.rs
25+
# NOTICE: If you change anything here, please make the same changes in setup_mode.rs
2626
usage() {
27-
cat 1>&2 <<EOF
27+
cat <<EOF
2828
rustup-init 1.25.2 (8c4dad73d 2023-02-01)
2929
The installer for rustup
3030
3131
USAGE:
3232
rustup-init [FLAGS] [OPTIONS]
3333
3434
FLAGS:
35-
-v, --verbose Enable verbose output
36-
-q, --quiet Disable progress output
37-
-y Disable confirmation prompt.
38-
--no-modify-path Don't configure the PATH environment variable
39-
-h, --help Prints help information
40-
-V, --version Prints version information
35+
-v, --verbose Enable verbose output
36+
-q, --quiet Disable progress output
37+
-y Disable confirmation prompt.
38+
--no-update-default-toolchain Don't update any existing default toolchain after install
39+
--no-modify-path Don't configure the PATH environment variable
40+
-h, --help Prints help information
41+
-V, --version Prints version information
4142
4243
OPTIONS:
4344
--default-host <default-host> Choose a default host triple
4445
--default-toolchain <default-toolchain> Choose a default toolchain to install
45-
--default-toolchain none Do not install any toolchains
46-
--profile [minimal|default|complete] Choose a profile
46+
--profile <profile> [default: default] [possible values: minimal, default, complete]
4747
-c, --component <components>... Component name to also install
4848
-t, --target <targets>... Target name to also install
4949
EOF

src/cli/setup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn main() -> Result<utils::ExitCode> {
2222
return Ok(utils::ExitCode(0));
2323
}
2424

25-
// XXX: If you change anything here, please make the same changes in rustup-init.sh
25+
// NOTICE: If you change anything here, please make the same changes in rustup-init.sh.
2626
let cli = App::new("rustup-init")
2727
.version(common::version())
2828
.about("The installer for rustup")

tests/cli-ui.rs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,58 @@
1-
use std::fs;
1+
use std::{fs, path::PathBuf};
22

33
#[test]
4-
fn ui_doc_text_tests() {
4+
fn rustup_ui_doc_text_tests() {
55
let t = trycmd::TestCases::new();
66
let rustup_init = trycmd::cargo::cargo_bin("rustup-init");
77
let rustup = trycmd::cargo::cargo_bin("rustup");
8-
t.register_bin("rustup-init", &rustup_init);
98
// Copy rustup-init to rustup so that the tests can run it.
109
fs::copy(&rustup_init, &rustup).unwrap();
1110
t.register_bin("rustup", &rustup);
12-
t.case("tests/cli-ui/*.toml");
11+
t.case("tests/cli-ui/rustup/*.toml");
1312
#[cfg(target_os = "windows")]
1413
{
15-
// On windows, we don't have man command, so skip the tests.
16-
t.skip("tests/cli-ui/rustup_man_cmd_help_flag_stdout.toml");
14+
// On windows, we don't have man command, so skip the test.
15+
t.skip("tests/cli-ui/rustup/rustup_man_cmd_help_flag_stdout.toml");
16+
}
17+
}
18+
19+
#[test]
20+
fn rustup_init_ui_doc_text_tests() {
21+
let t = trycmd::TestCases::new();
22+
let rustup_init = trycmd::cargo::cargo_bin("rustup-init");
23+
let project_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
24+
t.register_bin("rustup-init", &rustup_init);
25+
t.register_bin("rustup-init.sh", &project_root.join("rustup-init.sh"));
26+
t.case("tests/cli-ui/rustup-init/*.toml");
27+
#[cfg(target_os = "windows")]
28+
{
29+
// On non-windows, we don't use rustup-init.sh, so skip the test.
30+
t.skip("tests/cli-ui/rustup-init/rustup-init_sh_help_flag_stdout.toml");
31+
}
32+
33+
// On non-windows, we don't use rustup-init.sh, so skip the test.
34+
#[cfg(not(target_os = "windows"))]
35+
{
36+
let rustup_init_help_toml =
37+
project_root.join("tests/cli-ui/rustup-init/rustup-init_help_flag_stdout.toml");
38+
let rustup_init_sh_help_toml =
39+
project_root.join("tests/cli-ui/rustup-init/rustup-init_sh_help_flag_stdout.toml");
40+
41+
#[derive(Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
42+
struct Stdout {
43+
#[serde(default)]
44+
pub(crate) stdout: Option<String>,
45+
}
46+
let rustup_init_help_std_out: Stdout =
47+
toml::from_str(fs::read_to_string(rustup_init_help_toml).unwrap().as_str()).unwrap();
48+
let rustup_init_sh_help_std_out: Stdout = toml::from_str(
49+
fs::read_to_string(rustup_init_sh_help_toml)
50+
.unwrap()
51+
.as_str(),
52+
)
53+
.unwrap();
54+
55+
// Make sure that the help output of rustup-init and rustup-init.sh are the same.
56+
assert!(rustup_init_help_std_out == rustup_init_sh_help_std_out)
1757
}
1858
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
bin.name = "rustup-init.sh"
2+
args = ["--help"]
3+
status.code = 0
4+
stdout = """
5+
rustup-init [..]
6+
The installer for rustup
7+
8+
USAGE:
9+
rustup-init[EXE] [FLAGS] [OPTIONS]
10+
11+
FLAGS:
12+
-v, --verbose Enable verbose output
13+
-q, --quiet Disable progress output
14+
-y Disable confirmation prompt.
15+
--no-update-default-toolchain Don't update any existing default toolchain after install
16+
--no-modify-path Don't configure the PATH environment variable
17+
-h, --help Prints help information
18+
-V, --version Prints version information
19+
20+
OPTIONS:
21+
--default-host <default-host> Choose a default host triple
22+
--default-toolchain <default-toolchain> Choose a default toolchain to install
23+
--profile <profile> [default: default] [possible values: minimal, default, complete]
24+
-c, --component <components>... Component name to also install
25+
-t, --target <targets>... Target name to also install
26+
"""
27+
stderr = ""

0 commit comments

Comments
 (0)