summaryrefslogtreecommitdiff
path: root/lib/constant.t
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2005-12-24 16:06:10 +0000
committerNicholas Clark <nick@ccl4.org>2005-12-24 16:06:10 +0000
commit69e7dc3c564b0153c599a70d21ee3044fc270d54 (patch)
tree1b33089a4c3f7f9460a0bf67eaf20f810bc53484 /lib/constant.t
parentb35226bb9fb75776ec63888a35027b665a5af9dc (diff)
downloadperl-69e7dc3c564b0153c599a70d21ee3044fc270d54.tar.gz
Tests for creating constants where prototypes or other symbols of the
same name already exist. p4raw-id: //depot/perl@26484
Diffstat (limited to 'lib/constant.t')
-rw-r--r--lib/constant.t74
1 files changed, 72 insertions, 2 deletions
diff --git a/lib/constant.t b/lib/constant.t
index 1f1d0be3d9..f714d23bcc 100644
--- a/lib/constant.t
+++ b/lib/constant.t
@@ -6,7 +6,7 @@ BEGIN {
}
use warnings;
-use vars qw{ @warnings };
+use vars qw{ @warnings $fagwoosh $putt $kloong};
BEGIN { # ...and save 'em for later
$SIG{'__WARN__'} = sub { push @warnings, @_ }
}
@@ -14,7 +14,7 @@ END { print STDERR @warnings }
use strict;
-use Test::More tests => 75;
+use Test::More tests => 95;
my $TB = Test::More->builder;
BEGIN { use_ok('constant'); }
@@ -242,3 +242,73 @@ is THREE**3, SPIT->(@{+FAMILY}**3);
};
ok( $@ eq '' );
}
+
+sub slotch ();
+
+{
+ my @warnings;
+ local $SIG{'__WARN__'} = sub { push @warnings, @_ };
+ eval 'use constant slotch => 3; 1' or die $@;
+
+ is ("@warnings", "", "No warnings if a prototype exists");
+
+ my $value = eval 'slotch';
+ is ($@, '');
+ is ($value, 3);
+}
+
+sub zit;
+
+{
+ my @warnings;
+ local $SIG{'__WARN__'} = sub { push @warnings, @_ };
+ eval 'use constant zit => 4; 1' or die $@;
+
+ is(scalar @warnings, 1, "1 warning");
+ like ($warnings[0], qr/^Prototype mismatch: sub main::zit: none vs \(\)/,
+ "about the prototype mismatch");
+
+ my $value = eval 'zit';
+ is ($@, '');
+ is ($value, 4);
+}
+
+$fagwoosh = 'geronimo';
+$putt = 'leutwein';
+$kloong = 'schlozhauer';
+
+{
+ my @warnings;
+ local $SIG{'__WARN__'} = sub { push @warnings, @_ };
+ eval 'use constant fagwoosh => 5; 1' or die $@;
+
+ is ("@warnings", "", "No warnings if the typeglob exists already");
+
+ my $value = eval 'fagwoosh';
+ is ($@, '');
+ is ($value, 5);
+
+ my @value = eval 'fagwoosh';
+ is ($@, '');
+ is_deeply (\@value, [5]);
+
+ eval 'use constant putt => 6, 7; 1' or die $@;
+
+ is ("@warnings", "", "No warnings if the typeglob exists already");
+
+ @value = eval 'putt';
+ is ($@, '');
+ is_deeply (\@value, [6, 7]);
+
+ eval 'use constant "klong"; 1' or die $@;
+
+ is ("@warnings", "", "No warnings if the typeglob exists already");
+
+ $value = eval 'klong';
+ is ($@, '');
+ is ($value, undef);
+
+ @value = eval 'klong';
+ is ($@, '');
+ is_deeply (\@value, []);
+}