[Bast-commits] r3536 - in trunk/Devel-BeginLift: . t
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Wed Jun 27 04:07:50 GMT 2007
Author: matthewt
Date: 2007-06-27 04:07:49 +0100 (Wed, 27 Jun 2007)
New Revision: 3536
Added:
trunk/Devel-BeginLift/t/
trunk/Devel-BeginLift/t/constcalc.t
trunk/Devel-BeginLift/t/proto.t
Log:
tests!
Added: trunk/Devel-BeginLift/t/constcalc.t
===================================================================
--- trunk/Devel-BeginLift/t/constcalc.t (rev 0)
+++ trunk/Devel-BeginLift/t/constcalc.t 2007-06-27 03:07:49 UTC (rev 3536)
@@ -0,0 +1,33 @@
+BEGIN { our @warnings; $SIG{__WARN__} = sub { push(@warnings, $_[0]); } }
+
+use Devel::BeginLift 'foo';
+
+use vars qw($int);
+
+BEGIN { $int = 1 }
+
+sub foo { warn "foo: $_[0]\n"; $int++; 4; }
+
+sub bar { warn "bar: $_[0]\n"; $int; }
+
+warn "yep\n";
+
+warn foo("foo")."\n";
+
+warn bar("bar")."\n";
+
+no Devel::BeginLift;
+
+foo();
+
+END {
+ use Test::More 'no_plan';
+ our @warnings;
+ is(shift(@warnings), "foo: foo\n", "compile-time foo call first");
+ is(shift(@warnings), "yep\n", "manual warning");
+ is(shift(@warnings), "4\n", "const return from compile-time foo");
+ is(shift(@warnings), "bar: bar\n", "bar called at run-time");
+ is(shift(@warnings), "2\n", "\$int was incremented");
+ is(shift(@warnings), "foo: \n", "run-time foo after BeginLift disabled");
+ ok(!@warnings, "no more warnings");
+}
Added: trunk/Devel-BeginLift/t/proto.t
===================================================================
--- trunk/Devel-BeginLift/t/proto.t (rev 0)
+++ trunk/Devel-BeginLift/t/proto.t 2007-06-27 03:07:49 UTC (rev 3536)
@@ -0,0 +1,34 @@
+BEGIN { our @warnings; $SIG{__WARN__} = sub { push(@warnings, $_[0]); } }
+
+use strict;
+use warnings;
+
+sub foo (&) {
+ $_[0]->();
+ ();
+}
+
+sub bar {
+ my ($name, $val) = @_;
+ no strict 'refs';
+ *{$name} = sub (&) { $_[0]->($val); };
+}
+
+use Devel::BeginLift 'foo';
+
+foo {
+ bar "boom1" => "BOOM 1";
+ bar "boom2" => "BOOM 2";
+};
+
+boom1 { warn "1: $_[0]\n"; };
+
+boom2 { warn "2: $_[0]\n"; };
+
+END {
+ use Test::More 'no_plan';
+ our @warnings;
+ is(shift(@warnings), "1: BOOM 1\n", 'boom1');
+ is(shift(@warnings), "2: BOOM 2\n", 'boom2');
+ ok(!@warnings, 'No more warnings');
+}
More information about the Bast-commits
mailing list