BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
+ require './test.pl';
}
-print "1..9\n";
-
sub t1;
sub t2 : lvalue;
sub t3 ();
@ISA = 'P1';
}
-print "not " unless exists &t1 && not defined &t1;
-print "ok 1\n";
-print "not " unless exists &t2 && not defined &t2;
-print "ok 2\n";
-print "not " unless exists &t3 && not defined &t3;
-print "ok 3\n";
-print "not " unless exists &t4 && not defined &t4;
-print "ok 4\n";
-print "not " unless exists &t5 && defined &t5;
-print "ok 5\n";
-P2::->tmc;
-print "not " unless not exists &P2::tmc && not defined &P2::tmc;
-print "ok 6\n";
+my $has_t1 = ok( exists &t1, 't1 sub declared' );
+SKIP: {
+ skip 't1 sub was not declared', 1 if ! $has_t1;
+ ok( ! defined &t1, 't1 not defined' );
+}
+
+my $has_t2 = ok( exists &t2, 't2 sub declared' );
+SKIP: {
+ skip 't2 sub was not declared', 1 if ! $has_t2;
+ ok( ! defined &t2, 't2 not defined' );
+}
+
+my $has_t3 = ok( exists &t3, 't3 sub declared' );
+SKIP: {
+ skip 't3 sub was not declared', 1 if ! $has_t3;
+ ok( ! defined &t3, 't3 not defined' );
+}
+
+my $has_t4 = ok( exists &t4, 't4 sub declared' );
+SKIP: {
+ skip 't4 sub was not declared', 1 if ! $has_t4;
+ ok( ! defined &t4, 't4 not defined' );
+}
+
+my $has_t5 = ok( exists &t5, 't5 sub declared' );
+SKIP: {
+ skip 't5 sub was not declared', 1 if ! $has_t5;
+ ok( defined &t5, , 't5 defined' );
+}
+
+my $has_p2_tmc = ok(! exists &P2::tmc, 'P2::tmc not declared, it was inherited');
+SKIP: {
+ skip 'P2::tmc sub was not declared', 1 if ! $has_t5;
+ ok( ! defined &P2::tmc, 'P2::tmc not defined' );
+}
+
my $ref;
$ref->{A}[0] = \&t4;
-print "not " unless exists &{$ref->{A}[0]} && not defined &{$ref->{A}[0]};
-print "ok 7\n";
+my $ref_exists = ok( exists &{$ref->{A}[0]}, 'references to subroutines exist');
+SKIP: {
+ skip 1, 'Reference sub is not considered declared', 1 if ! $ref_exists;
+ ok( ! defined &{$ref->{A}[0]}, 'Reference to a sub is not defined' );
+}
+
+my $p1_tmc_exists = ok( exists &P1::tmc, 'test setup check');
+SKIP: {
+ skip 'Setup P1::tmc sub is not considered declared', 1 if ! $p1_tmc_exists;
+ ok( defined P1::tmc, 'Setup sub is defined' );
+}
+
undef &P1::tmc;
-print "not " unless exists &P1::tmc && not defined &P1::tmc;
-print "ok 8\n";
+$p1_tmc_exists = ok( exists &P1::tmc, 'P1::tmc was once defined, and continues to be after being undeffed');
+SKIP: {
+ skip( 'Sub P1::tmc still exists after having undef called on it', 1) if ! $p1_tmc_exists;
+ ok( ! defined &P1::tmc, 'P1::tmc is not longer defined after undef was called on it' );
+}
+
eval 'exists &t5()';
-print "not " unless $@;
-print "ok 9\n";
+like( $@, qr/not a subroutine name/, 'exists takes subroutine names with no argument list');
+
+done_testing();
exit 0;