My agentic slop goes here. Not intended for anyone else!
1Test with default directories:
2
3 $ export HOME=./test_home
4 $ unset XDG_CONFIG_HOME XDG_DATA_HOME XDG_CACHE_HOME XDG_STATE_HOME XDG_RUNTIME_DIR
5 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
6 $ ../example/xdg_example.exe
7 === Cmdliner Config ===
8 XDG config:
9
10 === XDG Directories ===
11 XDG directories for 'xdg_example':
12 User directories:
13 config: <fs:./test_home/./test_home/.config/xdg_example> [default]
14 data: <fs:./test_home/./test_home/.local/share/xdg_example> [default]
15 cache: <fs:./test_home/./test_home/.cache/xdg_example> [default]
16 state: <fs:./test_home/./test_home/.local/state/xdg_example> [default]
17 runtime: <none> [default]
18 System directories:
19 config_dirs: [<fs:/etc/xdg/xdg_example>]
20 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
21
22This test is correct: No command-line args or env vars are set, so all directories
23use defaults. Config shows empty (no overrides), and directories show [default] source.
24User directories follow XDG spec: ~/.config, ~/.local/share, ~/.cache, ~/.local/state.
25Runtime dir is <none> since XDG_RUNTIME_DIR has no default.
26System dirs use XDG spec defaults: /etc/xdg for config, /usr/{local/,}share for data.
27
28Test with all command line arguments specified
29 $ unset XDG_CONFIG_HOME XDG_DATA_HOME XDG_CACHE_HOME XDG_STATE_HOME XDG_RUNTIME_DIR
30 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
31 $ ../example/xdg_example.exe \
32 > --config-dir ./test-config \
33 > --data-dir ./test-data \
34 > --cache-dir ./test-cache \
35 > --state-dir ./test-state \
36 > --runtime-dir ./test-runtime
37 === Cmdliner Config ===
38 XDG config:
39 config_dir: ./test-config [cmdline]
40 data_dir: ./test-data [cmdline]
41 cache_dir: ./test-cache [cmdline]
42 state_dir: ./test-state [cmdline]
43 runtime_dir: ./test-runtime [cmdline]
44
45 === XDG Directories ===
46 XDG directories for 'xdg_example':
47 User directories:
48 config: <fs:./test_home/./test-config> [cmdline]
49 data: <fs:./test_home/./test-data> [cmdline]
50 cache: <fs:./test_home/./test-cache> [cmdline]
51 state: <fs:./test_home/./test-state> [cmdline]
52 runtime: <fs:./test_home/./test-runtime> [cmdline]
53 System directories:
54 config_dirs: [<fs:/etc/xdg/xdg_example>]
55 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
56
57This test is correct: All user directories are overridden by command-line arguments,
58showing [cmdline] as the source. The config section shows all overrides with their
59values and [cmdline] sources. System directories remain at their defaults since
60they cannot be overridden by user directories command-line options.
61
62Test with environment variables (app-specific)
63 $ XDG_EXAMPLE_CONFIG_DIR=./env-config \
64 > XDG_EXAMPLE_DATA_DIR=./env-data \
65 > XDG_EXAMPLE_CACHE_DIR=./env-cache \
66 > XDG_EXAMPLE_STATE_DIR=./env-state \
67 > XDG_EXAMPLE_RUNTIME_DIR=./env-runtime \
68 > ../example/xdg_example.exe
69 === Cmdliner Config ===
70 XDG config:
71 config_dir: ./env-config [env(XDG_EXAMPLE_CONFIG_DIR)]
72 data_dir: ./env-data [env(XDG_EXAMPLE_DATA_DIR)]
73 cache_dir: ./env-cache [env(XDG_EXAMPLE_CACHE_DIR)]
74 state_dir: ./env-state [env(XDG_EXAMPLE_STATE_DIR)]
75 runtime_dir: ./env-runtime [env(XDG_EXAMPLE_RUNTIME_DIR)]
76
77 === XDG Directories ===
78 XDG directories for 'xdg_example':
79 User directories:
80 config: <fs:./test_home/./env-config> [env(XDG_EXAMPLE_CONFIG_DIR)]
81 data: <fs:./test_home/./env-data> [env(XDG_EXAMPLE_DATA_DIR)]
82 cache: <fs:./test_home/./env-cache> [env(XDG_EXAMPLE_CACHE_DIR)]
83 state: <fs:./test_home/./env-state> [env(XDG_EXAMPLE_STATE_DIR)]
84 runtime: <fs:./test_home/./env-runtime> [env(XDG_EXAMPLE_RUNTIME_DIR)]
85 System directories:
86 config_dirs: [<fs:/etc/xdg/xdg_example>]
87 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
88
89This test is correct: App-specific environment variables (XDG_EXAMPLE_*) override
90the defaults. The source correctly shows [env(XDG_EXAMPLE_*)] for each variable.
91These app-specific variables take precedence over XDG standard variables when both
92are available, allowing per-application customization.
93
94Test with standard XDG environment variables:
95
96 $ XDG_CONFIG_HOME=/tmp/xdge/xdg-config \
97 > XDG_DATA_HOME=/tmp/xdge/xdg-data \
98 > XDG_CACHE_HOME=/tmp/xdge/xdg-cache \
99 > XDG_STATE_HOME=/tmp/xdge/xdg-state \
100 > XDG_RUNTIME_DIR=/tmp/xdge/xdg-runtime \
101 > ../example/xdg_example.exe
102 === Cmdliner Config ===
103 XDG config:
104 config_dir: /tmp/xdge/xdg-config [env(XDG_CONFIG_HOME)]
105 data_dir: /tmp/xdge/xdg-data [env(XDG_DATA_HOME)]
106 cache_dir: /tmp/xdge/xdg-cache [env(XDG_CACHE_HOME)]
107 state_dir: /tmp/xdge/xdg-state [env(XDG_STATE_HOME)]
108 runtime_dir: /tmp/xdge/xdg-runtime [env(XDG_RUNTIME_DIR)]
109
110 === XDG Directories ===
111 XDG directories for 'xdg_example':
112 User directories:
113 config: <fs:/tmp/xdge/xdg-config> [env(XDG_CONFIG_HOME)]
114 data: <fs:/tmp/xdge/xdg-data> [env(XDG_DATA_HOME)]
115 cache: <fs:/tmp/xdge/xdg-cache> [env(XDG_CACHE_HOME)]
116 state: <fs:/tmp/xdge/xdg-state> [env(XDG_STATE_HOME)]
117 runtime: <fs:/tmp/xdge/xdg-runtime> [env(XDG_RUNTIME_DIR)]
118 System directories:
119 config_dirs: [<fs:/etc/xdg/xdg_example>]
120 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
121
122This test is correct: Standard XDG environment variables (XDG_*_HOME, XDG_RUNTIME_DIR)
123override the defaults. The source correctly shows [env(XDG_*)] for each variable.
124Note that the user directories use the raw paths from env vars (not app-specific subdirs)
125since XDG_CONFIG_HOME etc. are intended to be the base directories for the user.
126
127Test command line overrides environment variables:
128
129 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
130 $ XDG_EXAMPLE_CONFIG_DIR=./env-config \
131 > ../example/xdg_example.exe --config-dir ./cli-config
132 === Cmdliner Config ===
133 XDG config:
134 config_dir: ./cli-config [cmdline]
135
136 === XDG Directories ===
137 XDG directories for 'xdg_example':
138 User directories:
139 config: <fs:./test_home/./cli-config> [cmdline]
140 data: <fs:./test_home/./test_home/.local/share/xdg_example> [default]
141 cache: <fs:./test_home/./test_home/.cache/xdg_example> [default]
142 state: <fs:./test_home/./test_home/.local/state/xdg_example> [default]
143 runtime: <none> [default]
144 System directories:
145 config_dirs: [<fs:/etc/xdg/xdg_example>]
146 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
147
148This test is correct: Command-line arguments have highest precedence, overriding
149environment variables. Only config_dir is shown in the config section since it is
150the only one explicitly set. The config_dir shows [cmdline] source while other
151directories fall back to defaults, demonstrating the precedence hierarchy:
152of cmdline then app env vars then XDG env vars then defaults.
153
154Test mixed environment variable precedence (app-specific overrides XDG standard):
155
156 $ export HOME=./test_home
157 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
158 $ XDG_CONFIG_HOME=/tmp/xdge/xdg-config \
159 > XDG_EXAMPLE_CONFIG_DIR=./app-config \
160 > XDG_DATA_HOME=/tmp/xdge/xdg-data \
161 > XDG_EXAMPLE_DATA_DIR=./app-data \
162 > ../example/xdg_example.exe
163 === Cmdliner Config ===
164 XDG config:
165 config_dir: ./app-config [env(XDG_EXAMPLE_CONFIG_DIR)]
166 data_dir: ./app-data [env(XDG_EXAMPLE_DATA_DIR)]
167
168 === XDG Directories ===
169 XDG directories for 'xdg_example':
170 User directories:
171 config: <fs:./test_home/./app-config> [env(XDG_EXAMPLE_CONFIG_DIR)]
172 data: <fs:./test_home/./app-data> [env(XDG_EXAMPLE_DATA_DIR)]
173 cache: <fs:./test_home/./test_home/.cache/xdg_example> [default]
174 state: <fs:./test_home/./test_home/.local/state/xdg_example> [default]
175 runtime: <none> [default]
176 System directories:
177 config_dirs: [<fs:/etc/xdg/xdg_example>]
178 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
179
180This test is correct: Demonstrates app-specific environment variables taking
181precedence over XDG standard ones. Both XDG_CONFIG_HOME and XDG_EXAMPLE_CONFIG_DIR
182are set, but the app-specific one wins. Same for data directories. Cache, state,
183and runtime fall back to defaults since no variables are set for them.
184
185Test partial environment variable override:
186
187 $ export HOME=./test_home
188 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
189 $ XDG_EXAMPLE_CONFIG_DIR=./app-config \
190 > XDG_DATA_HOME=/tmp/xdge/xdg-data \
191 > XDG_CACHE_HOME=/tmp/xdge/xdg-cache \
192 > ../example/xdg_example.exe
193 === Cmdliner Config ===
194 XDG config:
195 config_dir: ./app-config [env(XDG_EXAMPLE_CONFIG_DIR)]
196 data_dir: /tmp/xdge/xdg-data [env(XDG_DATA_HOME)]
197 cache_dir: /tmp/xdge/xdg-cache [env(XDG_CACHE_HOME)]
198
199 === XDG Directories ===
200 XDG directories for 'xdg_example':
201 User directories:
202 config: <fs:./test_home/./app-config> [env(XDG_EXAMPLE_CONFIG_DIR)]
203 data: <fs:/tmp/xdge/xdg-data> [env(XDG_DATA_HOME)]
204 cache: <fs:/tmp/xdge/xdg-cache> [env(XDG_CACHE_HOME)]
205 state: <fs:./test_home/./test_home/.local/state/xdg_example> [default]
206 runtime: <none> [default]
207 System directories:
208 config_dirs: [<fs:/etc/xdg/xdg_example>]
209 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
210
211This test is correct: Shows mixed sources working together. Config uses app-specific
212env var (highest priority among env vars), data and cache use XDG standard env vars
213(no app-specific ones set), and state uses default (no env vars set). Each directory
214gets its value from the highest-priority available source.
215
216Test command line overrides mixed environment variables:
217
218 $ export HOME=./test_home
219 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
220 $ XDG_CONFIG_HOME=/tmp/xdge/xdg-config \
221 > XDG_EXAMPLE_CONFIG_DIR=./app-config \
222 > ../example/xdg_example.exe --config-dir ./cli-config
223 === Cmdliner Config ===
224 XDG config:
225 config_dir: ./cli-config [cmdline]
226
227 === XDG Directories ===
228 XDG directories for 'xdg_example':
229 User directories:
230 config: <fs:./test_home/./cli-config> [cmdline]
231 data: <fs:./test_home/./test_home/.local/share/xdg_example> [default]
232 cache: <fs:./test_home/./test_home/.cache/xdg_example> [default]
233 state: <fs:./test_home/./test_home/.local/state/xdg_example> [default]
234 runtime: <none> [default]
235 System directories:
236 config_dirs: [<fs:/etc/xdg/xdg_example>]
237 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
238
239This test is correct: Command-line argument overrides both types of environment
240variables. Even though both XDG_CONFIG_HOME and XDG_EXAMPLE_CONFIG_DIR are set,
241the --config-dir flag takes precedence and shows [cmdline] source. Other directories
242fall back to defaults since no other command-line args are provided.
243
244
245Test empty environment variable handling:
246 $ export HOME=./test_home
247 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
248 $ XDG_EXAMPLE_CONFIG_DIR="" \
249 > XDG_CONFIG_HOME=/tmp/xdge/xdg-config \
250 > ../example/xdg_example.exe
251 === Cmdliner Config ===
252 XDG config:
253 config_dir: /tmp/xdge/xdg-config [env(XDG_CONFIG_HOME)]
254
255 === XDG Directories ===
256 XDG directories for 'xdg_example':
257 User directories:
258 config: <fs:/tmp/xdge/xdg-config> [env(XDG_CONFIG_HOME)]
259 data: <fs:./test_home/./test_home/.local/share/xdg_example> [default]
260 cache: <fs:./test_home/./test_home/.cache/xdg_example> [default]
261 state: <fs:./test_home/./test_home/.local/state/xdg_example> [default]
262 runtime: <none> [default]
263 System directories:
264 config_dirs: [<fs:/etc/xdg/xdg_example>]
265 data_dirs: [<fs:/usr/local/share/xdg_example>; <fs:/usr/share/xdg_example>]
266
267This test is correct: When an app-specific env var is empty (""), it falls back to
268the XDG standard variable. XDG_EXAMPLE_CONFIG_DIR="" is ignored, so XDG_CONFIG_HOME
269is used instead, correctly showing [env(XDG_CONFIG_HOME)] as the source.
270This behavior ensures that empty app-specific variables do not override useful
271XDG standard settings.
272
273
274Test system directory environment variables:
275
276 $ export HOME=./test_home
277 $ unset XDG_CONFIG_HOME XDG_DATA_HOME XDG_CACHE_HOME XDG_STATE_HOME XDG_RUNTIME_DIR
278 $ XDG_CONFIG_DIRS=/tmp/xdge/sys1:/tmp/xdge/sys2 \
279 > XDG_DATA_DIRS=/tmp/xdge/data1:/tmp/xdge/data2 \
280 > ../example/xdg_example.exe
281 === Cmdliner Config ===
282 XDG config:
283
284 === XDG Directories ===
285 XDG directories for 'xdg_example':
286 User directories:
287 config: <fs:./test_home/./test_home/.config/xdg_example> [default]
288 data: <fs:./test_home/./test_home/.local/share/xdg_example> [default]
289 cache: <fs:./test_home/./test_home/.cache/xdg_example> [default]
290 state: <fs:./test_home/./test_home/.local/state/xdg_example> [default]
291 runtime: <none> [default]
292 System directories:
293 config_dirs: [<fs:/tmp/xdge/sys1/xdg_example>;
294 <fs:/tmp/xdge/sys2/xdg_example>]
295 data_dirs: [<fs:/tmp/xdge/data1/xdg_example>;
296 <fs:/tmp/xdge/data2/xdg_example>]
297
298This test is correct: XDG_CONFIG_DIRS and XDG_DATA_DIRS environment variables
299override the default system directories. The colon-separated paths are parsed
300and the app name is appended to each path. User directories remain at defaults
301since no user-level overrides are provided. System directory env vars only
302affect the system directories, not user directories.
303
304
305Test help message:
306
307 $ ../example/xdg_example.exe --help=plain | head -20
308 NAME
309 xdg_example - Example program demonstrating XDG directory selection
310 with Cmdliner
311
312 SYNOPSIS
313 xdg_example [OPTION]…
314
315 DESCRIPTION
316 This example shows how to use the Xdge library with Cmdliner to handle
317 XDG Base Directory Specification paths with command-line and
318 environment variable overrides.
319
320 OPTIONS
321 --cache-dir=DIR
322 Override cache directory. Can also be set with
323 XDG_EXAMPLE_CACHE_DIR or XDG_CACHE_HOME. Default:
324 $HOME/.cache/xdg_example
325
326 --config-dir=DIR
327 Override config directory. Can also be set with
328
329Test _path functions do not create directories but can access files within them:
330
331 $ export HOME=/tmp/xdge/xdg_path_test
332 $ mkdir -p /tmp/xdge/xdg_path_test
333 $ unset XDG_CONFIG_HOME XDG_DATA_HOME XDG_CACHE_HOME XDG_STATE_HOME XDG_RUNTIME_DIR
334 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
335Create config subdirectory manually and write a test file:
336 $ mkdir -p "/tmp/xdge/xdg_path_test/.config/path_test/profiles"
337 $ echo "test profile content" > "/tmp/xdge/xdg_path_test/.config/path_test/profiles/default.json"
338Create data subdirectory manually and write a test file:
339 $ mkdir -p "/tmp/xdge/xdg_path_test/.local/share/path_test/databases"
340 $ echo "test database content" > "/tmp/xdge/xdg_path_test/.local/share/path_test/databases/main.db"
341Create cache subdirectory manually and write a test file:
342 $ mkdir -p "/tmp/xdge/xdg_path_test/.cache/path_test/thumbnails"
343 $ echo "test cache content" > "/tmp/xdge/xdg_path_test/.cache/path_test/thumbnails/thumb1.png"
344Create state subdirectory manually and write a test file:
345 $ mkdir -p "/tmp/xdge/xdg_path_test/.local/state/path_test/logs"
346 $ echo "test log content" > "/tmp/xdge/xdg_path_test/.local/state/path_test/logs/app.log"
347
348Now test that we can read the files through the XDG _path functions:
349 $ ./test_paths.exe
350 config file content: test profile content
351 data file content: test database content
352 cache file content: test cache content
353 state file content: test log content
354
355This test verifies that the _path functions return correct paths that can be used to access
356files within XDG subdirectories, without the functions automatically creating those directories.
357
358Test path resolution with --show-paths:
359
360Test with a preset HOME to verify correct path resolution:
361 $ export HOME=./home_testuser
362 $ unset XDG_CONFIG_HOME XDG_DATA_HOME XDG_CACHE_HOME XDG_STATE_HOME XDG_RUNTIME_DIR
363 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
364 $ ../example/xdg_example.exe --show-paths
365 config_dir: ./home_testuser/./home_testuser/.config/xdg_example
366 data_dir: ./home_testuser/./home_testuser/.local/share/xdg_example
367 cache_dir: ./home_testuser/./home_testuser/.cache/xdg_example
368 state_dir: ./home_testuser/./home_testuser/.local/state/xdg_example
369 runtime_dir: <none>
370 config_dirs: /etc/xdg/xdg_example
371 data_dirs: /usr/local/share/xdg_example:/usr/share/xdg_example
372
373Test with environment variables set:
374 $ export HOME=./home_testuser
375 $ export XDG_CONFIG_HOME=/tmp/xdge/config
376 $ export XDG_DATA_HOME=/tmp/xdge/data
377 $ export XDG_CACHE_HOME=/tmp/xdge/cache
378 $ export XDG_STATE_HOME=/tmp/xdge/state
379 $ export XDG_CONFIG_DIRS=/tmp/xdge/config1:/tmp/xdge/config2
380 $ export XDG_DATA_DIRS=/tmp/xdge/data1:/tmp/xdge/data2
381 $ ../example/xdg_example.exe --show-paths
382 config_dir: /tmp/xdge/config
383 data_dir: /tmp/xdge/data
384 cache_dir: /tmp/xdge/cache
385 state_dir: /tmp/xdge/state
386 runtime_dir: <none>
387 config_dirs: /tmp/xdge/config1/xdg_example:/tmp/xdge/config2/xdg_example
388 data_dirs: /tmp/xdge/data1/xdg_example:/tmp/xdge/data2/xdg_example
389
390Test with command-line overrides:
391 $ export HOME=./home_testuser
392 $ unset XDG_CONFIG_HOME XDG_DATA_HOME XDG_CACHE_HOME XDG_STATE_HOME XDG_RUNTIME_DIR
393 $ unset XDG_CONFIG_DIRS XDG_DATA_DIRS
394 $ ../example/xdg_example.exe --show-paths --config-dir ./override/config --data-dir ./override/data
395 config_dir: ./home_testuser/./override/config
396 data_dir: ./home_testuser/./override/data
397 cache_dir: ./home_testuser/./home_testuser/.cache/xdg_example
398 state_dir: ./home_testuser/./home_testuser/.local/state/xdg_example
399 runtime_dir: <none>
400 config_dirs: /etc/xdg/xdg_example
401 data_dirs: /usr/local/share/xdg_example:/usr/share/xdg_example
402