1 # Copyright 2021-2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # GDB reads some environment variables on startup, make sure it behaves
17 # correctly if these variables are defined but empty.
19 set all_env_vars { HOME XDG_CACHE_HOME LOCALAPPDATA XDG_CONFIG_HOME }
21 # Record the initial value of the index-cache directory.
23 set index_cache_directory ""
24 gdb_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]
32 foreach_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) {}
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
43 if { $env_var_name == "HOME" } {
44 gdb_test "show index-cache directory" \
45 "The directory of the index cache is \"\"\\."
47 gdb_test "show index-cache directory" \
48 "The directory of the index cache is \"$index_cache_directory\"\\."
53 # Try the same, but with all the env vars set to an empty value at the same
55 with_test_prefix "all env vars" {
57 foreach env_var_name $all_env_vars {
58 lappend save_vars_arg env($env_var_name)
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) {}
69 gdb_test "show index-cache directory" \
70 "The directory of the index cache is \"\"\\."