]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
test/test-utils.c: Add command line option --help to test applications
authorRalf Habacker <ralf.habacker@freenet.de>
Fri, 10 Dec 2021 09:17:18 +0000 (10:17 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Fri, 10 Dec 2021 09:21:35 +0000 (10:21 +0100)
test/test-utils.c

index c8884da49d74aabd5b3a1da4d1425a428f6dba30..e78527080e360b71673f8a8f167a4f860cc0f846 100644 (file)
@@ -647,6 +647,18 @@ _dbus_check_fdleaks_leave (DBusInitialFDs *fds,
 #endif
 }
 
+static void
+_dbus_test_help_page (const char *appname)
+{
+  fprintf(stdout, "%s [<options>] [<test-data-dir>] [<specific-test>]\n", appname);
+  fprintf(stdout, "Options:\n");
+  fprintf(stdout, "    --help         this page\n");
+  fprintf(stdout, "    --tap          expect test data dir to be set by environment variable DBUS_TEST_DATA\n");
+  fprintf(stdout, "Environment variables:\n");
+  fprintf(stdout, "    DBUS_TEST_ONLY=<specific-test>    set specific test to run\n");
+  fprintf(stdout, "    DBUS_TEST_DATA=<test-data-dir>    set test data dir (required when using --tap)\n");
+}
+
 /*
  * _dbus_test_main:
  * @argc: number of command-line arguments
@@ -684,6 +696,12 @@ _dbus_test_main (int                  argc,
   setlocale(LC_ALL, "");
 #endif
 
+  if (argc > 1 && strcmp (argv[1], "--help") == 0)
+    {
+      _dbus_test_help_page (argv[0]);
+      exit(0);
+    }
+
   /* We can't assume that strings from _dbus_getenv() will remain valid
    * forever, because some tests call setenv(), which is allowed to
    * reallocate the entire environment block, and in Wine it seems that it
@@ -701,8 +719,11 @@ _dbus_test_main (int                  argc,
   if (test_data_dir != NULL)
     _dbus_test_diag ("Test data in %s", test_data_dir);
   else if (flags & DBUS_TEST_FLAGS_REQUIRE_DATA)
-    _dbus_test_fatal ("Must specify test data directory as argv[1] or "
-                      "in DBUS_TEST_DATA environment variable");
+    {
+      _dbus_test_help_page (argv[0]);
+      _dbus_test_fatal ("Must specify test data directory as argv[1] or "
+                        "in DBUS_TEST_DATA environment variable");
+    }
   else
     _dbus_test_diag ("No test data!");