File: tests-Use-G_TEST_OPTION_ISOLATE_DIRS-for-utils-tests.patch

package info (click to toggle)
glib2.0 2.86.0-6
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 74,852 kB
  • sloc: ansic: 544,570; python: 9,702; sh: 1,612; xml: 1,482; perl: 1,222; cpp: 535; makefile: 321; javascript: 11
file content (246 lines) | stat: -rw-r--r-- 6,984 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
From: Philip Withnall <pwithnall@gnome.org>
Date: Fri, 19 Sep 2025 11:42:46 +0100
Subject: tests: Use G_TEST_OPTION_ISOLATE_DIRS for utils tests

Another test isolated.

This does mean moving one of the test cases from the suite out into a
separate suite, as it explicitly relies on running without
`G_TEST_OPTION_ISOLATE_DIRS`, and I think that makes sense. The other
test cases run fine when isolated.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Origin: upstream, 2.86.1, commit:133aed18752f0d7af761a38f39f8dbb7ba90c967
---
 glib/tests/meson.build        |   1 +
 glib/tests/utils-unisolated.c | 110 ++++++++++++++++++++++++++++++++++++++++++
 glib/tests/utils.c            |  73 +---------------------------
 3 files changed, 112 insertions(+), 72 deletions(-)
 create mode 100644 glib/tests/utils-unisolated.c

diff --git a/glib/tests/meson.build b/glib/tests/meson.build
index 76b0311..564497c 100644
--- a/glib/tests/meson.build
+++ b/glib/tests/meson.build
@@ -185,6 +185,7 @@ glib_tests = {
     'c_standards': c_standards.keys(),
   },
   'utils-isolated' : {},
+  'utils-unisolated' : {},
   'unicode' : {},
   'unicode-encoding' : {},
   'unicode-normalize': {},
diff --git a/glib/tests/utils-unisolated.c b/glib/tests/utils-unisolated.c
new file mode 100644
index 0000000..01d4a3b
--- /dev/null
+++ b/glib/tests/utils-unisolated.c
@@ -0,0 +1,110 @@
+/* Unit tests for utilities
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * SPDX-License-Identifier: LicenseRef-old-glib-tests
+ *
+ * This work is provided "as is"; redistribution and modification
+ * in whole or in part, in any medium, physical or electronic is
+ * permitted without restriction.
+ *
+ * This work is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * In no event shall the authors or contributors be liable for any
+ * direct, indirect, incidental, special, exemplary, or consequential
+ * damages (including, but not limited to, procurement of substitute
+ * goods or services; loss of use, data, or profits; or business
+ * interruption) however caused and on any theory of liability, whether
+ * in contract, strict liability, or tort (including negligence or
+ * otherwise) arising in any way out of the use of this software, even
+ * if advised of the possibility of such damage.
+ *
+ * Author: Matthias Clasen
+ */
+
+#include "glib.h"
+
+static void
+test_xdg_dirs (void)
+{
+#ifdef G_OS_UNIX
+  char *xdg = NULL;
+  const char *dir;
+  const char * const *dirs;
+  char *s = NULL;
+
+  xdg = g_strdup (g_getenv ("XDG_CONFIG_HOME"));
+  if (!xdg)
+    xdg = g_build_filename (g_get_home_dir (), ".config", NULL);
+
+  dir = g_get_user_config_dir ();
+
+  g_assert_cmpstr (dir, ==, xdg);
+  g_free (xdg);
+
+  xdg = g_strdup (g_getenv ("XDG_DATA_HOME"));
+  if (!xdg)
+    xdg = g_build_filename (g_get_home_dir (), ".local", "share", NULL);
+
+  dir = g_get_user_data_dir ();
+
+  g_assert_cmpstr (dir, ==, xdg);
+  g_free (xdg);
+
+  xdg = g_strdup (g_getenv ("XDG_CACHE_HOME"));
+  if (!xdg)
+    xdg = g_build_filename (g_get_home_dir (), ".cache", NULL);
+
+  dir = g_get_user_cache_dir ();
+
+  g_assert_cmpstr (dir, ==, xdg);
+  g_free (xdg);
+
+  xdg = g_strdup (g_getenv ("XDG_STATE_HOME"));
+  if (!xdg)
+    xdg = g_build_filename (g_get_home_dir (), ".local/state", NULL);
+
+  dir = g_get_user_state_dir ();
+
+  g_assert_cmpstr (dir, ==, xdg);
+  g_free (xdg);
+
+  xdg = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
+  if (!xdg)
+    xdg = g_strdup (g_get_user_cache_dir ());
+
+  dir = g_get_user_runtime_dir ();
+
+  g_assert_cmpstr (dir, ==, xdg);
+  g_free (xdg);
+
+  xdg = (gchar *)g_getenv ("XDG_CONFIG_DIRS");
+  if (!xdg)
+    xdg = "/etc/xdg";
+
+  dirs = g_get_system_config_dirs ();
+
+  s = g_strjoinv (":", (gchar **)dirs);
+
+  g_assert_cmpstr (s, ==, xdg);
+
+  g_free (s);
+#else
+  g_test_skip ("User special dirs are not defined using environment variables on non-Unix systems");
+#endif
+}
+
+int
+main (int   argc,
+      char *argv[])
+{
+  /* Note: We do *not* use G_TEST_OPTION_ISOLATE_DIRS here, as we want to test
+   * the calculation of the XDG dirs from a real environment. */
+  g_test_init (&argc, &argv, NULL);
+
+  /* You almost certainly want to add a test to glib/tests/utils.c instead of here. */
+  g_test_add_func ("/utils/xdgdirs", test_xdg_dirs);
+
+  return g_test_run ();
+}
diff --git a/glib/tests/utils.c b/glib/tests/utils.c
index 1e7ec41..97148b8 100644
--- a/glib/tests/utils.c
+++ b/glib/tests/utils.c
@@ -817,74 +817,6 @@ test_hostname (void)
   g_assert_true (g_utf8_validate (name, -1, NULL));
 }
 
-#ifdef G_OS_UNIX
-static void
-test_xdg_dirs (void)
-{
-  gchar *xdg;
-  const gchar *dir;
-  const gchar * const *dirs;
-  gchar *s;
-
-  xdg = g_strdup (g_getenv ("XDG_CONFIG_HOME"));
-  if (!xdg)
-    xdg = g_build_filename (g_get_home_dir (), ".config", NULL);
-
-  dir = g_get_user_config_dir ();
-
-  g_assert_cmpstr (dir, ==, xdg);
-  g_free (xdg);
-
-  xdg = g_strdup (g_getenv ("XDG_DATA_HOME"));
-  if (!xdg)
-    xdg = g_build_filename (g_get_home_dir (), ".local", "share", NULL);
-
-  dir = g_get_user_data_dir ();
-
-  g_assert_cmpstr (dir, ==, xdg);
-  g_free (xdg);
-
-  xdg = g_strdup (g_getenv ("XDG_CACHE_HOME"));
-  if (!xdg)
-    xdg = g_build_filename (g_get_home_dir (), ".cache", NULL);
-
-  dir = g_get_user_cache_dir ();
-
-  g_assert_cmpstr (dir, ==, xdg);
-  g_free (xdg);
-
-  xdg = g_strdup (g_getenv ("XDG_STATE_HOME"));
-  if (!xdg)
-    xdg = g_build_filename (g_get_home_dir (), ".local/state", NULL);
-
-  dir = g_get_user_state_dir ();
-
-  g_assert_cmpstr (dir, ==, xdg);
-  g_free (xdg);
-
-  xdg = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
-  if (!xdg)
-    xdg = g_strdup (g_get_user_cache_dir ());
-
-  dir = g_get_user_runtime_dir ();
-
-  g_assert_cmpstr (dir, ==, xdg);
-  g_free (xdg);
-
-  xdg = (gchar *)g_getenv ("XDG_CONFIG_DIRS");
-  if (!xdg)
-    xdg = "/etc/xdg";
-
-  dirs = g_get_system_config_dirs ();
-
-  s = g_strjoinv (":", (gchar **)dirs);
-
-  g_assert_cmpstr (s, ==, xdg);
-
-  g_free (s);
-}
-#endif
-
 static void
 test_special_dir (void)
 {
@@ -1353,7 +1285,7 @@ main (int   argc,
    */
   g_set_prgname (argv[0]);
 
-  g_test_init (&argc, &argv, NULL);
+  g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
 
   g_test_add_func ("/utils/language-names", test_language_names);
   g_test_add_func ("/utils/locale-variants", test_locale_variants);
@@ -1374,9 +1306,6 @@ main (int   argc,
   g_test_add_func ("/utils/username", test_username);
   g_test_add_func ("/utils/realname", test_realname);
   g_test_add_func ("/utils/hostname", test_hostname);
-#ifdef G_OS_UNIX
-  g_test_add_func ("/utils/xdgdirs", test_xdg_dirs);
-#endif
   g_test_add_func ("/utils/specialdir", test_special_dir);
   g_test_add_func ("/utils/specialdir/desktop", test_desktop_special_dir);
   g_test_add_func ("/utils/os-info", test_os_info);