Skip to content

Commit

Permalink
Add macros for all g_test_init options
Browse files Browse the repository at this point in the history
Add macros, and use them.
  • Loading branch information
Matthias Clasen authored and pwithnall committed Nov 8, 2024
1 parent 90f4e56 commit b161cb9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
12 changes: 7 additions & 5 deletions glib/gtestutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,12 +1637,14 @@ test_rm_isolate_dirs (void)
*
* Options which can be passed to @... are:
*
* - `"no_g_set_prgname"`: Causes g_test_init() to not call g_set_prgname().
* - %G_TEST_OPTION_ISOLATE_DIRS: Creates a unique temporary directory for each
* - `G_TEST_OPTION_NO_PRGNAME`: Causes g_test_init() to not call
* [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
* that temporary directory for the duration of the unit test. See the
* 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,
* g_test_init() will print an error and exit. This is to prevent no-op tests
Expand Down Expand Up @@ -1697,11 +1699,11 @@ void
va_start (args, argv);
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;
else if (g_strcmp0 (option, G_TEST_OPTION_ISOLATE_DIRS) == 0)
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;
}
va_end (args);
Expand Down
25 changes: 25 additions & 0 deletions glib/gtestutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ void g_test_init (int *argc,
/**
* 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
* 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
Expand Down Expand Up @@ -330,6 +332,29 @@ void g_test_init (int *argc,
*/
#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
* (especially in legacy code). g_assert_*() should really be used instead.
* g_assert() can be disabled at client program compile time, which can render
Expand Down

0 comments on commit b161cb9

Please sign in to comment.