]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/empty-host-env-vars.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / empty-host-env-vars.exp
CommitLineData
213516ef 1# Copyright 2021-2023 Free Software Foundation, Inc.
6abd4cf2
SM
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# GDB reads some environment variables on startup, make sure it behaves
17# correctly if these variables are defined but empty.
18
19set all_env_vars { HOME XDG_CACHE_HOME LOCALAPPDATA XDG_CONFIG_HOME }
20
21# Record the initial value of the index-cache directory.
22clean_restart
23set index_cache_directory ""
24gdb_test_multiple "show index-cache directory" "" {
25 -re -wrap "The directory of the index cache is \"(.*)\"\\." {
26 set index_cache_directory $expect_out(1,string)
27 set index_cache_directory [string_to_regexp $index_cache_directory]
28 pass $gdb_test_name
29 }
30}
31
32foreach_with_prefix env_var_name $all_env_vars {
33 # Restore the original state of the environment variable.
34 save_vars env($env_var_name) {
35 set env($env_var_name) {}
36 clean_restart
37
38 # Verify that the empty environment variable didn't affect the
39 # index-cache directory setting, that we still see the initial value.
40 # "HOME" is different, because if that one is unset, GDB isn't even
41 # able to compute the default location. In that case, we expect it to
42 # be empty.
43 if { $env_var_name == "HOME" } {
44 gdb_test "show index-cache directory" \
45 "The directory of the index cache is \"\"\\."
46 } else {
47 gdb_test "show index-cache directory" \
48 "The directory of the index cache is \"$index_cache_directory\"\\."
49 }
50 }
51}
52
53# Try the same, but with all the env vars set to an empty value at the same
54# time.
55with_test_prefix "all env vars" {
56 set save_vars_arg {}
57 foreach env_var_name $all_env_vars {
58 lappend save_vars_arg env($env_var_name)
59 }
60
61 # Restore the original state of all the environment variables.
62 save_vars $save_vars_arg {
63 foreach env_var_name $all_env_vars {
64 set env($env_var_name) {}
65 }
66
67 clean_restart
68
69 gdb_test "show index-cache directory" \
70 "The directory of the index cache is \"\"\\."
71 }
72}