summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/environ.exp
blob: e4b5cc5f414a629cabb713fe2ef32e1a7f270321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright 1997-2018 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

gdb_start

proc test_set_show_env_var { name value test_name } {
    gdb_test_no_output "set environment $name $value" "$test_name"
    gdb_test "show environment $name" "$name = $value" \
	"confirm $test_name"
}

proc test_set_show_env_var_equal { name value test_name } {
    gdb_test_no_output "set environment $name = $value" "$test_name"
    gdb_test "show environment $name" "$name = $value" \
	"confirm $test_name"
}

# Verify that we can show all currently-set environment variables.
# It's hard to do this verification since we can't really compare each
# entry with the current environment.  So we just check to see if
# there is anything that looks like an environment variable being
# printed.
gdb_test "show environment" "(\[A-Za-z_\]+=.*)+" \
    "show environment works"

# Verify that we can unset a specific environment variable.
gdb_test_no_output "unset environment EDITOR" "unset environment variable"

gdb_test "show environment EDITOR" "Environment variable \"EDITOR\" not defined\." \
    "confirm unset environment variable worked"

# Verify that we can unset all environment variables.
gdb_test "unset environment" "" "unset all environment variables" \
    "Delete all environment variables. .y or n. $" \
    "y"

gdb_test_no_output "show environment" \
    "all environment variables have been unset"

# Verify that we can set a specific environment variable.
test_set_show_env_var "EDITOR" "emacs" "set environment variable"

# Verify that GDB responds gracefully to a request to set environment,
# with no variable name.
gdb_test "set environment" "Argument required \\\(environment variable and value\\\)\." \
    "set environment without arguments"

# I'm not sure just what GDB has in mind in explicitly checking
# for this variant, but since GDB handles it, test it.
gdb_test "set environment =" "Argument required \\\(environment variable to set\\\)\." \
    "set environment without variable name"

# Setting an environment variable without a value sets it to a NULL
# value.
gdb_test "set environment EDITOR" "Setting environment variable \"EDITOR\" to null value\." \
    "set environment variable to null value"
gdb_test "show environment EDITOR" "EDITOR = " "show null environment variable"

# Verify that GDB responds gracefully to an attempt to show a
# non-existent environment variable.  (We hope this variable is
# undefined!)
gdb_test "show environment FOOBARBAZGRUNGESPAZBALL" \
    "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined\." \
    "show non-existent environment variable"

# Verify that GDB can set an environment variable hitherto undefined.
test_set_show_env_var "FOOBARBAZGRUNGESPAZBALL" "t" \
    "set environment variable previously undefined"

# Verify that GDB can also set an environment variable using the "="
# syntax.
test_set_show_env_var_equal "FOOBARBAZGRUNGESPAZBALL" "y" \
    "set environment variable using = syntax"

# Verify that GDB can set an environment variable to a value that has
# an embedded (trailing, in this case) equals.
test_set_show_env_var_equal "FOOBARBAZGRUNGESPAZBALL" "t=" \
    "set environment variable with trailing equals"

# Verify that GDB can set an environment variable to a value preceded
# by whitespace, and that such whitespace is ignored (not included
# in the set value).
gdb_test_no_output "set environment FOOBARBAZGRUNGESPAZBALL =        foo" \
    "set environment variable with trailing whitespace"
gdb_test "show environment FOOBARBAZGRUNGESPAZBALL" \
    "FOOBARBAZGRUNGESPAZBALL = foo" \
    "confirm set environment variable with trailing whitespace"

# Verify that GDB can manipulate the distinguished PATH variable.
gdb_test "path /tmp/FOOBARBAZGRUNGESPAZBALL" \
    "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*" \
    "set path works properly"
gdb_test "show paths" \
    "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*" \
    "show paths works properly"

gdb_exit
return 0