Skip to content

Add test for cli ui #3205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 271 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ url = "2.1"
wait-timeout = "0.2"
xz2 = "0.1.3"
zstd = "0.11"
trycmd = "0.14.11"

[dependencies.retry]
default-features = false
Expand Down
18 changes: 18 additions & 0 deletions tests/cli-ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::fs;

#[test]
fn ui_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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also export RUSTUP_FORCE_ARG0='rust', but the copy is fine.

t.register_bin("rustup", &rustup);
t.case("tests/cli-ui/*.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");
}
}
27 changes: 27 additions & 0 deletions tests/cli-ui/rustup-init_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
bin.name = "rustup-init"
args = ["--help"]
status.code = 0
stdout = """
rustup-init [..]
The installer for rustup

USAGE:
rustup-init[EXE] [FLAGS] [OPTIONS]

FLAGS:
-v, --verbose Enable verbose output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will be stable as clap evolves - we may want to do things like

--verbose[...] Enable verbose output : but we can do that if we need to, not right now ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. we can update it if we need to.
Thanks for your review! 💚 💙 💜 💛 ❤️

-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
--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 = ""
13 changes: 13 additions & 0 deletions tests/cli-ui/rustup_check_cmd_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
bin.name = "rustup"
args = ["check","--help"]
stdout = """
...
Check for updates to Rust toolchains and rustup

USAGE:
rustup[EXE] check

FLAGS:
-h, --help Prints help information
"""
stderr = ""
138 changes: 138 additions & 0 deletions tests/cli-ui/rustup_completions_cmd_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
bin.name = "rustup"
args = ["completions","--help"]
stdout = """
...
Generate tab-completion scripts for your shell

USAGE:
rustup[EXE] completions [ARGS]

FLAGS:
-h, --help Prints help information

ARGS:
<shell> [possible values: zsh, bash, fish, powershell, elvish]
<command> [possible values: rustup, cargo]

DISCUSSION:
Enable tab completion for Bash, Fish, Zsh, or PowerShell
The script is output on `stdout`, allowing one to re-direct the
output to the file of their choosing. Where you place the file
will depend on which shell, and which operating system you are
using. Your particular configuration may also determine where
these scripts need to be placed.

Here are some common set ups for the three supported shells under
Unix and similar operating systems (such as GNU/Linux).

BASH:

Completion files are commonly stored in `/etc/bash_completion.d/` for
system-wide commands, but can be stored in
`~/.local/share/bash-completion/completions` for user-specific commands.
Run the command:

$ mkdir -p ~/.local/share/bash-completion/completions
$ rustup completions bash >> ~/.local/share/bash-completion/completions/rustup

This installs the completion script. You may have to log out and
log back in to your shell session for the changes to take effect.

BASH (macOS/Homebrew):

Homebrew stores bash completion files within the Homebrew directory.
With the `bash-completion` brew formula installed, run the command:

$ mkdir -p $(brew --prefix)/etc/bash_completion.d
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion

FISH:

Fish completion files are commonly stored in
`$HOME/.config/fish/completions`. Run the command:

$ mkdir -p ~/.config/fish/completions
$ rustup completions fish > ~/.config/fish/completions/rustup.fish

This installs the completion script. You may have to log out and
log back in to your shell session for the changes to take effect.

ZSH:

ZSH completions are commonly stored in any directory listed in
your `$fpath` variable. To use these completions, you must either
add the generated script to one of those directories, or add your
own to this list.

Adding a custom directory is often the safest bet if you are
unsure of which directory to use. First create the directory; for
this example we'll create a hidden directory inside our `$HOME`
directory:

$ mkdir ~/.zfunc

Then add the following lines to your `.zshrc` just before
`compinit`:

fpath+=~/.zfunc

Now you can install the completions script using the following
command:

$ rustup completions zsh > ~/.zfunc/_rustup

You must then either log out and log back in, or simply run

$ exec zsh

for the new completions to take effect.

CUSTOM LOCATIONS:

Alternatively, you could save these files to the place of your
choosing, such as a custom directory inside your $HOME. Doing so
will require you to add the proper directives, such as `source`ing
inside your login script. Consult your shells documentation for
how to add such directives.

POWERSHELL:

The powershell completion scripts require PowerShell v5.0+ (which
comes with Windows 10, but can be downloaded separately for windows 7
or 8.1).

First, check if a profile has already been set

PS C:/> Test-Path $profile

If the above command returns `False` run the following

PS C:/> New-Item -path $profile -type file -force

Now open the file provided by `$profile` (if you used the
`New-Item` command it will be
`${env:USERPROFILE}/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1`

Next, we either save the completions file into our profile, or
into a separate file and source it inside our profile. To save the
completions into our profile simply use

PS C:/> rustup completions powershell >>
${env:USERPROFILE}/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1

CARGO:

Rustup can also generate a completion script for `cargo`. The script output
by `rustup` will source the completion script distributed with your default
toolchain. Not all shells are currently supported. Here are examples for
the currently supported shells.

BASH:

$ rustup completions bash cargo >> ~/.local/share/bash-completion/completions/cargo

ZSH:

$ rustup completions zsh cargo > ~/.zfunc/_cargo
"""
stderr = ""
21 changes: 21 additions & 0 deletions tests/cli-ui/rustup_component_cmd_add_cmd_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
bin.name = "rustup"
args = ["component","add","--help"]
stdout = """
...
Add a component to a Rust toolchain

USAGE:
rustup[EXE] component add [OPTIONS] <component>...

FLAGS:
-h, --help Prints help information

OPTIONS:
--target <target>
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`

ARGS:
<component>...
"""
stderr = ""
18 changes: 18 additions & 0 deletions tests/cli-ui/rustup_component_cmd_list_cmd_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bin.name = "rustup"
args = ["component","list","--help"]
stdout = """
...
List installed and available components

USAGE:
rustup[EXE] component list [FLAGS] [OPTIONS]

FLAGS:
-h, --help Prints help information
--installed List only installed components

OPTIONS:
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`
"""
stderr = ""
21 changes: 21 additions & 0 deletions tests/cli-ui/rustup_component_cmd_remove_cmd_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
bin.name = "rustup"
args = ["component","remove","--help"]
stdout = """
...
Remove a component from a Rust toolchain

USAGE:
rustup[EXE] component remove [OPTIONS] <component>...

FLAGS:
-h, --help Prints help information

OPTIONS:
--target <target>
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`

ARGS:
<component>...
"""
stderr = ""
21 changes: 21 additions & 0 deletions tests/cli-ui/rustup_default_cmd_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
bin.name = "rustup"
args = ["default","--help"]
stdout = """
...
Set the default toolchain

USAGE:
rustup[EXE] default [toolchain]

FLAGS:
-h, --help Prints help information

ARGS:
<toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see `rustup help
toolchain`

DISCUSSION:
Sets the default toolchain to the one specified. If the toolchain
is not already installed then it is installed first.
"""
stderr = ""
45 changes: 45 additions & 0 deletions tests/cli-ui/rustup_doc_cmd_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
bin.name = "rustup"
args = ["doc","--help"]
stdout = """
...
Open the documentation for the current toolchain

USAGE:
rustup[EXE] doc [FLAGS] [OPTIONS] [topic]

FLAGS:
--alloc The Rust core allocation and collections library
--book The Rust Programming Language book
--cargo The Cargo Book
--core The Rust Core Library
--edition-guide The Rust Edition Guide
--embedded-book The Embedded Rust Book
-h, --help Prints help information
--nomicon The Dark Arts of Advanced and Unsafe Rust Programming
--path Only print the path to the documentation
--proc_macro A support library for macro authors when defining new macros
--reference The Rust Reference
--rust-by-example A collection of runnable examples that illustrate various Rust concepts and standard
libraries
--rustc The compiler for the Rust programming language
--rustdoc Documentation generator for Rust projects
--std Standard library API documentation
--test Support code for rustc's built in unit-test and micro-benchmarking framework
--unstable-book The Unstable Book

OPTIONS:
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`

ARGS:
<topic> Topic such as 'core', 'fn', 'usize', 'eprintln!', 'core::arch', 'alloc::format!', 'std::fs',
'std::fs::read_dir', 'std::io::Bytes', 'std::iter::Sum', 'std::io::error::Result' etc...

DISCUSSION:
Opens the documentation for the currently active toolchain with
the default browser.

By default, it opens the documentation index. Use the various
flags to open specific pieces of documentation.
"""
stderr = ""
48 changes: 48 additions & 0 deletions tests/cli-ui/rustup_help_cmd_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
bin.name = "rustup"
args = ["help"]
status.code = 0
stdout = """
rustup [..]
The Rust toolchain installer

USAGE:
rustup[EXE] [FLAGS] [+toolchain] <SUBCOMMAND>

FLAGS:
-v, --verbose Enable verbose output
-q, --quiet Disable progress output
-h, --help Prints help information
-V, --version Prints version information

ARGS:
<+toolchain> release channel (e.g. +stable) or custom toolchain to set override

SUBCOMMANDS:
show Show the active and installed toolchains or profiles
update Update Rust toolchains and rustup
check Check for updates to Rust toolchains and rustup
default Set the default toolchain
toolchain Modify or query the installed toolchains
target Modify a toolchain's supported targets
component Modify a toolchain's installed components
override Modify directory toolchain overrides
run Run a command with an environment configured for a given toolchain
which Display which binary will be run for a given command
doc Open the documentation for the current toolchain
...
self Modify the rustup installation
set Alter rustup settings
completions Generate tab-completion scripts for your shell
help Prints this message or the help of the given subcommand(s)

DISCUSSION:
Rustup installs The Rust Programming Language from the official
release channels, enabling you to easily switch between stable,
beta, and nightly compilers and keep them updated. It makes
cross-compiling simpler with binary builds of the standard library
for common platforms.

If you are new to Rust consider running `rustup doc --book` to
learn Rust.
"""
stderr = ""
Loading