]>
Commit | Line | Data |
---|---|---|
8868edaf CR |
1 | # This program is free software: you can redistribute it and/or modify |
2 | # it under the terms of the GNU General Public License as published by | |
3 | # the Free Software Foundation, either version 3 of the License, or | |
4 | # (at your option) any later version. | |
5 | # | |
6 | # This program is distributed in the hope that it will be useful, | |
7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 | # GNU General Public License for more details. | |
10 | # | |
11 | # You should have received a copy of the GNU General Public License | |
12 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 | # | |
a0c0a00f CR |
14 | # test behavior of readonly namerefs and namerefs referencing readonly variables |
15 | ||
16 | # readonly nameref variable referencing read-write global variable | |
17 | ||
18 | bar=one | |
19 | declare -rn foo0=bar | |
20 | unset foo0 # unsets bar | |
21 | declare -p bar | |
22 | unset -n foo0 # cannot unset | |
23 | declare -p foo0 | |
24 | ||
25 | declare +r foo0 # modifies bar | |
26 | declare -p foo0 bar | |
27 | declare +r -n foo0 # error | |
28 | declare +n foo0 # error | |
29 | unset bar | |
30 | ||
31 | # readonly nameref variable without a value | |
32 | typeset -n foo1 | |
33 | typeset -r foo1 | |
34 | ||
35 | typeset -p foo1 | |
36 | ||
37 | typeset foo1=bar # error | |
38 | typeset +r foo1 # no-op, follows nameref chain to nothing | |
39 | typeset -p foo1 | |
40 | ||
41 | # nameref pointing to read-only global variable | |
42 | foo2=bar | |
43 | typeset -n foo2 | |
44 | typeset -r foo2 # changes bar | |
45 | ||
46 | typeset -p foo2 bar | |
47 | ||
48 | foo2=bar # error? | |
49 | typeset +r foo2 # attempts to change bar, error | |
50 | typeset -p foo2 bar # nameref unchanged | |
51 | ||
52 | # read-only nameref pointing to read-only global variable | |
53 | bar3=three | |
54 | declare -rn foo3=bar3 | |
55 | unset foo3 # unsets bar3 | |
56 | ||
57 | bar3=three | |
58 | declare -p bar3 | |
59 | unset -n foo3 # cannot unset | |
60 | ||
61 | readonly bar3 | |
62 | declare +r foo3 # error attempting to reference bar3 | |
63 | declare -p foo3 bar3 | |
64 | declare +r -n foo3 # error | |
65 | ||
66 | # readonly nameref pointing to read-write local -- can we remove nameref attr? | |
67 | func() | |
68 | { | |
69 | typeset bar4=four | |
70 | ||
71 | # readonly nameref | |
72 | typeset -n -r foo4=bar4 | |
73 | ||
74 | typeset -p foo4 bar4 | |
75 | ||
76 | typeset +n foo4 | |
77 | ||
78 | typeset -p foo4 | |
79 | } | |
80 | func | |
81 | unset -f func | |
82 | ||
83 | # readonly nameref pointing to read-write global -- can we remove nameref attr? | |
84 | bar4=four | |
85 | foo4=bar4 | |
86 | # readonly nameref | |
87 | typeset -n foo4 | |
88 | typeset -r -n foo4 | |
89 | ||
90 | typeset -p foo4 bar4 | |
91 | ||
92 | typeset +n foo4 | |
93 | typeset -p foo4 | |
94 | ||
95 | bar4=four | |
96 | : ${foo4=bar4} | |
97 | ||
98 | typeset -p foo4 bar4 | |
99 | ||
100 | # readonly local nameref without a value -- can we remove nameref attribute? | |
101 | func() | |
102 | { | |
103 | declare -r -n foo5 | |
104 | declare -p foo5 | |
105 | declare +n foo5 | |
106 | declare -p foo5 | |
107 | } | |
108 | func | |
109 | unset -f func | |
110 | ||
111 | # readonly global nameref without a value -- can we remove nameref attribute? | |
112 | declare -n foo5 | |
113 | declare -r -n foo5 | |
114 | declare -p foo5 | |
115 | declare +n foo5 | |
116 | declare -p foo5 |