From 7cd65cd07cfa2693455d174049b4887434041695 Mon Sep 17 00:00:00 2001 From: Andres Mejia Date: Fri, 16 Mar 2012 16:02:26 -0400 Subject: [PATCH] Allow verbosity level for test programs to be set via environment variables. --- cpio/test/main.c | 21 ++++++++++++++++++--- libarchive/test/main.c | 21 ++++++++++++++++++--- tar/test/main.c | 21 ++++++++++++++++++--- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/cpio/test/main.c b/cpio/test/main.c index 77bdabe6c..da4c015e6 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -2387,7 +2387,7 @@ main(int argc, char **argv) const char *progname; char **saved_argv; const char *tmp, *option_arg, *p; - char tmpdir[256], *pwd, *testprogdir, *tmp2 = NULL; + char tmpdir[256], *pwd, *testprogdir, *tmp2 = NULL, *vlevel = NULL; char tmpdir_timestamp[256]; (void)argc; /* UNUSED */ @@ -2473,6 +2473,19 @@ main(int argc, char **argv) if (getenv(ENVBASE "_DEBUG") != NULL) dump_on_failure = 1; + /* Allow -v to be controlled through the environment. */ + if (getenv("_VERBOSITY_LEVEL") != NULL) + { + vlevel = getenv("_VERBOSITY_LEVEL"); + verbosity = atoi(vlevel); + if (verbosity < VERBOSITY_SUMMARY_ONLY || verbosity > VERBOSITY_FULL) + { + /* Unsupported verbosity levels are silently ignored */ + vlevel = NULL; + verbosity = VERBOSITY_PASSFAIL; + } + } + /* Get the directory holding test files from environment. */ refdir = getenv(ENVBASE "_TEST_FILES"); @@ -2520,7 +2533,8 @@ main(int argc, char **argv) #endif break; case 'q': - verbosity--; + if (!vlevel) + verbosity--; break; case 'r': refdir = option_arg; @@ -2529,7 +2543,8 @@ main(int argc, char **argv) until_failure++; break; case 'v': - verbosity++; + if (!vlevel) + verbosity++; break; default: fprintf(stderr, "Unrecognized option '%c'\n", diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 11f01d2d6..56f798129 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -2385,7 +2385,7 @@ main(int argc, char **argv) const char *progname; char **saved_argv; const char *tmp, *option_arg, *p; - char tmpdir[256], *pwd, *testprogdir, *tmp2 = NULL; + char tmpdir[256], *pwd, *testprogdir, *tmp2 = NULL, *vlevel = NULL; char tmpdir_timestamp[256]; (void)argc; /* UNUSED */ @@ -2471,6 +2471,19 @@ main(int argc, char **argv) if (getenv(ENVBASE "_DEBUG") != NULL) dump_on_failure = 1; + /* Allow -v to be controlled through the environment. */ + if (getenv("_VERBOSITY_LEVEL") != NULL) + { + vlevel = getenv("_VERBOSITY_LEVEL"); + verbosity = atoi(vlevel); + if (verbosity < VERBOSITY_SUMMARY_ONLY || verbosity > VERBOSITY_FULL) + { + /* Unsupported verbosity levels are silently ignored */ + vlevel = NULL; + verbosity = VERBOSITY_PASSFAIL; + } + } + /* Get the directory holding test files from environment. */ refdir = getenv(ENVBASE "_TEST_FILES"); @@ -2518,7 +2531,8 @@ main(int argc, char **argv) #endif break; case 'q': - verbosity--; + if (!vlevel) + verbosity--; break; case 'r': refdir = option_arg; @@ -2527,7 +2541,8 @@ main(int argc, char **argv) until_failure++; break; case 'v': - verbosity++; + if (!vlevel) + verbosity++; break; default: fprintf(stderr, "Unrecognized option '%c'\n", diff --git a/tar/test/main.c b/tar/test/main.c index 45cbae0a6..a202334ce 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -2387,7 +2387,7 @@ main(int argc, char **argv) const char *progname; char **saved_argv; const char *tmp, *option_arg, *p; - char tmpdir[256], *pwd, *testprogdir, *tmp2 = NULL; + char tmpdir[256], *pwd, *testprogdir, *tmp2 = NULL, *vlevel = NULL; char tmpdir_timestamp[256]; (void)argc; /* UNUSED */ @@ -2473,6 +2473,19 @@ main(int argc, char **argv) if (getenv(ENVBASE "_DEBUG") != NULL) dump_on_failure = 1; + /* Allow -v to be controlled through the environment. */ + if (getenv("_VERBOSITY_LEVEL") != NULL) + { + vlevel = getenv("_VERBOSITY_LEVEL"); + verbosity = atoi(vlevel); + if (verbosity < VERBOSITY_SUMMARY_ONLY || verbosity > VERBOSITY_FULL) + { + /* Unsupported verbosity levels are silently ignored */ + vlevel = NULL; + verbosity = VERBOSITY_PASSFAIL; + } + } + /* Get the directory holding test files from environment. */ refdir = getenv(ENVBASE "_TEST_FILES"); @@ -2520,7 +2533,8 @@ main(int argc, char **argv) #endif break; case 'q': - verbosity--; + if (!vlevel) + verbosity--; break; case 'r': refdir = option_arg; @@ -2529,7 +2543,8 @@ main(int argc, char **argv) until_failure++; break; case 'v': - verbosity++; + if (!vlevel) + verbosity++; break; default: fprintf(stderr, "Unrecognized option '%c'\n", -- 2.47.3