From a7f82d31480b8d10999ae2588c0559698f090b8a Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sun, 3 Jun 2018 16:19:14 -0400 Subject: [PATCH] Allow verbose and scoped tests output. --- platform-independent/cli-c/cli/mpw-cli.c | 6 ++- platform-independent/cli-c/cli/mpw-tests.c | 54 ++++++++++++++++++++++ platform-independent/cli-c/core | 2 +- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/platform-independent/cli-c/cli/mpw-cli.c b/platform-independent/cli-c/cli/mpw-cli.c index f1b9625c..10ce2c30 100644 --- a/platform-independent/cli-c/cli/mpw-cli.c +++ b/platform-independent/cli-c/cli/mpw-cli.c @@ -34,14 +34,14 @@ static void usage() { inf( "" - " Master Password v%s\n" + " Master Password v%s - CLI\n" "--------------------------------------------------------------------------------\n" " https://masterpasswordapp.com\n", stringify_def( MP_VERSION ) ); inf( "" "\nUSAGE\n\n" " mpw [-u|-U full-name] [-m fd] [-t pw-type] [-P value] [-c counter]\n" " [-a version] [-p purpose] [-C context] [-f|F format] [-R 0|1]\n" - " [-v|-q] [-h] [site-name]\n" ); + " [-v|-q]* [-h] [site-name]\n" ); inf( "" " -u full-name Specify the full name of the user.\n" " -u checks the master password against the config,\n" @@ -110,6 +110,8 @@ static void usage() { " -q Decrease output verbosity (can be repeated).\n" ); inf( "" " -h Show this help output instead of performing any operation.\n" ); + inf( "" + " site-name Name of the site for which to generate a token.\n" ); inf( "" "\nENVIRONMENT\n\n" " %-12s The full name of the user (see -u).\n" diff --git a/platform-independent/cli-c/cli/mpw-tests.c b/platform-independent/cli-c/cli/mpw-tests.c index dc4db5db..140c377b 100644 --- a/platform-independent/cli-c/cli/mpw-tests.c +++ b/platform-independent/cli-c/cli/mpw-tests.c @@ -16,8 +16,13 @@ // LICENSE file. Alternatively, see . //============================================================================== +#define _POSIX_C_SOURCE 200809L + #include #include +#include +#include +#include #ifndef mpw_log_do #define mpw_log_do(level, format, ...) ({ \ @@ -32,8 +37,48 @@ #include "mpw-tests-util.h" +/** Output the program's usage documentation. */ +static void usage() { + + inf( "" + " Master Password v%s - Tests\n" + "--------------------------------------------------------------------------------\n" + " https://masterpasswordapp.com\n", stringify_def( MP_VERSION ) ); + inf( "" + "\nUSAGE\n\n" + " mpw-tests [-v|-q]* [-h] [test-name ...]\n" ); + inf( "" + " -v Increase output verbosity (can be repeated).\n" + " -q Decrease output verbosity (can be repeated).\n" ); + inf( "" + " -h Show this help output instead of performing any operation.\n" ); + inf( "" + " test-name Only run tests whose identifier starts with one of the these.\n" ); + exit( EX_OK ); +} + int main(int argc, char *const argv[]) { + for (int opt; (opt = getopt( argc, argv, "vqh" )) != EOF; + optarg? mpw_zero( optarg, strlen( optarg ) ): (void)0) + switch (opt) { + case 'v': + ++mpw_verbosity; + break; + case 'q': + --mpw_verbosity; + break; + case 'h': + usage(); + break; + case '?': + ftl( "Unknown option: -%c", optopt ); + exit( EX_USAGE ); + default: + ftl( "Unexpected option: %c", opt ); + exit( EX_USAGE ); + } + int failedTests = 0; xmlNodePtr tests = xmlDocGetRootElement( xmlParseFile( "mpw_tests.xml" ) ); @@ -64,6 +109,15 @@ int main(int argc, char *const argv[]) { // Run the test case. do { + if (optind < argc) { + bool selected = false; + for (int a = optind; !selected && a <= argc; ++a) + if (strstr((char *)id, argv[optind]) == (char *)id) + selected = true; + if (!selected) + continue; + } + fprintf( stdout, "test case %s... ", id ); if (!xmlStrlen( result )) { fprintf( stdout, "abstract." ); diff --git a/platform-independent/cli-c/core b/platform-independent/cli-c/core index 6f667dc4..bb825c69 120000 --- a/platform-independent/cli-c/core +++ b/platform-independent/cli-c/core @@ -1 +1 @@ -../../core/c \ No newline at end of file +../../core/c/src \ No newline at end of file