0b69a80a902a2cd568939031705a723dd888401b
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / environ.exp
1 # Copyright 1997-2017 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 # Verify that we can set a specific environment variable.
50 test_set_show_env_var "EDITOR" "emacs" "set environment variable"
51
52 # Verify that GDB responds gracefully to a request to set environment,
53 # with no variable name.
54 gdb_test "set environment" "Argument required \\\(environment variable and value\\\)\." \
55 "set environment without arguments"
56
57 # I'm not sure just what GDB has in mind in explicitly checking
58 # for this variant, but since GDB handles it, test it.
59 gdb_test "set environment =" "Argument required \\\(environment variable to set\\\)\." \
60 "set environment without variable name"
61
62 # Setting an environment variable without a value sets it to a NULL
63 # value.
64 gdb_test "set environment EDITOR" "Setting environment variable \"EDITOR\" to null value\." \
65 "set environment variable to null value"
66 gdb_test "show environment EDITOR" "EDITOR = " "show null environment variable"
67
68 # Verify that GDB responds gracefully to an attempt to show a
69 # non-existent environment variable. (We hope this variable is
70 # undefined!)
71 gdb_test "show environment FOOBARBAZGRUNGESPAZBALL" \
72 "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined\." \
73 "show non-existent environment variable"
74
75 # Verify that GDB can set an environment variable hitherto undefined.
76 test_set_show_env_var "FOOBARBAZGRUNGESPAZBALL" "t" \
77 "set environment variable previously undefined"
78
79 # Verify that GDB can also set an environment variable using the "="
80 # syntax.
81 test_set_show_env_var_equal "FOOBARBAZGRUNGESPAZBALL" "y" \
82 "set environment variable using = syntax"
83
84 # Verify that GDB can set an environment variable to a value that has
85 # an embedded (trailing, in this case) equals.
86 test_set_show_env_var_equal "FOOBARBAZGRUNGESPAZBALL" "t=" \
87 "set environment variable with trailing equals"
88
89 # Verify that GDB can set an environment variable to a value preceded
90 # by whitespace, and that such whitespace is ignored (not included
91 # in the set value).
92 gdb_test_no_output "set environment FOOBARBAZGRUNGESPAZBALL = foo" \
93 "set environment variable with trailing whitespace"
94 gdb_test "show environment FOOBARBAZGRUNGESPAZBALL" \
95 "FOOBARBAZGRUNGESPAZBALL = foo" \
96 "confirm set environment variable with trailing whitespace"
97
98 # Verify that GDB can manipulate the distinguished PATH variable.
99 gdb_test "path /tmp/FOOBARBAZGRUNGESPAZBALL" \
100 "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*" \
101 "set path works properly"
102 gdb_test "show paths" \
103 "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*" \
104 "show paths works properly"
105
106 gdb_exit
107 return 0
This page took 0.03764 seconds and 4 git commands to generate.