Skip to content

Commit 8bf8c7f

Browse files
committed
Add test for cli ui
Signed-off-by: hi-rustin <[email protected]>
1 parent 80cbc43 commit 8bf8c7f

File tree

46 files changed

+1384
-6
lines changed

Some content is hidden

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

46 files changed

+1384
-6
lines changed

Cargo.lock

+271-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ url = "2.1"
6666
wait-timeout = "0.2"
6767
xz2 = "0.1.3"
6868
zstd = "0.11"
69+
trycmd = "0.14.11"
6970

7071
[dependencies.retry]
7172
default-features = false

src/utils/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ where
341341
})
342342
}
343343

344-
pub(crate) fn copy_file(src: &Path, dest: &Path) -> Result<()> {
344+
pub fn copy_file(src: &Path, dest: &Path) -> Result<()> {
345345
let metadata = fs::symlink_metadata(src).with_context(|| RustupError::ReadingFile {
346346
name: "metadata for",
347347
path: PathBuf::from(src),

tests/cli-ui.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use rustup::utils::utils;
2+
3+
#[test]
4+
fn ui_tests() {
5+
let t = trycmd::TestCases::new();
6+
let rustup_init = trycmd::cargo::cargo_bin("rustup-init");
7+
let rustup = trycmd::cargo::cargo_bin("rustup");
8+
t.register_bin("rustup-init", &rustup_init);
9+
// Copy rustup-init to rustup so that the tests can run it.
10+
utils::copy_file(&rustup_init, &rustup).unwrap();
11+
t.register_bin("rustup", &rustup);
12+
t.case("tests/cli-ui/*.toml");
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
bin.name = "rustup-init"
2+
args = ["--help"]
3+
status.code = 0
4+
stdout = """
5+
rustup-init [..]
6+
The installer for rustup
7+
8+
USAGE:
9+
rustup-init [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 = ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bin.name = "rustup"
2+
args = ["check","--help"]
3+
stdout = """
4+
rustup-check
5+
Check for updates to Rust toolchains and rustup
6+
7+
USAGE:
8+
rustup check
9+
10+
FLAGS:
11+
-h, --help Prints help information
12+
"""
13+
stderr = ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
bin.name = "rustup"
2+
args = ["completions","--help"]
3+
stdout = """
4+
rustup-completions
5+
Generate tab-completion scripts for your shell
6+
7+
USAGE:
8+
rustup completions [ARGS]
9+
10+
FLAGS:
11+
-h, --help Prints help information
12+
13+
ARGS:
14+
<shell> [possible values: zsh, bash, fish, powershell, elvish]
15+
<command> [possible values: rustup, cargo]
16+
17+
DISCUSSION:
18+
Enable tab completion for Bash, Fish, Zsh, or PowerShell
19+
The script is output on `stdout`, allowing one to re-direct the
20+
output to the file of their choosing. Where you place the file
21+
will depend on which shell, and which operating system you are
22+
using. Your particular configuration may also determine where
23+
these scripts need to be placed.
24+
25+
Here are some common set ups for the three supported shells under
26+
Unix and similar operating systems (such as GNU/Linux).
27+
28+
BASH:
29+
30+
Completion files are commonly stored in `/etc/bash_completion.d/` for
31+
system-wide commands, but can be stored in
32+
`~/.local/share/bash-completion/completions` for user-specific commands.
33+
Run the command:
34+
35+
$ mkdir -p ~/.local/share/bash-completion/completions
36+
$ rustup completions bash >> ~/.local/share/bash-completion/completions/rustup
37+
38+
This installs the completion script. You may have to log out and
39+
log back in to your shell session for the changes to take effect.
40+
41+
BASH (macOS/Homebrew):
42+
43+
Homebrew stores bash completion files within the Homebrew directory.
44+
With the `bash-completion` brew formula installed, run the command:
45+
46+
$ mkdir -p $(brew --prefix)/etc/bash_completion.d
47+
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
48+
49+
FISH:
50+
51+
Fish completion files are commonly stored in
52+
`$HOME/.config/fish/completions`. Run the command:
53+
54+
$ mkdir -p ~/.config/fish/completions
55+
$ rustup completions fish > ~/.config/fish/completions/rustup.fish
56+
57+
This installs the completion script. You may have to log out and
58+
log back in to your shell session for the changes to take effect.
59+
60+
ZSH:
61+
62+
ZSH completions are commonly stored in any directory listed in
63+
your `$fpath` variable. To use these completions, you must either
64+
add the generated script to one of those directories, or add your
65+
own to this list.
66+
67+
Adding a custom directory is often the safest bet if you are
68+
unsure of which directory to use. First create the directory; for
69+
this example we'll create a hidden directory inside our `$HOME`
70+
directory:
71+
72+
$ mkdir ~/.zfunc
73+
74+
Then add the following lines to your `.zshrc` just before
75+
`compinit`:
76+
77+
fpath+=~/.zfunc
78+
79+
Now you can install the completions script using the following
80+
command:
81+
82+
$ rustup completions zsh > ~/.zfunc/_rustup
83+
84+
You must then either log out and log back in, or simply run
85+
86+
$ exec zsh
87+
88+
for the new completions to take effect.
89+
90+
CUSTOM LOCATIONS:
91+
92+
Alternatively, you could save these files to the place of your
93+
choosing, such as a custom directory inside your $HOME. Doing so
94+
will require you to add the proper directives, such as `source`ing
95+
inside your login script. Consult your shells documentation for
96+
how to add such directives.
97+
98+
POWERSHELL:
99+
100+
The powershell completion scripts require PowerShell v5.0+ (which
101+
comes with Windows 10, but can be downloaded separately for windows 7
102+
or 8.1).
103+
104+
First, check if a profile has already been set
105+
106+
PS C:/> Test-Path $profile
107+
108+
If the above command returns `False` run the following
109+
110+
PS C:/> New-Item -path $profile -type file -force
111+
112+
Now open the file provided by `$profile` (if you used the
113+
`New-Item` command it will be
114+
`${env:USERPROFILE}/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1`
115+
116+
Next, we either save the completions file into our profile, or
117+
into a separate file and source it inside our profile. To save the
118+
completions into our profile simply use
119+
120+
PS C:/> rustup completions powershell >>
121+
${env:USERPROFILE}/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1
122+
123+
CARGO:
124+
125+
Rustup can also generate a completion script for `cargo`. The script output
126+
by `rustup` will source the completion script distributed with your default
127+
toolchain. Not all shells are currently supported. Here are examples for
128+
the currently supported shells.
129+
130+
BASH:
131+
132+
$ rustup completions bash cargo >> ~/.local/share/bash-completion/completions/cargo
133+
134+
ZSH:
135+
136+
$ rustup completions zsh cargo > ~/.zfunc/_cargo
137+
"""
138+
stderr = ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bin.name = "rustup"
2+
args = ["component","add","--help"]
3+
stdout = """
4+
rustup-component-add
5+
Add a component to a Rust toolchain
6+
7+
USAGE:
8+
rustup component add [OPTIONS] <component>...
9+
10+
FLAGS:
11+
-h, --help Prints help information
12+
13+
OPTIONS:
14+
--target <target>
15+
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
16+
`rustup help toolchain`
17+
18+
ARGS:
19+
<component>...
20+
"""
21+
stderr = ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
bin.name = "rustup"
2+
args = ["component","list","--help"]
3+
stdout = """
4+
rustup-component-list
5+
List installed and available components
6+
7+
USAGE:
8+
rustup component list [FLAGS] [OPTIONS]
9+
10+
FLAGS:
11+
-h, --help Prints help information
12+
--installed List only installed components
13+
14+
OPTIONS:
15+
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
16+
`rustup help toolchain`
17+
"""
18+
stderr = ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bin.name = "rustup"
2+
args = ["component","remove","--help"]
3+
stdout = """
4+
rustup-component-remove
5+
Remove a component from a Rust toolchain
6+
7+
USAGE:
8+
rustup component remove [OPTIONS] <component>...
9+
10+
FLAGS:
11+
-h, --help Prints help information
12+
13+
OPTIONS:
14+
--target <target>
15+
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
16+
`rustup help toolchain`
17+
18+
ARGS:
19+
<component>...
20+
"""
21+
stderr = ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bin.name = "rustup"
2+
args = ["default","--help"]
3+
stdout = """
4+
rustup-default
5+
Set the default toolchain
6+
7+
USAGE:
8+
rustup default [toolchain]
9+
10+
FLAGS:
11+
-h, --help Prints help information
12+
13+
ARGS:
14+
<toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see `rustup help
15+
toolchain`
16+
17+
DISCUSSION:
18+
Sets the default toolchain to the one specified. If the toolchain
19+
is not already installed then it is installed first.
20+
"""
21+
stderr = ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
bin.name = "rustup"
2+
args = ["doc","--help"]
3+
stdout = """
4+
rustup-doc
5+
Open the documentation for the current toolchain
6+
7+
USAGE:
8+
rustup doc [FLAGS] [OPTIONS] [topic]
9+
10+
FLAGS:
11+
--alloc The Rust core allocation and collections library
12+
--book The Rust Programming Language book
13+
--cargo The Cargo Book
14+
--core The Rust Core Library
15+
--edition-guide The Rust Edition Guide
16+
--embedded-book The Embedded Rust Book
17+
-h, --help Prints help information
18+
--nomicon The Dark Arts of Advanced and Unsafe Rust Programming
19+
--path Only print the path to the documentation
20+
--proc_macro A support library for macro authors when defining new macros
21+
--reference The Rust Reference
22+
--rust-by-example A collection of runnable examples that illustrate various Rust concepts and standard
23+
libraries
24+
--rustc The compiler for the Rust programming language
25+
--rustdoc Documentation generator for Rust projects
26+
--std Standard library API documentation
27+
--test Support code for rustc's built in unit-test and micro-benchmarking framework
28+
--unstable-book The Unstable Book
29+
30+
OPTIONS:
31+
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
32+
`rustup help toolchain`
33+
34+
ARGS:
35+
<topic> Topic such as 'core', 'fn', 'usize', 'eprintln!', 'core::arch', 'alloc::format!', 'std::fs',
36+
'std::fs::read_dir', 'std::io::Bytes', 'std::iter::Sum', 'std::io::error::Result' etc...
37+
38+
DISCUSSION:
39+
Opens the documentation for the currently active toolchain with
40+
the default browser.
41+
42+
By default, it opens the documentation index. Use the various
43+
flags to open specific pieces of documentation.
44+
"""
45+
stderr = ""
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
bin.name = "rustup"
2+
args = ["help"]
3+
status.code = 0
4+
stdout = """
5+
rustup [..]
6+
The Rust toolchain installer
7+
8+
USAGE:
9+
rustup [FLAGS] [+toolchain] <SUBCOMMAND>
10+
11+
FLAGS:
12+
-v, --verbose Enable verbose output
13+
-q, --quiet Disable progress output
14+
-h, --help Prints help information
15+
-V, --version Prints version information
16+
17+
ARGS:
18+
<+toolchain> release channel (e.g. +stable) or custom toolchain to set override
19+
20+
SUBCOMMANDS:
21+
show Show the active and installed toolchains or profiles
22+
update Update Rust toolchains and rustup
23+
check Check for updates to Rust toolchains and rustup
24+
default Set the default toolchain
25+
toolchain Modify or query the installed toolchains
26+
target Modify a toolchain's supported targets
27+
component Modify a toolchain's installed components
28+
override Modify directory toolchain overrides
29+
run Run a command with an environment configured for a given toolchain
30+
which Display which binary will be run for a given command
31+
doc Open the documentation for the current toolchain
32+
man View the man page for a given command
33+
self Modify the rustup installation
34+
set Alter rustup settings
35+
completions Generate tab-completion scripts for your shell
36+
help Prints this message or the help of the given subcommand(s)
37+
38+
DISCUSSION:
39+
Rustup installs The Rust Programming Language from the official
40+
release channels, enabling you to easily switch between stable,
41+
beta, and nightly compilers and keep them updated. It makes
42+
cross-compiling simpler with binary builds of the standard library
43+
for common platforms.
44+
45+
If you are new to Rust consider running `rustup doc --book` to
46+
learn Rust.
47+
"""
48+
stderr = ""

0 commit comments

Comments
 (0)