From: Matt S Trout Date: Wed, 27 Jun 2007 03:07:49 +0000 (+0000) Subject: tests! X-Git-Tag: 0.001000~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=00aef8ff1e6cabf4627e20eeb29f68a75c799f47;p=p5sagit%2FDevel-BeginLift.git tests! --- diff --git a/t/constcalc.t b/t/constcalc.t new file mode 100644 index 0000000..755d238 --- /dev/null +++ b/t/constcalc.t @@ -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"); +} diff --git a/t/proto.t b/t/proto.t new file mode 100644 index 0000000..11739fb --- /dev/null +++ b/t/proto.t @@ -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'); +}