Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / environ.exp
1 # Copyright 1997-2022 Free Software Foundation, Inc.
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_start
17
18 proc test_set_show_env_var { name value test_name } {
19 gdb_test_no_output "set environment $name $value" "$test_name"
20 gdb_test "show environment $name" "$name = $value" \
21 "confirm $test_name"
22 }
23
24 proc test_set_show_env_var_equal { name value test_name } {
25 gdb_test_no_output "set environment $name = $value" "$test_name"
26 gdb_test "show environment $name" "$name = $value" \
27 "confirm $test_name"
28 }
29
30 # Verify that we can show all currently-set environment variables.
31 # It's hard to do this verification since we can't really compare each
32 # entry with the current environment. So we just check to see if
33 # there is anything that looks like an environment variable being
34 # printed.
35 gdb_test "show environment" "(\[A-Za-z_\]+=.*)+" \
36 "show environment works"
37
38 # Verify that we can unset a specific environment variable.
39 gdb_test_no_output "unset environment EDITOR" "unset environment variable"
40
41 gdb_test "show environment EDITOR" "Environment variable \"EDITOR\" not defined\." \
42 "confirm unset environment variable worked"
43
44 # Verify that we can unset all environment variables.
45 gdb_test "unset environment" "" "unset all environment variables" \
46 "Delete all environment variables. .y or n. $" \
47 "y"
48
49 gdb_test_no_output "show environment" \
50 "all environment variables have been unset"
51
52 # Verify that we can set a specific environment variable.
53 test_set_show_env_var "EDITOR" "emacs" "set environment variable"
54
55 # Verify that GDB responds gracefully to a request to set environment,
56 # with no variable name.
57 gdb_test "set environment" "Argument required \\\(environment variable and value\\\)\." \
58 "set environment without arguments"
59
60 # I'm not sure just what GDB has in mind in explicitly checking
61 # for this variant, but since GDB handles it, test it.
62 gdb_test "set environment =" "Argument required \\\(environment variable to set\\\)\." \
63 "set environment without variable name"
64
65 # Setting an environment variable without a value sets it to a NULL
66 # value.
67 gdb_test "set environment EDITOR" "Setting environment variable \"EDITOR\" to null value\." \
68 "set environment variable to null value"
69 gdb_test "show environment EDITOR" "EDITOR = " "show null environment variable"
70
71 # Verify that GDB responds gracefully to an attempt to show a
72 # non-existent environment variable. (We hope this variable is
73 # undefined!)
74 gdb_test "show environment FOOBARBAZGRUNGESPAZBALL" \
75 "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined\." \
76 "show non-existent environment variable"
77
78 # Verify that GDB can set an environment variable hitherto undefined.
79 test_set_show_env_var "FOOBARBAZGRUNGESPAZBALL" "t" \
80 "set environment variable previously undefined"
81
82 # Verify that GDB can also set an environment variable using the "="
83 # syntax.
84 test_set_show_env_var_equal "FOOBARBAZGRUNGESPAZBALL" "y" \
85 "set environment variable using = syntax"
86
87 # Verify that GDB can set an environment variable to a value that has
88 # an embedded (trailing, in this case) equals.
89 test_set_show_env_var_equal "FOOBARBAZGRUNGESPAZBALL" "t=" \
90 "set environment variable with trailing equals"
91
92 # Verify that GDB can set an environment variable to a value preceded
93 # by whitespace, and that such whitespace is ignored (not included
94 # in the set value).
95 gdb_test_no_output "set environment FOOBARBAZGRUNGESPAZBALL = foo" \
96 "set environment variable with trailing whitespace"
97 gdb_test "show environment FOOBARBAZGRUNGESPAZBALL" \
98 "FOOBARBAZGRUNGESPAZBALL = foo" \
99 "confirm set environment variable with trailing whitespace"
100
101 # Verify that GDB can manipulate the distinguished PATH variable.
102 gdb_test "path /tmp/FOOBARBAZGRUNGESPAZBALL" \
103 "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*" \
104 "set path works properly"
105 gdb_test "show paths" \
106 "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*" \
107 "show paths works properly"
108
109 gdb_exit
110 return 0
This page took 0.031663 seconds and 4 git commands to generate.