develooper Front page | perl.perl5.porters | Postings from February 2008

Re: [PATCH] Read-only variable tests

Thread Previous
From:
Rafael Garcia-Suarez
Date:
February 13, 2008 02:15
Subject:
Re: [PATCH] Read-only variable tests
Message ID:
b77c1dce0802130214x40e538f8qc0a5295790d4fecb@mail.gmail.com
On 08/02/2008, Jerry D. Hedden <jdhedden@cpan.org> wrote:
> I discovered that there was no comprehensive testing of
> read-only variables.  Attached is a patch to add lots more
> tests to lib/Internals.t.
>
> There are some issues associated with all this:
>
> Read-only scalar:
>     undef               Fails = okay
>     modify              Fails = okay
>
> Read-only array:
>     undef               Fails = okay
>     reassign            Fails = okay
>     shift               Fails = okay
>     push                Fails = okay
>     delete elem         Fails = okay
>     modify elem         Works = marked as TODO
>
> Read-only array element:
>     modify              Fails = okay
>     undef               Fails = okay
>     delete              Works = marked as TODO
>
>     The read-only status on an array element is not fixed to
>     the array position, but to the element.  When the array
>     is shifted or unshifed, the read-only element moves:
>
>         Internals::SvREADONLY($foo[2], 1);
>         shift(@foo);    # $foo[1] is now read-only
>
>     Is this the correct behavior, or should the read-only
>     status be associated with the array position?

That would sound correct to me...

> Read-only hash:
>     undef               Fails = okay
>     reassign            Raises exception, but hash is cleared
>                             = marked as TODO
>     add key             Fails = okay
>     modify key's value  Works because it's designed that way
>                           for Hash::Util = okay
>     delete key          Works because it's designed that way
>                           for Hash::Util = okay
>     add back deleted keys
>                         Works because it's designed that way
>                           for Hash::Util = okay
>
> Read-only hash value:
>     modify              Fails = okay
>     undef               Fails = okay
>     delete              Works because it's designed that way
>                           for Hash::Util = okay
>
> The three TODOs are the result of the implementation of
> restricted hashes for Hash::Util, and since
> Internals::SvREADONLY is not explicitly documented, I
> suppose they don't require any 'fixes'.

I don't agree with the 1st TODO:

TODO: {
    local $TODO = 'Due to restricted hashes implementation';
    eval { $foo[2] = 'qux'; };
    like($@, $ro_err, q/Can't modify element in read-only array/);
}

The readonlyness is on the container, not on the element.

All other tests are in as change #33297, thanks.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About