From: Florian Ragwitz Date: Tue, 30 Jun 2009 05:10:50 +0000 (+0200) Subject: Add testcase for clobbering globs when trying to restore them. X-Git-Tag: 0.12~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6444f23aeb3cb76d2da354c91b65e7d77fd7c13d;p=p5sagit%2Fnamespace-clean.git Add testcase for clobbering globs when trying to restore them. Courtesy of Ben Morrows. --- diff --git a/t/06-other-types.t b/t/06-other-types.t new file mode 100644 index 0000000..f6254ec --- /dev/null +++ b/t/06-other-types.t @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +use warnings; +use strict; + +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 17; + +our $pvio; + +use_ok('OtherTypes'); + +# Since we use use_ok, this is effectively 'compile time'. + +ok( defined *OtherTypes::foo{SCALAR}, + "SCALAR slot intact at compile time" ); +ok( defined *OtherTypes::foo{ARRAY}, + "ARRAY slot intact at compile time" ); +ok( defined *OtherTypes::foo{HASH}, + "HASH slot intact at compile time" ); +ok( defined *OtherTypes::foo{IO}, + "IO slot intact at compile time" ); + +is( $OtherTypes::foo, 23, + "SCALAR slot correct at compile time" ); +is( $OtherTypes::foo[0], "bar", + "ARRAY slot correct at compile time" ); +is( $OtherTypes::foo{mouse}, "trap", + "HASH slot correct at compile time" ); +is( *OtherTypes::foo{IO}, $pvio, + "IO slot correct at compile time" ); + +eval q{ + ok( defined *OtherTypes::foo{SCALAR}, + "SCALAR slot intact at run time" ); + ok( defined *OtherTypes::foo{ARRAY}, + "ARRAY slot intact at run time" ); + ok( defined *OtherTypes::foo{HASH}, + "HASH slot intact at run time" ); + ok( defined *OtherTypes::foo{IO}, + "IO slot intact at run time" ); + + is( $OtherTypes::foo, 23, + "SCALAR slot correct at run time" ); + is( $OtherTypes::foo[0], "bar", + "ARRAY slot correct at run time" ); + is( $OtherTypes::foo{mouse}, "trap", + "HASH slot correct at run time" ); + is( *OtherTypes::foo{IO}, $pvio, + "IO slot correct at run time" ); +}; diff --git a/t/lib/OtherTypes.pm b/t/lib/OtherTypes.pm new file mode 100644 index 0000000..66b8873 --- /dev/null +++ b/t/lib/OtherTypes.pm @@ -0,0 +1,20 @@ +package OtherTypes; + +our $foo = 23; +our @foo = "bar"; +our %foo = (mouse => "trap"); +{ + no warnings; + # perl warns about the bareword foo. If we use *foo instead the + # warning goes away, but the *foo{IO} slot doesn't get autoviv'd at + # compile time. + open foo, "<", $0; +} + +BEGIN { $main::pvio = *foo{IO} } + +sub foo { 1 } + +use namespace::clean; + +1;