From 9138d65e4cc6d33583cf787b9d9d27e5553bcb1e Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 5 Jul 2020 17:51:22 -0700 Subject: [PATCH] Create a dedicated module for help tests. --- tests/testsuite/cargo_command.rs | 38 ------------------------- tests/testsuite/help.rs | 49 ++++++++++++++++++++++++++++++++ tests/testsuite/main.rs | 1 + tests/testsuite/search.rs | 11 ------- 4 files changed, 50 insertions(+), 49 deletions(-) create mode 100644 tests/testsuite/help.rs diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index 667c29338..b099bf517 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -338,35 +338,6 @@ fn cargo_subcommand_args() { .run(); } -#[cargo_test] -fn cargo_help() { - cargo_process("").run(); - cargo_process("help").run(); - cargo_process("-h").run(); - cargo_process("help build").run(); - cargo_process("build -h").run(); - cargo_process("help help").run(); -} - -#[cargo_test] -fn cargo_help_external_subcommand() { - Package::new("cargo-fake-help", "1.0.0") - .file( - "src/main.rs", - r#" - fn main() { - if ::std::env::args().nth(2) == Some(String::from("--help")) { - println!("fancy help output"); - } - }"#, - ) - .publish(); - cargo_process("install cargo-fake-help").run(); - cargo_process("help fake-help") - .with_stdout("fancy help output\n") - .run(); -} - #[cargo_test] fn explain() { cargo_process("--explain E0001") @@ -376,15 +347,6 @@ fn explain() { .run(); } -// Test that the output of `cargo -Z help` shows a different help screen with -// all the `-Z` flags. -#[cargo_test] -fn z_flags_help() { - cargo_process("-Z help") - .with_stdout_contains(" -Z unstable-options -- Allow the usage of unstable options") - .run(); -} - #[cargo_test] fn closed_output_ok() { // Checks that closed output doesn't cause an error. diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs new file mode 100644 index 000000000..5bd3aa5ed --- /dev/null +++ b/tests/testsuite/help.rs @@ -0,0 +1,49 @@ +//! Tests for cargo's help output. + +use cargo_test_support::cargo_process; +use cargo_test_support::registry::Package; + +#[cargo_test] +fn help() { + cargo_process("").run(); + cargo_process("help").run(); + cargo_process("-h").run(); + cargo_process("help build").run(); + cargo_process("build -h").run(); + cargo_process("help help").run(); + // Ensure that help output goes to stdout, not stderr. + cargo_process("search --help").with_stderr("").run(); + cargo_process("search --help") + .with_stdout_contains("[..] --frozen [..]") + .run(); +} + +#[cargo_test] +fn help_external_subcommand() { + // Check that `help external-subcommand` forwards the --help flag to the + // given subcommand. + Package::new("cargo-fake-help", "1.0.0") + .file( + "src/main.rs", + r#" + fn main() { + if ::std::env::args().nth(2) == Some(String::from("--help")) { + println!("fancy help output"); + } + }"#, + ) + .publish(); + cargo_process("install cargo-fake-help").run(); + cargo_process("help fake-help") + .with_stdout("fancy help output\n") + .run(); +} + +#[cargo_test] +fn z_flags_help() { + // Test that the output of `cargo -Z help` shows a different help screen with + // all the `-Z` flags. + cargo_process("-Z help") + .with_stdout_contains(" -Z unstable-options -- Allow the usage of unstable options") + .run(); +} diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index e21fa7ffd..78379e8a0 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -52,6 +52,7 @@ mod generate_lockfile; mod git; mod git_auth; mod git_gc; +mod help; mod init; mod install; mod install_upgrade; diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 4b4eb8a01..94f432263 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -244,14 +244,3 @@ fn multiple_query_params() { .with_stdout_contains(SEARCH_RESULTS) .run(); } - -#[cargo_test] -fn help() { - cargo_process("search -h").run(); - cargo_process("help search").run(); - // Ensure that help output goes to stdout, not stderr. - cargo_process("search --help").with_stderr("").run(); - cargo_process("search --help") - .with_stdout_contains("[..] --frozen [..]") - .run(); -}