Skip to content
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

test(cli): Track --help output #11912

Merged
merged 1 commit into from
Jul 25, 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
12 changes: 12 additions & 0 deletions tests/testsuite/cargo/help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use cargo_test_support::curr_dir;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, is there a reason curr_dir is not in cargo_test_support::prelude?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really. I can add it if wanted.

Copy link
Contributor

Choose a reason for hiding this comment

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

That might help with some of the boilerplate. It looks like it is used for essentially every UI test. This is unrelated to this PR, though, and can be done any time.

use cargo_test_support::prelude::*;

#[cargo_test]
fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("--help")
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Empty file.
39 changes: 39 additions & 0 deletions tests/testsuite/cargo/help/stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Rust's package manager

Usage: cargo [+toolchain] [OPTIONS] [COMMAND]
cargo [+toolchain] [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]...

Options:
-h, --help Print help
-V, --version Print version info and exit
--list List installed commands
--explain <CODE> Run `rustc --explain CODE`
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet Do not print cargo log messages
--color <WHEN> Coloring: auto, always, never
-C <DIRECTORY> Change to DIRECTORY before doing anything (nightly-only)
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
--offline Run without accessing the network
--config <KEY=VALUE> Override a configuration value
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details

Some common cargo commands are (see all commands with --list):
build, b Compile the current package
check, c Analyze the current package and report errors, but don't build object files
clean Remove the target directory
doc, d Build this package's and its dependencies' documentation
new Create a new cargo package
init Create a new cargo package in an existing directory
add Add dependencies to a manifest file
remove Remove dependencies from a manifest file
run, r Run a binary or example of the local package
test, t Run the tests
bench Run the benchmarks
update Update dependencies listed in Cargo.lock
search Search registry for crates
publish Package and upload this package to the registry
install Install a Rust binary. Default location is $HOME/.cargo/bin
uninstall Uninstall a Rust binary

See 'cargo help <command>' for more information on a specific command.
1 change: 1 addition & 0 deletions tests/testsuite/cargo/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod help;
13 changes: 13 additions & 0 deletions tests/testsuite/cargo_add/help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;

#[cargo_test]
fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg("--help")
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Empty file.
122 changes: 122 additions & 0 deletions tests/testsuite/cargo_add/help/stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Add dependencies to a Cargo.toml manifest file

Usage: cargo add [OPTIONS] <DEP>[@<VERSION>] ...
cargo add [OPTIONS] --path <PATH> ...
cargo add [OPTIONS] --git <URL> ...

Arguments:
[DEP_ID]...
Reference to a package to add as a dependency

You can reference a package by:
- `<name>`, like `cargo add serde` (latest version will be used)
- `<name>@<version-req>`, like `cargo add serde@1` or `cargo add serde@=1.0.38`

Options:
--no-default-features
Disable the default features

--default-features
Re-enable the default features

-F, --features <FEATURES>
Space or comma separated list of features to activate

--optional
Mark the dependency as optional

The package name will be exposed as feature of your crate.

--no-optional
Mark the dependency as required

The package will be removed from your features.

--rename <NAME>
Rename the dependency

Example uses:
- Depending on multiple versions of a crate
- Depend on crates with the same name from different registries

--ignore-rust-version
Ignore `rust-version` specification in packages (unstable)

--manifest-path <PATH>
Path to Cargo.toml

-p, --package [<SPEC>]
Package to modify

-q, --quiet
Do not print cargo log messages

--dry-run
Don't actually write the manifest

-h, --help
Print help (see a summary with '-h')

-v, --verbose...
Use verbose output (-vv very verbose/build.rs output)

--color <WHEN>
Coloring: auto, always, never

--frozen
Require Cargo.lock and cache are up to date

--locked
Require Cargo.lock is up to date

--offline
Run without accessing the network

--config <KEY=VALUE>
Override a configuration value

-Z <FLAG>
Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details

Source:
--path <PATH>
Filesystem path to local crate to add

--git <URI>
Git repository location

Without any other information, cargo will use latest commit on the main branch.

--branch <BRANCH>
Git branch to download the crate from

--tag <TAG>
Git tag to download the crate from

--rev <REV>
Git reference to download the crate from

This is the catch all, handling hashes to named references in remote repositories.

--registry <NAME>
Package registry for this dependency

Section:
--dev
Add as development dependency

Dev-dependencies are not used when compiling a package for building, but are used for
compiling tests, examples, and benchmarks.

These dependencies are not propagated to other packages which depend on this package.

--build
Add as build dependency

Build-dependencies are the only dependencies available for use by build scripts
(`build.rs` files).

--target <TARGET>
Add as dependency to the given target platform

Run `cargo help add` for more detailed information.
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod git_normalized_name;
mod git_registry;
mod git_rev;
mod git_tag;
mod help;
mod infer_prerelease;
mod invalid_arg;
mod invalid_git_name;
Expand Down
13 changes: 13 additions & 0 deletions tests/testsuite/cargo_bench/help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;

#[cargo_test]
fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("bench")
.arg("--help")
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Empty file.
50 changes: 50 additions & 0 deletions tests/testsuite/cargo_bench/help/stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Execute all benchmarks of a local package

Usage: cargo[EXE] bench [OPTIONS] [BENCHNAME] [-- [args]...]

Arguments:
[BENCHNAME] If specified, only run benches containing this string in their names
[args]... Arguments for the bench binary

Options:
-q, --quiet Do not print cargo log messages
--lib Benchmark only this package's library
--bins Benchmark all binaries
--bin [<NAME>] Benchmark only the specified binary
--examples Benchmark all examples
--example [<NAME>] Benchmark only the specified example
--tests Benchmark all tests
--test [<NAME>] Benchmark only the specified test target
--benches Benchmark all benches
--bench [<NAME>] Benchmark only the specified bench target
--all-targets Benchmark all targets
--no-run Compile, but don't run benchmarks
-p, --package [<SPEC>] Package to run benchmarks for
--workspace Benchmark all packages in the workspace
--exclude <SPEC> Exclude packages from the benchmark
--all Alias for --workspace (deprecated)
-j, --jobs <N> Number of parallel jobs, defaults to # of CPUs.
--keep-going Do not abort the build as soon as there is an error (unstable)
--profile <PROFILE-NAME> Build artifacts with the specified profile
-F, --features <FEATURES> Space or comma separated list of features to activate
--all-features Activate all available features
--no-default-features Do not activate the `default` feature
--target <TRIPLE> Build for the target triple
--target-dir <DIRECTORY> Directory for all generated artifacts
--manifest-path <PATH> Path to Cargo.toml
--ignore-rust-version Ignore `rust-version` specification in packages
--message-format <FMT> Error format
--no-fail-fast Run all benchmarks regardless of failure
--unit-graph Output build graph in JSON (unstable)
--timings[=<FMTS>] Timing output formats (unstable) (comma separated): html, json
-h, --help Print help
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
--offline Run without accessing the network
--config <KEY=VALUE> Override a configuration value
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for
details

Run `cargo help bench` for more detailed information.
1 change: 1 addition & 0 deletions tests/testsuite/cargo_bench/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod help;
13 changes: 13 additions & 0 deletions tests/testsuite/cargo_build/help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;

#[cargo_test]
fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("build")
.arg("--help")
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Empty file.
48 changes: 48 additions & 0 deletions tests/testsuite/cargo_build/help/stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Compile a local package and all of its dependencies

Usage: cargo[EXE] build [OPTIONS]

Options:
-q, --quiet Do not print cargo log messages
-p, --package [<SPEC>] Package to build (see `cargo help pkgid`)
--workspace Build all packages in the workspace
--exclude <SPEC> Exclude packages from the build
--all Alias for --workspace (deprecated)
-j, --jobs <N> Number of parallel jobs, defaults to # of CPUs.
--keep-going Do not abort the build as soon as there is an error (unstable)
--lib Build only this package's library
--bins Build all binaries
--bin [<NAME>] Build only the specified binary
--examples Build all examples
--example [<NAME>] Build only the specified example
--tests Build all tests
--test [<NAME>] Build only the specified test target
--benches Build all benches
--bench [<NAME>] Build only the specified bench target
--all-targets Build all targets
-r, --release Build artifacts in release mode, with optimizations
--profile <PROFILE-NAME> Build artifacts with the specified profile
-F, --features <FEATURES> Space or comma separated list of features to activate
--all-features Activate all available features
--no-default-features Do not activate the `default` feature
--target <TRIPLE> Build for the target triple
--target-dir <DIRECTORY> Directory for all generated artifacts
--out-dir <PATH> Copy final artifacts to this directory (unstable)
--manifest-path <PATH> Path to Cargo.toml
--ignore-rust-version Ignore `rust-version` specification in packages
--message-format <FMT> Error format
--build-plan Output the build plan in JSON (unstable)
--unit-graph Output build graph in JSON (unstable)
--future-incompat-report Outputs a future incompatibility report at the end of the build
--timings[=<FMTS>] Timing output formats (unstable) (comma separated): html, json
-h, --help Print help
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
--offline Run without accessing the network
--config <KEY=VALUE> Override a configuration value
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for
details

Run `cargo help build` for more detailed information.
1 change: 1 addition & 0 deletions tests/testsuite/cargo_build/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod help;
13 changes: 13 additions & 0 deletions tests/testsuite/cargo_check/help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;

#[cargo_test]
fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("check")
.arg("--help")
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Empty file.
46 changes: 46 additions & 0 deletions tests/testsuite/cargo_check/help/stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Check a local package and all of its dependencies for errors

Usage: cargo[EXE] check [OPTIONS]

Options:
-q, --quiet Do not print cargo log messages
-p, --package [<SPEC>] Package(s) to check
--workspace Check all packages in the workspace
--exclude <SPEC> Exclude packages from the check
--all Alias for --workspace (deprecated)
-j, --jobs <N> Number of parallel jobs, defaults to # of CPUs.
--keep-going Do not abort the build as soon as there is an error (unstable)
--lib Check only this package's library
--bins Check all binaries
--bin [<NAME>] Check only the specified binary
--examples Check all examples
--example [<NAME>] Check only the specified example
--tests Check all tests
--test [<NAME>] Check only the specified test target
--benches Check all benches
--bench [<NAME>] Check only the specified bench target
--all-targets Check all targets
-r, --release Check artifacts in release mode, with optimizations
--profile <PROFILE-NAME> Check artifacts with the specified profile
-F, --features <FEATURES> Space or comma separated list of features to activate
--all-features Activate all available features
--no-default-features Do not activate the `default` feature
--target <TRIPLE> Check for the target triple
--target-dir <DIRECTORY> Directory for all generated artifacts
--manifest-path <PATH> Path to Cargo.toml
--ignore-rust-version Ignore `rust-version` specification in packages
--message-format <FMT> Error format
--unit-graph Output build graph in JSON (unstable)
--future-incompat-report Outputs a future incompatibility report at the end of the build
--timings[=<FMTS>] Timing output formats (unstable) (comma separated): html, json
-h, --help Print help
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
--offline Run without accessing the network
--config <KEY=VALUE> Override a configuration value
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for
details

Run `cargo help check` for more detailed information.
1 change: 1 addition & 0 deletions tests/testsuite/cargo_check/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod help;
Loading