diff --git a/glib/gtestutils.c b/glib/gtestutils.c index fa820db21..34cee4d1b 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -627,6 +627,7 @@ static GTestConfig mutable_test_config_vars = { TRUE, /* test_undefined */ }; const GTestConfig * const g_test_config_vars = &mutable_test_config_vars; +static gboolean no_g_set_prgname = FALSE; /* --- functions --- */ const char* @@ -1003,7 +1004,9 @@ parse_args (gint *argc_p, * Changed if any arguments were handled. * @argv: Address of the @argv parameter of main(). * Any parameters understood by g_test_init() stripped before return. - * @...: Reserved for future extension. Currently, you must pass %NULL. + * @...: %NULL-terminated list of special options. Currently the only + * defined option is "no_g_set_prgname", which + * will cause g_test_init() to not call g_set_prgname(). * * Initialize the GLib testing framework, e.g. by seeding the * test random number generator, the name for g_get_prgname() @@ -1094,9 +1097,10 @@ g_test_init (int *argc, { static char seedstr[4 + 4 * 8 + 1]; va_list args; - gpointer vararg1; + gpointer option; /* make warnings and criticals fatal for all test programs */ GLogLevelFlags fatal_mask = (GLogLevelFlags) g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK); + fatal_mask = (GLogLevelFlags) (fatal_mask | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); g_log_set_always_fatal (fatal_mask); /* check caller args */ @@ -1106,9 +1110,12 @@ g_test_init (int *argc, mutable_test_config_vars.test_initialized = TRUE; va_start (args, argv); - vararg1 = va_arg (args, gpointer); /* reserved for future extensions */ + while ((option = va_arg (args, char *))) + { + if (g_strcmp0 (option, "no_g_set_prgname") == 0) + no_g_set_prgname = TRUE; + } va_end (args); - g_return_if_fail (vararg1 == NULL); /* setup random seed string */ g_snprintf (seedstr, sizeof (seedstr), "R02S%08x%08x%08x%08x", g_random_int(), g_random_int(), g_random_int(), g_random_int()); @@ -1116,7 +1123,8 @@ g_test_init (int *argc, /* parse args, sets up mode, changes seed, etc. */ parse_args (argc, argv); - if (!g_get_prgname()) + + if (!g_get_prgname() && !no_g_set_prgname) g_set_prgname ((*argv)[0]); /* verify GRand reliability, needed for reliable seeds */ diff --git a/glib/gtestutils.h b/glib/gtestutils.h index 889df44ac..9700f38fc 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -107,7 +107,7 @@ void g_test_maximized_result (double maximized_quantity, GLIB_AVAILABLE_IN_ALL void g_test_init (int *argc, char ***argv, - ...); + ...) G_GNUC_NULL_TERMINATED; /* query testing framework config */ #define g_test_initialized() (g_test_config_vars->test_initialized) #define g_test_quick() (g_test_config_vars->test_quick) diff --git a/glib/tests/option-argv0.c b/glib/tests/option-argv0.c index c7bbc7c53..8ae00ca6f 100644 --- a/glib/tests/option-argv0.c +++ b/glib/tests/option-argv0.c @@ -54,14 +54,11 @@ int main (int argc, char *argv[]) { - /* Note - we can't actually use g_test_* because g_test_init mutates - * g_get_prgname() which is exactly what we wanted to test =/ - */ + g_test_init (&argc, &argv, "no_g_set_prgname", NULL); + #if defined __linux || defined __OpenBSD__ - g_print ("/option/argv0: "); - test_platform_argv0 (); - g_print ("OK\n"); + g_test_add_func ("/option/argv0", test_platform_argv0); #endif - return 0; + return g_test_run (); }