From 045bf99ae0901bd45ffb6fd3529fa707c900a34e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 30 Nov 2021 09:31:19 -0600 Subject: [PATCH] test: Consolidate builder tests This is prep for moving the derive tests. Besides organizing the test folder for each API, this should reduce link time at the cost of re-compiling more when a test changes. --- tests/{ => builder}/app_from_crate.rs | 0 tests/{ => builder}/app_settings.rs | 2 +- tests/{ => builder}/arg_aliases.rs | 2 +- tests/{ => builder}/arg_aliases_short.rs | 2 +- tests/{ => builder}/arg_matcher_assertions.rs | 0 tests/{ => builder}/arg_settings.rs | 2 - tests/{ => builder}/borrowed.rs | 0 tests/{ => builder}/cargo.rs | 0 tests/{ => builder}/conflicts.rs | 2 +- tests/{ => builder}/default_missing_vals.rs | 0 tests/{ => builder}/default_vals.rs | 2 +- tests/{ => builder}/delimiters.rs | 0 tests/{ => builder}/derive_order.rs | 2 +- tests/{ => builder}/display_order.rs | 2 +- tests/{ => builder}/double_require.rs | 0 tests/{ => builder}/empty_values.rs | 2 +- tests/{ => builder}/env.rs | 0 tests/{ => builder}/error.rs | 2 +- tests/{ => builder}/flag_subcommands.rs | 2 +- tests/{ => builder}/flags.rs | 2 +- tests/{ => builder}/global_args.rs | 2 - tests/{ => builder}/grouped_values.rs | 2 - tests/{ => builder}/groups.rs | 2 +- tests/{ => builder}/help.rs | 2 +- tests/{ => builder}/help_env.rs | 2 +- tests/{ => builder}/hidden_args.rs | 2 +- tests/{ => builder}/ignore_errors.rs | 0 tests/{ => builder}/indices.rs | 2 - tests/builder/main.rs | 47 +++++++++++++++++++ tests/{ => builder}/multiple_occurrences.rs | 0 tests/{ => builder}/multiple_values.rs | 0 tests/{ => builder}/opts.rs | 2 +- tests/{ => builder}/positionals.rs | 0 tests/{ => builder}/posix_compatible.rs | 0 tests/{ => builder}/possible_values.rs | 2 +- tests/{ => builder}/propagate_globals.rs | 2 - tests/{ => builder}/regex.rs | 0 tests/{ => builder}/require.rs | 2 +- tests/{ => builder}/subcommands.rs | 2 +- tests/{ => builder}/template_help.rs | 2 +- tests/{ => builder}/tests.rs | 2 +- tests/{ => builder}/unicode.rs | 0 tests/{ => builder}/unique_args.rs | 0 tests/{ => builder}/utf16.rs | 0 tests/{ => builder}/utf8.rs | 0 tests/{ => builder}/utils.rs | 0 tests/{ => builder}/validators.rs | 0 tests/{ => builder}/version.rs | 2 +- tests/macros.rs | 30 +----------- 49 files changed, 70 insertions(+), 61 deletions(-) rename tests/{ => builder}/app_from_crate.rs (100%) rename tests/{ => builder}/app_settings.rs (99%) rename tests/{ => builder}/arg_aliases.rs (99%) rename tests/{ => builder}/arg_aliases_short.rs (99%) rename tests/{ => builder}/arg_matcher_assertions.rs (100%) rename tests/{ => builder}/arg_settings.rs (99%) rename tests/{ => builder}/borrowed.rs (100%) rename tests/{ => builder}/cargo.rs (100%) rename tests/{ => builder}/conflicts.rs (99%) rename tests/{ => builder}/default_missing_vals.rs (100%) rename tests/{ => builder}/default_vals.rs (99%) rename tests/{ => builder}/delimiters.rs (100%) rename tests/{ => builder}/derive_order.rs (99%) rename tests/{ => builder}/display_order.rs (96%) rename tests/{ => builder}/double_require.rs (100%) rename tests/{ => builder}/empty_values.rs (99%) rename tests/{ => builder}/env.rs (100%) rename tests/{ => builder}/error.rs (98%) rename tests/{ => builder}/flag_subcommands.rs (99%) rename tests/{ => builder}/flags.rs (99%) rename tests/{ => builder}/global_args.rs (99%) rename tests/{ => builder}/grouped_values.rs (99%) rename tests/{ => builder}/groups.rs (99%) rename tests/{ => builder}/help.rs (99%) rename tests/{ => builder}/help_env.rs (99%) rename tests/{ => builder}/hidden_args.rs (99%) rename tests/{ => builder}/ignore_errors.rs (100%) rename tests/{ => builder}/indices.rs (99%) create mode 100644 tests/builder/main.rs rename tests/{ => builder}/multiple_occurrences.rs (100%) rename tests/{ => builder}/multiple_values.rs (100%) rename tests/{ => builder}/opts.rs (99%) rename tests/{ => builder}/positionals.rs (100%) rename tests/{ => builder}/posix_compatible.rs (100%) rename tests/{ => builder}/possible_values.rs (99%) rename tests/{ => builder}/propagate_globals.rs (99%) rename tests/{ => builder}/regex.rs (100%) rename tests/{ => builder}/require.rs (99%) rename tests/{ => builder}/subcommands.rs (99%) rename tests/{ => builder}/template_help.rs (99%) rename tests/{ => builder}/tests.rs (99%) rename tests/{ => builder}/unicode.rs (100%) rename tests/{ => builder}/unique_args.rs (100%) rename tests/{ => builder}/utf16.rs (100%) rename tests/{ => builder}/utf8.rs (100%) rename tests/{ => builder}/utils.rs (100%) rename tests/{ => builder}/validators.rs (100%) rename tests/{ => builder}/version.rs (99%) diff --git a/tests/app_from_crate.rs b/tests/builder/app_from_crate.rs similarity index 100% rename from tests/app_from_crate.rs rename to tests/builder/app_from_crate.rs diff --git a/tests/app_settings.rs b/tests/builder/app_settings.rs similarity index 99% rename from tests/app_settings.rs rename to tests/builder/app_settings.rs index 7e03807a..0f280192 100644 --- a/tests/app_settings.rs +++ b/tests/builder/app_settings.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, AppSettings, Arg, ErrorKind}; diff --git a/tests/arg_aliases.rs b/tests/builder/arg_aliases.rs similarity index 99% rename from tests/arg_aliases.rs rename to tests/builder/arg_aliases.rs index 1c043f64..4411412d 100644 --- a/tests/arg_aliases.rs +++ b/tests/builder/arg_aliases.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, Arg}; diff --git a/tests/arg_aliases_short.rs b/tests/builder/arg_aliases_short.rs similarity index 99% rename from tests/arg_aliases_short.rs rename to tests/builder/arg_aliases_short.rs index a4e4d42e..341a9837 100644 --- a/tests/arg_aliases_short.rs +++ b/tests/builder/arg_aliases_short.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, Arg}; diff --git a/tests/arg_matcher_assertions.rs b/tests/builder/arg_matcher_assertions.rs similarity index 100% rename from tests/arg_matcher_assertions.rs rename to tests/builder/arg_matcher_assertions.rs diff --git a/tests/arg_settings.rs b/tests/builder/arg_settings.rs similarity index 99% rename from tests/arg_settings.rs rename to tests/builder/arg_settings.rs index c642ce33..3ee15078 100644 --- a/tests/arg_settings.rs +++ b/tests/builder/arg_settings.rs @@ -1,5 +1,3 @@ -mod utils; - use clap::{Arg, ArgSettings}; #[test] diff --git a/tests/borrowed.rs b/tests/builder/borrowed.rs similarity index 100% rename from tests/borrowed.rs rename to tests/builder/borrowed.rs diff --git a/tests/cargo.rs b/tests/builder/cargo.rs similarity index 100% rename from tests/cargo.rs rename to tests/builder/cargo.rs diff --git a/tests/conflicts.rs b/tests/builder/conflicts.rs similarity index 99% rename from tests/conflicts.rs rename to tests/builder/conflicts.rs index f1e79c0c..c01df2dc 100644 --- a/tests/conflicts.rs +++ b/tests/builder/conflicts.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, Arg, ArgGroup, ErrorKind}; diff --git a/tests/default_missing_vals.rs b/tests/builder/default_missing_vals.rs similarity index 100% rename from tests/default_missing_vals.rs rename to tests/builder/default_missing_vals.rs diff --git a/tests/default_vals.rs b/tests/builder/default_vals.rs similarity index 99% rename from tests/default_vals.rs rename to tests/builder/default_vals.rs index 16f9c07c..e5160d67 100644 --- a/tests/default_vals.rs +++ b/tests/builder/default_vals.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, Arg, ErrorKind}; #[test] diff --git a/tests/delimiters.rs b/tests/builder/delimiters.rs similarity index 100% rename from tests/delimiters.rs rename to tests/builder/delimiters.rs diff --git a/tests/derive_order.rs b/tests/builder/derive_order.rs similarity index 99% rename from tests/derive_order.rs rename to tests/builder/derive_order.rs index ae3dcc62..c1a232c2 100644 --- a/tests/derive_order.rs +++ b/tests/builder/derive_order.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use std::str; diff --git a/tests/display_order.rs b/tests/builder/display_order.rs similarity index 96% rename from tests/display_order.rs rename to tests/builder/display_order.rs index f538d5fc..cf83fadf 100644 --- a/tests/display_order.rs +++ b/tests/builder/display_order.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::App; diff --git a/tests/double_require.rs b/tests/builder/double_require.rs similarity index 100% rename from tests/double_require.rs rename to tests/builder/double_require.rs diff --git a/tests/empty_values.rs b/tests/builder/empty_values.rs similarity index 99% rename from tests/empty_values.rs rename to tests/builder/empty_values.rs index 1de9e30b..ca268b20 100644 --- a/tests/empty_values.rs +++ b/tests/builder/empty_values.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{App, Arg, ErrorKind}; diff --git a/tests/env.rs b/tests/builder/env.rs similarity index 100% rename from tests/env.rs rename to tests/builder/env.rs diff --git a/tests/error.rs b/tests/builder/error.rs similarity index 98% rename from tests/error.rs rename to tests/builder/error.rs index f6e3a859..e9bde59c 100644 --- a/tests/error.rs +++ b/tests/builder/error.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{App, Arg, Error, ErrorKind}; diff --git a/tests/flag_subcommands.rs b/tests/builder/flag_subcommands.rs similarity index 99% rename from tests/flag_subcommands.rs rename to tests/builder/flag_subcommands.rs index 3b79de07..0000adfb 100644 --- a/tests/flag_subcommands.rs +++ b/tests/builder/flag_subcommands.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, AppSettings, Arg, ErrorKind}; diff --git a/tests/flags.rs b/tests/builder/flags.rs similarity index 99% rename from tests/flags.rs rename to tests/builder/flags.rs index 65dc964b..d84e748c 100644 --- a/tests/flags.rs +++ b/tests/builder/flags.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, Arg}; const USE_FLAG_AS_ARGUMENT: &str = diff --git a/tests/global_args.rs b/tests/builder/global_args.rs similarity index 99% rename from tests/global_args.rs rename to tests/builder/global_args.rs index 82cfdced..e6583f5f 100644 --- a/tests/global_args.rs +++ b/tests/builder/global_args.rs @@ -1,5 +1,3 @@ -mod utils; - use clap::{arg, App, Arg}; #[test] diff --git a/tests/grouped_values.rs b/tests/builder/grouped_values.rs similarity index 99% rename from tests/grouped_values.rs rename to tests/builder/grouped_values.rs index a7e01d4e..6d7838db 100644 --- a/tests/grouped_values.rs +++ b/tests/builder/grouped_values.rs @@ -1,7 +1,5 @@ #![cfg(feature = "unstable-grouped")] -mod utils; - use clap::{App, AppSettings, Arg}; #[test] diff --git a/tests/groups.rs b/tests/builder/groups.rs similarity index 99% rename from tests/groups.rs rename to tests/builder/groups.rs index 367d1177..ea64144b 100644 --- a/tests/groups.rs +++ b/tests/builder/groups.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, Arg, ArgGroup, ErrorKind}; diff --git a/tests/help.rs b/tests/builder/help.rs similarity index 99% rename from tests/help.rs rename to tests/builder/help.rs index d41471f0..c613bfed 100644 --- a/tests/help.rs +++ b/tests/builder/help.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, AppSettings, Arg, ArgGroup, ErrorKind, PossibleValue}; diff --git a/tests/help_env.rs b/tests/builder/help_env.rs similarity index 99% rename from tests/help_env.rs rename to tests/builder/help_env.rs index 2a0aae85..d203ed15 100644 --- a/tests/help_env.rs +++ b/tests/builder/help_env.rs @@ -4,7 +4,7 @@ use std::env; use clap::{App, Arg}; -mod utils; +use crate::utils; static HIDE_ENV: &str = "ctest 0.1 diff --git a/tests/hidden_args.rs b/tests/builder/hidden_args.rs similarity index 99% rename from tests/hidden_args.rs rename to tests/builder/hidden_args.rs index 60b833df..04f45279 100644 --- a/tests/hidden_args.rs +++ b/tests/builder/hidden_args.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, AppSettings, Arg}; diff --git a/tests/ignore_errors.rs b/tests/builder/ignore_errors.rs similarity index 100% rename from tests/ignore_errors.rs rename to tests/builder/ignore_errors.rs diff --git a/tests/indices.rs b/tests/builder/indices.rs similarity index 99% rename from tests/indices.rs rename to tests/builder/indices.rs index 94935957..5da79d7d 100644 --- a/tests/indices.rs +++ b/tests/builder/indices.rs @@ -1,5 +1,3 @@ -mod utils; - use clap::{App, Arg}; #[test] diff --git a/tests/builder/main.rs b/tests/builder/main.rs new file mode 100644 index 00000000..ab181047 --- /dev/null +++ b/tests/builder/main.rs @@ -0,0 +1,47 @@ +mod app_from_crate; +mod app_settings; +mod arg_aliases; +mod arg_aliases_short; +mod arg_matcher_assertions; +mod arg_settings; +mod borrowed; +mod cargo; +mod conflicts; +mod default_missing_vals; +mod default_vals; +mod delimiters; +mod derive_order; +mod display_order; +mod double_require; +mod empty_values; +mod env; +mod error; +mod flag_subcommands; +mod flags; +mod global_args; +mod grouped_values; +mod groups; +mod help; +mod help_env; +mod hidden_args; +mod ignore_errors; +mod indices; +mod multiple_occurrences; +mod multiple_values; +mod opts; +mod positionals; +mod posix_compatible; +mod possible_values; +mod propagate_globals; +mod regex; +mod require; +mod subcommands; +mod template_help; +mod tests; +mod unicode; +mod unique_args; +mod utf16; +mod utf8; +mod utils; +mod validators; +mod version; diff --git a/tests/multiple_occurrences.rs b/tests/builder/multiple_occurrences.rs similarity index 100% rename from tests/multiple_occurrences.rs rename to tests/builder/multiple_occurrences.rs diff --git a/tests/multiple_values.rs b/tests/builder/multiple_values.rs similarity index 100% rename from tests/multiple_values.rs rename to tests/builder/multiple_values.rs diff --git a/tests/opts.rs b/tests/builder/opts.rs similarity index 99% rename from tests/opts.rs rename to tests/builder/opts.rs index 680107ab..d57de5b4 100644 --- a/tests/opts.rs +++ b/tests/builder/opts.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, AppSettings, Arg, ArgMatches, ErrorKind}; diff --git a/tests/positionals.rs b/tests/builder/positionals.rs similarity index 100% rename from tests/positionals.rs rename to tests/builder/positionals.rs diff --git a/tests/posix_compatible.rs b/tests/builder/posix_compatible.rs similarity index 100% rename from tests/posix_compatible.rs rename to tests/builder/posix_compatible.rs diff --git a/tests/possible_values.rs b/tests/builder/possible_values.rs similarity index 99% rename from tests/possible_values.rs rename to tests/builder/possible_values.rs index 5f5ee84b..6290b028 100644 --- a/tests/possible_values.rs +++ b/tests/builder/possible_values.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{App, Arg, ErrorKind, PossibleValue}; diff --git a/tests/propagate_globals.rs b/tests/builder/propagate_globals.rs similarity index 99% rename from tests/propagate_globals.rs rename to tests/builder/propagate_globals.rs index 8fc42572..f3340795 100644 --- a/tests/propagate_globals.rs +++ b/tests/builder/propagate_globals.rs @@ -1,5 +1,3 @@ -mod utils; - use clap::{App, Arg, ArgMatches}; fn get_app() -> App<'static> { diff --git a/tests/regex.rs b/tests/builder/regex.rs similarity index 100% rename from tests/regex.rs rename to tests/builder/regex.rs diff --git a/tests/require.rs b/tests/builder/require.rs similarity index 99% rename from tests/require.rs rename to tests/builder/require.rs index 81d1ab59..5e39073a 100644 --- a/tests/require.rs +++ b/tests/builder/require.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, Arg, ArgGroup, ErrorKind}; diff --git a/tests/subcommands.rs b/tests/builder/subcommands.rs similarity index 99% rename from tests/subcommands.rs rename to tests/builder/subcommands.rs index 47daa776..015fc7e3 100644 --- a/tests/subcommands.rs +++ b/tests/builder/subcommands.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App, AppSettings, Arg, ErrorKind}; diff --git a/tests/template_help.rs b/tests/builder/template_help.rs similarity index 99% rename from tests/template_help.rs rename to tests/builder/template_help.rs index f51f2b28..17ea5e8b 100644 --- a/tests/template_help.rs +++ b/tests/builder/template_help.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use clap::{arg, App}; diff --git a/tests/tests.rs b/tests/builder/tests.rs similarity index 99% rename from tests/tests.rs rename to tests/builder/tests.rs index b5c32250..33b29b1b 100644 --- a/tests/tests.rs +++ b/tests/builder/tests.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use std::io::Write; use std::str; diff --git a/tests/unicode.rs b/tests/builder/unicode.rs similarity index 100% rename from tests/unicode.rs rename to tests/builder/unicode.rs diff --git a/tests/unique_args.rs b/tests/builder/unique_args.rs similarity index 100% rename from tests/unique_args.rs rename to tests/builder/unique_args.rs diff --git a/tests/utf16.rs b/tests/builder/utf16.rs similarity index 100% rename from tests/utf16.rs rename to tests/builder/utf16.rs diff --git a/tests/utf8.rs b/tests/builder/utf8.rs similarity index 100% rename from tests/utf8.rs rename to tests/builder/utf8.rs diff --git a/tests/utils.rs b/tests/builder/utils.rs similarity index 100% rename from tests/utils.rs rename to tests/builder/utils.rs diff --git a/tests/validators.rs b/tests/builder/validators.rs similarity index 100% rename from tests/validators.rs rename to tests/builder/validators.rs diff --git a/tests/version.rs b/tests/builder/version.rs similarity index 99% rename from tests/version.rs rename to tests/builder/version.rs index ebb7ace2..bee11707 100644 --- a/tests/version.rs +++ b/tests/builder/version.rs @@ -1,4 +1,4 @@ -mod utils; +use crate::utils; use std::str; diff --git a/tests/macros.rs b/tests/macros.rs index 986fdb30..6dc479fa 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -1,28 +1,7 @@ -mod utils; - // We intentionally don't import `clap_app!` here; not having it in scope protects against the // class of errors where the macro refers to itself as `clap_app!` instead of `$crate::clap_app!` use clap::ErrorKind; -static LITERALS: &str = "clap-tests 0.1 - -USAGE: - clap-tests [OPTIONS] [SUBCOMMAND] - -OPTIONS: - -4, --4 Sets priority to 4 - -5, --5 Sets priority to 5 - -6, --6 Sets priority to 6 - -h, --help Print help information - -t, --task-num Task number [possible values: all, 0, 1, 2] - -V, --version Print version information - -SUBCOMMANDS: - 0 Set everything to zero priority - help Print this message or the help of the given subcommand(s) - view-tasks View all tasks -"; - #[test] fn basic() { #![allow(deprecated)] @@ -441,7 +420,7 @@ fn group_macro_multiple_invocations() { #[test] fn literals() { #![allow(deprecated)] - let app = clap::clap_app!("clap-tests" => + clap::clap_app!("clap-tests" => (version: "0.1") (@arg "task-num": -"t-n" --"task-num" +takes_value possible_value["all" 0 1 2] "Task number") @@ -455,13 +434,6 @@ fn literals() { (@subcommand 0 => (about: "Set everything to zero priority")) ); - - assert!(utils::compare_output( - app, - "clap-tests --help", - LITERALS, - false - )); } #[test]