diff options
Diffstat (limited to 'ext/List-Util/t/readonly.t')
-rw-r--r-- | ext/List-Util/t/readonly.t | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/ext/List-Util/t/readonly.t b/ext/List-Util/t/readonly.t new file mode 100644 index 0000000000..42ed3d811c --- /dev/null +++ b/ext/List-Util/t/readonly.t @@ -0,0 +1,51 @@ +#!./perl + +BEGIN { + unless (-d 'blib') { + chdir 't' if -d 't'; + @INC = '../lib'; + require Config; import Config; + keys %Config; # Silence warning + if ($Config{extensions} !~ /\bList\/Util\b/) { + print "1..0 # Skip: List::Util was not built\n"; + exit 0; + } + } +} + +use Scalar::Util qw(readonly); +use Test::More tests => 11; + +ok( readonly(1), 'number constant'); + +my $var = 2; + +ok( !readonly($var), 'number variable'); +is( $var, 2, 'no change to number variable'); + +ok( readonly("fred"), 'string constant'); + +$var = "fred"; + +ok( !readonly($var), 'string variable'); +is( $var, 'fred', 'no change to string variable'); + +$var = \2; + +ok( !readonly($var), 'reference to constant'); +ok( readonly($$var), 'de-reference to constant'); + +ok( !readonly(*STDOUT), 'glob'); + +sub try +{ + my $v = \$_[0]; + return readonly $$v; +} + +$var = 123; +{ + local $TODO = $Config::Config{useithreads} ? "doesn't work with threads" : undef; + ok( try ("abc"), 'reference a constant in a sub'); +} +ok( !try ($var), 'reference a non-constant in a sub'); |