This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add standard core test headers to the Class::ISA new tests
[perl5.git] / lib / Symbol.t
index 03449a3..c8a7c07 100755 (executable)
@@ -5,48 +5,73 @@ BEGIN {
     @INC = '../lib';
 }
 
-print "1..8\n";
+use Test::More tests => 19;
 
 BEGIN { $_ = 'foo'; }  # because Symbol used to clobber $_
 
 use Symbol;
 
-# First check $_ clobbering
-print "not " if $_ ne 'foo';
-print "ok 1\n";
+ok( $_ eq 'foo', 'check $_ clobbering' );
 
 
 # First test gensym()
 $sym1 = gensym;
-print "not " if ref($sym1) ne 'GLOB';
-print "ok 2\n";
+ok( ref($sym1) eq 'GLOB', 'gensym() returns a GLOB' );
 
 $sym2 = gensym;
 
-print "not " if $sym1 eq $sym2;
-print "ok 3\n";
+ok( $sym1 ne $sym2, 'gensym() returns a different GLOB' );
 
 ungensym $sym1;
 
 $sym1 = $sym2 = undef;
 
+# Test geniosym()
 
-# Test qualify()
-package foo;
+use Symbol qw(geniosym);
 
-use Symbol qw(qualify);  # must import into this package too
+$sym1 = geniosym;
+like( $sym1, qr/=IO\(/, 'got an IO ref' );
 
-qualify("x") eq "foo::x"          or print "not ";
-print "ok 4\n";
+$FOO = 'Eymascalar';
+*FOO = $sym1;
 
-qualify("x", "FOO") eq "FOO::x"   or print "not ";
-print "ok 5\n";
+is( $sym1, *FOO{IO}, 'assigns into glob OK' );
 
-qualify("BAR::x") eq "BAR::x"     or print "not ";
-print "ok 6\n";
+is( $FOO, 'Eymascalar', 'leaves scalar alone' );
+
+{
+    local $^W=1;               # 5.005 compat.
+    my $warn;
+    local $SIG{__WARN__} = sub { $warn .= "@_" };
+    readline FOO;
+    like( $warn, qr/unopened filehandle/, 'warns like an unopened filehandle' );
+}
 
-qualify("STDOUT") eq "main::STDOUT" or print "not ";
-print "ok 7\n";
+# Test qualify()
+package foo;
+
+use Symbol qw(qualify);  # must import into this package too
 
-qualify("ARGV", "FOO") eq "main::ARGV" or print "not ";
-print "ok 8\n";
+::ok( qualify("x") eq "foo::x",                'qualify() with a simple identifier' );
+::ok( qualify("x", "FOO") eq "FOO::x", 'qualify() with a package' );
+::ok( qualify("BAR::x") eq "BAR::x",
+    'qualify() with a qualified identifier' );
+::ok( qualify("STDOUT") eq "main::STDOUT",
+    'qualify() with a reserved identifier' );
+::ok( qualify("ARGV", "FOO") eq "main::ARGV",
+    'qualify() with a reserved identifier and a package' );
+::ok( qualify("_foo") eq "foo::_foo",
+    'qualify() with an identifier starting with a _' );
+::ok( qualify("^FOO") eq "main::\cFOO",
+    'qualify() with an identifier starting with a ^' );
+
+# tests for delete_package
+package main;
+$Transient::variable = 42;
+ok( exists $::{'Transient::'}, 'transient stash exists' );
+ok( defined $Transient::{variable}, 'transient variable in stash' );
+Symbol::delete_package('Transient');
+ok( !exists $Transient::{variable}, 'transient variable no longer in stash' );
+is( scalar(keys %Transient::), 0, 'transient stash is empty' );
+ok( !exists $::{'Transient::'}, 'no transient stash' );