]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
test-skeleton: add usage information
authorMike Frysinger <vapier@gentoo.org>
Tue, 4 Aug 2015 11:26:46 +0000 (07:26 -0400)
committerMike Frysinger <vapier@gentoo.org>
Wed, 5 Aug 2015 08:40:00 +0000 (04:40 -0400)
I keep trying to run tests with --help and then remembering that does
nothing when it throws an error.  That means I have to dig into the
source when I want to refer to flags or env vars and re-read a good
amount of code to find the nested locations.

Make this all much more user friendly with a usage screen that gets
printed out whenever an unknown option is specified.

ChangeLog
test-skeleton.c

index a05d2625b52daffb13a31eff68477663b2fe2fce..b072b80e9f6e13918d527d2932c33b78f9534478 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-08-05  Mike Frysinger  <vapier@gentoo.org>
+
+       * test-skeleton.c (usage): New function.
+       (main): Call usage when opt is '?'.
+
 2015-08-05  Mike Frysinger  <vapier@gentoo.org>
 
        * sysdeps/unix/sysv/linux/mmap64.c: Move MMAP2_PAGE_SHIFT define
index 9ee5001440b12805d22a8eb262c7651345a6c1f5..1b2688c3bf34817b26e64d5f38d124b46a5dee16 100644 (file)
@@ -250,6 +250,41 @@ set_fortify_handler (void (*handler) (int sig))
   ignore_stderr ();
 }
 
+/* Show people how to run the program.  */
+static void
+usage (void)
+{
+  size_t i;
+
+  printf ("Usage: %s [options]\n"
+         "\n"
+         "Environment Variables:\n"
+         "  TIMEOUTFACTOR          An integer used to scale the timeout\n"
+         "  TMPDIR                 Where to place temporary files\n"
+         "\n",
+         program_invocation_short_name);
+  printf ("Options:\n");
+  for (i = 0; options[i].name; ++i)
+    {
+      int indent;
+
+      indent = printf ("  --%s", options[i].name);
+      if (options[i].has_arg == required_argument)
+       indent += printf (" <arg>");
+      printf ("%*s", 25 - indent, "");
+      switch (options[i].val)
+       {
+       case OPT_DIRECT:
+         printf ("Run the test directly (instead of forking & monitoring)");
+         break;
+       case OPT_TESTDIR:
+         printf ("Override the TMPDIR env var");
+         break;
+       }
+      printf ("\n");
+    }
+}
+
 /* We provide the entry point here.  */
 int
 main (int argc, char *argv[])
@@ -271,6 +306,7 @@ main (int argc, char *argv[])
     switch (opt)
       {
       case '?':
+       usage ();
        exit (1);
       case OPT_DIRECT:
        direct = 1;