]> 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
1d506c26 1# Copyright 2021-2024 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
8de9b683
SL
16# This test assumes host == build.
17require {!is_remote host}
18
6abd4cf2
SM
19# GDB reads some environment variables on startup, make sure it behaves
20# correctly if these variables are defined but empty.
21
22set all_env_vars { HOME XDG_CACHE_HOME LOCALAPPDATA XDG_CONFIG_HOME }
23
24# Record the initial value of the index-cache directory.
25clean_restart
26set index_cache_directory ""
27gdb_test_multiple "show index-cache directory" "" {
28 -re -wrap "The directory of the index cache is \"(.*)\"\\." {
29 set index_cache_directory $expect_out(1,string)
30 set index_cache_directory [string_to_regexp $index_cache_directory]
31 pass $gdb_test_name
32 }
33}
34
35foreach_with_prefix env_var_name $all_env_vars {
36 # Restore the original state of the environment variable.
37 save_vars env($env_var_name) {
38 set env($env_var_name) {}
39 clean_restart
40
41 # Verify that the empty environment variable didn't affect the
42 # index-cache directory setting, that we still see the initial value.
43 # "HOME" is different, because if that one is unset, GDB isn't even
44 # able to compute the default location. In that case, we expect it to
45 # be empty.
46 if { $env_var_name == "HOME" } {
47 gdb_test "show index-cache directory" \
48 "The directory of the index cache is \"\"\\."
49 } else {
50 gdb_test "show index-cache directory" \
51 "The directory of the index cache is \"$index_cache_directory\"\\."
52 }
53 }
54}
55
56# Try the same, but with all the env vars set to an empty value at the same
57# time.
58with_test_prefix "all env vars" {
59 set save_vars_arg {}
60 foreach env_var_name $all_env_vars {
61 lappend save_vars_arg env($env_var_name)
62 }
63
64 # Restore the original state of all the environment variables.
65 save_vars $save_vars_arg {
66 foreach env_var_name $all_env_vars {
67 set env($env_var_name) {}
68 }
69
70 clean_restart
71
72 gdb_test "show index-cache directory" \
73 "The directory of the index cache is \"\"\\."
74 }
75}