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.
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.
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/>.
14 # test behavior of readonly namerefs and namerefs referencing readonly variables
16 # readonly nameref variable referencing read-write global variable
20 unset foo0 # unsets bar
22 unset -n foo0 # cannot unset
25 declare +r foo0 # modifies bar
27 declare +r -n foo0 # error
28 declare +n foo0 # error
31 # readonly nameref variable without a value
37 typeset foo1=bar # error
38 typeset +r foo1 # no-op, follows nameref chain to nothing
41 # nameref pointing to read-only global variable
44 typeset -r foo2 # changes bar
49 typeset +r foo2 # attempts to change bar, error
50 typeset -p foo2 bar # nameref unchanged
52 # read-only nameref pointing to read-only global variable
55 unset foo3 # unsets bar3
59 unset -n foo3 # cannot unset
62 declare +r foo3 # error attempting to reference bar3
64 declare +r -n foo3 # error
66 # readonly nameref pointing to read-write local -- can we remove nameref attr?
72 typeset -n -r foo4=bar4
83 # readonly nameref pointing to read-write global -- can we remove nameref attr?
100 # readonly local nameref without a value -- can we remove nameref attribute?
111 # readonly global nameref without a value -- can we remove nameref attribute?