After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 674197 - Add helpers to redirect XDG_*_HOME to a temp dir for unit tests
Add helpers to redirect XDG_*_HOME to a temp dir for unit tests
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gio
2.29.x
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on: 672985
Blocks:
 
 
Reported: 2012-04-16 11:37 UTC by Xavier Claessens
Modified: 2018-05-24 14:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add helper functions to set XDG dirs to a temporary directory (7.13 KB, patch)
2012-04-16 11:39 UTC, Xavier Claessens
none Details | Review
Add helper functions to set XDG dirs to a temporary directory (7.93 KB, patch)
2012-04-19 12:35 UTC, Xavier Claessens
none Details | Review
Add helper functions to set XDG dirs to a temporary directory (10.15 KB, patch)
2013-03-25 17:06 UTC, Xavier Claessens
none Details | Review

Description Xavier Claessens 2012-04-16 11:37:45 UTC
Some unit tests may want to write in ~/.cache but does not want to mess up with user's files. In that case the unit test needs to set XDG_CACHE_HOME to /tmp/something.

This gets tricky to cleanup the directory in the case the unit test crash for example. We could profit of the watcher process we fork in gtestdbus.c (see bug #672985) and make that process also cleanup the temp dirs.
Comment 1 Xavier Claessens 2012-04-16 11:38:54 UTC
My git branch doing this:
http://cgit.collabora.com/git/user/xclaesse/glib.git/log/?h=xdg-test
Comment 2 Xavier Claessens 2012-04-16 11:39:32 UTC
Created attachment 212136 [details] [review]
Add helper functions to set XDG dirs to a temporary directory

This is useful for unit tests not wanting to mess up user's files
Comment 3 Xavier Claessens 2012-04-16 11:40:38 UTC
This commit is a WIP, it already got some critics in bug #672985, that's why I'm proposing it in a separate bug to continue discussion separately.
Comment 4 Xavier Claessens 2012-04-19 12:35:41 UTC
Created attachment 212354 [details] [review]
Add helper functions to set XDG dirs to a temporary directory

This is useful for unit tests not wanting to mess up user's files
Comment 5 Allison Karlitskaya (desrt) 2012-12-24 13:53:09 UTC
If this is just about testing then I think with the changes to g_get_home_dir() to support HOME, this bug is obsolete?
Comment 6 Matthias Clasen 2013-01-01 15:11:11 UTC
marking as such, then
Comment 7 Xavier Claessens 2013-01-02 09:32:26 UTC
Not sure that's enough. What my patch does is also cleanup the tmp directory when the test is done, or even if it crash. Also, I think we need a way to make g_get_user_cache_dir() and friends reload their value, so each unit test can use a new directory to be sure they don't get data of previous test. Something like g_reload_user_special_dirs_cache().
Comment 8 Allison Karlitskaya (desrt) 2013-01-02 12:39:10 UTC
I think this belongs in a framework outside of GLib...
Comment 9 Dan Winship 2013-01-02 17:50:27 UTC
(In reply to comment #7)
> Not sure that's enough. What my patch does is also cleanup the tmp directory
> when the test is done, or even if it crash. Also, I think we need a way to make
> g_get_user_cache_dir() and friends reload their value, so each unit test can
> use a new directory to be sure they don't get data of previous test.

You can use g_test_trap_subprocess() once that lands (bug 679683) and just run each test in a separate subprocess, and have the parent test do the cleanup.
Comment 10 Xavier Claessens 2013-03-25 17:06:38 UTC
Created attachment 239792 [details] [review]
Add helper functions to set XDG dirs to a temporary directory

This is useful for unit tests not wanting to mess up user's files
Comment 11 Xavier Claessens 2013-03-25 17:20:06 UTC
@Dan, I don't see how bug #679683 has anything to do with this one.

I've made another patch, maybe that version is better? Note that EDS unit tests does something similar as well now that it uses GTestDBus.
Comment 12 Martyn Russell 2014-01-09 19:32:14 UTC
I use and wrote this for Tracker:
https://git.gnome.org/browse/tracker/tree/utils/sandbox/tracker-sandbox.py

It essentially creates entire DBus sessions and allows for starting a shell in that session by storing the details somewhere ... It's a bit crude, but it could be a start or help if you want to avoid the pitfalls I came across when developing this...

Anyway, happy to help :)
Comment 13 GNOME Infrastructure Team 2018-05-24 14:01:29 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/538.