Add macros for all g_test_init options

Add macros, and use them.
This commit is contained in:
Matthias Clasen 2024-11-07 11:41:28 -05:00 committed by Philip Withnall
parent 90f4e562be
commit b161cb9252
2 changed files with 32 additions and 5 deletions

View File

@ -1637,12 +1637,14 @@ test_rm_isolate_dirs (void)
* *
* Options which can be passed to @... are: * Options which can be passed to @... are:
* *
* - `"no_g_set_prgname"`: Causes g_test_init() to not call g_set_prgname(). * - `G_TEST_OPTION_NO_PRGNAME`: Causes g_test_init() to not call
* - %G_TEST_OPTION_ISOLATE_DIRS: Creates a unique temporary directory for each * [func@GLib.set_prgname]. Since. 2.84
* - `G_TEST_OPTION_ISOLATE_DIRS`: Creates a unique temporary directory for each
* unit test and uses g_set_user_dirs() to set XDG directories to point into * unit test and uses g_set_user_dirs() to set XDG directories to point into
* that temporary directory for the duration of the unit test. See the * that temporary directory for the duration of the unit test. See the
* documentation for %G_TEST_OPTION_ISOLATE_DIRS. * documentation for %G_TEST_OPTION_ISOLATE_DIRS.
* - "nonfatal-assertions": This has the same effect as [func@GLib.test_set_nonfatal_assertions]. Since 2.82 * - `G_TEST_OPTION_NONFATAL_ASSERTIONS`: This has the same effect as
* [func@GLib.test_set_nonfatal_assertions]. Since 2.84
* *
* Since 2.58, if tests are compiled with `G_DISABLE_ASSERT` defined, * Since 2.58, if tests are compiled with `G_DISABLE_ASSERT` defined,
* g_test_init() will print an error and exit. This is to prevent no-op tests * g_test_init() will print an error and exit. This is to prevent no-op tests
@ -1697,11 +1699,11 @@ void
va_start (args, argv); va_start (args, argv);
while ((option = va_arg (args, char *))) while ((option = va_arg (args, char *)))
{ {
if (g_strcmp0 (option, "no_g_set_prgname") == 0) if (g_strcmp0 (option, G_TEST_OPTION_NO_PRGNAME) == 0)
no_g_set_prgname = TRUE; no_g_set_prgname = TRUE;
else if (g_strcmp0 (option, G_TEST_OPTION_ISOLATE_DIRS) == 0) else if (g_strcmp0 (option, G_TEST_OPTION_ISOLATE_DIRS) == 0)
test_isolate_dirs = TRUE; test_isolate_dirs = TRUE;
else if (g_strcmp0 (option, "nonfatal-assertions") == 0) else if (g_strcmp0 (option, G_TEST_OPTION_NONFATAL_ASSERTIONS) == 0)
test_nonfatal_assertions = TRUE; test_nonfatal_assertions = TRUE;
} }
va_end (args); va_end (args);

View File

@ -302,6 +302,8 @@ void g_test_init (int *argc,
/** /**
* G_TEST_OPTION_ISOLATE_DIRS: * G_TEST_OPTION_ISOLATE_DIRS:
* *
* A value that can be passed as an option to [func@GLib.test_init].
*
* Creates a unique temporary directory for each unit test and uses * Creates a unique temporary directory for each unit test and uses
* g_set_user_dirs() to set XDG directories to point into subdirectories of it * g_set_user_dirs() to set XDG directories to point into subdirectories of it
* for the duration of the unit test. The directory tree is cleaned up after the * for the duration of the unit test. The directory tree is cleaned up after the
@ -330,6 +332,29 @@ void g_test_init (int *argc,
*/ */
#define G_TEST_OPTION_ISOLATE_DIRS "isolate_dirs" #define G_TEST_OPTION_ISOLATE_DIRS "isolate_dirs"
/**
* G_TEST_OPTION_NO_PRGNAME:
*
* A value that can be passed as an option to [func@GLib.test_init].
*
* If this option is given, [func@GLib.test_init] will not call [func@GLib.set_prgname].
*
* Since: 2.84
*/
#define G_TEST_OPTION_NO_PRGNAME "no_g_set_prgname"
/**
* G_TEST_OPTION_NONFATAL_ASSERTIONS:
*
* A value that can be passed as an option to [func@GLib.test_init].
*
* If this option is given, assertions will not abort the process, but
* call [func@GLib.test_fail]. Equivalent to [func@GLib.test_set_nonfatal_assertions].
*
* Since: 2.84
*/
#define G_TEST_OPTION_NONFATAL_ASSERTIONS "nonfatal-assertions"
/* While we discourage its use, g_assert() is often used in unit tests /* While we discourage its use, g_assert() is often used in unit tests
* (especially in legacy code). g_assert_*() should really be used instead. * (especially in legacy code). g_assert_*() should really be used instead.
* g_assert() can be disabled at client program compile time, which can render * g_assert() can be disabled at client program compile time, which can render