• Philip Withnall's avatar
    gtestutils: Add XDG directory isolation · 13730c27
    Philip Withnall authored
    Add a new G_TEST_OPTIONS_ISOLATE_XDG_DIRS option for g_test_init() which
    automatically creates a temporary set of XDG directories, and a
    temporary home directory, and overrides the g_get_user_data_dir() (etc.)
    functions for the duration of the unit test with the temporary values.
    This is intended to better isolate unit tests from the user’s actual
    data and home directory. It works with g_test_subprocess(), but does not
    work with subprocesses spawned manually by the test — each unit test’s
    code will need to be amended to correctly set the XDG_* environment
    variables in the environment of any spawned subprocess.
    “Why not solve that by setting the XDG environment variables for the
    whole unit test process tree?” I hear you say. Setting environment
    variables is not thread safe and they would need to be re-set for each
    unit test, once worker threads have potentially been spawned.
    Signed-off-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
gtestutils.h 27.6 KB