Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1997-2020 Free Software Foundation, Inc. |
c906108c SS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
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. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 15 | |
45ce1b47 | 16 | gdb_start |
c906108c | 17 | |
45ce1b47 SDJ |
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" | |
c906108c | 22 | } |
c906108c | 23 | |
45ce1b47 SDJ |
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" | |
c906108c SS |
28 | } |
29 | ||
30 | # Verify that we can show all currently-set environment variables. | |
45ce1b47 SDJ |
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" | |
c906108c SS |
37 | |
38 | # Verify that we can unset a specific environment variable. | |
45ce1b47 SDJ |
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" | |
c906108c SS |
43 | |
44 | # Verify that we can unset all environment variables. | |
45ce1b47 SDJ |
45 | gdb_test "unset environment" "" "unset all environment variables" \ |
46 | "Delete all environment variables. .y or n. $" \ | |
47 | "y" | |
c906108c | 48 | |
206726fb SDJ |
49 | gdb_test_no_output "show environment" \ |
50 | "all environment variables have been unset" | |
51 | ||
c906108c | 52 | # Verify that we can set a specific environment variable. |
45ce1b47 | 53 | test_set_show_env_var "EDITOR" "emacs" "set environment variable" |
c906108c SS |
54 | |
55 | # Verify that GDB responds gracefully to a request to set environment, | |
56 | # with no variable name. | |
45ce1b47 SDJ |
57 | gdb_test "set environment" "Argument required \\\(environment variable and value\\\)\." \ |
58 | "set environment without arguments" | |
c906108c SS |
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. | |
45ce1b47 SDJ |
62 | gdb_test "set environment =" "Argument required \\\(environment variable to set\\\)\." \ |
63 | "set environment without variable name" | |
c906108c SS |
64 | |
65 | # Setting an environment variable without a value sets it to a NULL | |
66 | # value. | |
45ce1b47 SDJ |
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" | |
c906108c SS |
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!) | |
45ce1b47 SDJ |
74 | gdb_test "show environment FOOBARBAZGRUNGESPAZBALL" \ |
75 | "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined\." \ | |
76 | "show non-existent environment variable" | |
c906108c SS |
77 | |
78 | # Verify that GDB can set an environment variable hitherto undefined. | |
45ce1b47 SDJ |
79 | test_set_show_env_var "FOOBARBAZGRUNGESPAZBALL" "t" \ |
80 | "set environment variable previously undefined" | |
c906108c SS |
81 | |
82 | # Verify that GDB can also set an environment variable using the "=" | |
83 | # syntax. | |
45ce1b47 SDJ |
84 | test_set_show_env_var_equal "FOOBARBAZGRUNGESPAZBALL" "y" \ |
85 | "set environment variable using = syntax" | |
c906108c SS |
86 | |
87 | # Verify that GDB can set an environment variable to a value that has | |
88 | # an embedded (trailing, in this case) equals. | |
45ce1b47 SDJ |
89 | test_set_show_env_var_equal "FOOBARBAZGRUNGESPAZBALL" "t=" \ |
90 | "set environment variable with trailing equals" | |
c906108c SS |
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). | |
45ce1b47 SDJ |
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" | |
c906108c SS |
100 | |
101 | # Verify that GDB can manipulate the distinguished PATH variable. | |
45ce1b47 SDJ |
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" | |
c906108c SS |
108 | |
109 | gdb_exit | |
110 | return 0 |