From: Robert Sedlacek Date: Mon, 28 Nov 2011 17:45:43 +0000 (+0100) Subject: added new, bare simple test X-Git-Tag: v1.000000~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FPackage-Variant.git;a=commitdiff_plain;h=f9c096bb0bb7309f1be31d001f7eba966bb273de added new, bare simple test --- diff --git a/t/01simple.t b/t/01simple.t new file mode 100644 index 0000000..535d499 --- /dev/null +++ b/t/01simple.t @@ -0,0 +1,56 @@ +use strictures 1; +use Test::More; +use Test::Fatal; +use Package::Variant (); + +my @DECLARED; + +BEGIN { + package TestSugar; + use Exporter; + our @EXPORT_OK = qw( declare ); + sub declare { push @DECLARED, [@_] } + $INC{'TestSugar.pm'} = __FILE__; +} + +BEGIN { + package TestVariable; + use Package::Variant + importing => { 'TestSugar' => [qw( declare )] }, + subs => [qw( declare )]; + sub make_variant { + my ($class, $target, @args) = @_; + ::ok(__PACKAGE__->can('install'), 'install() is available') + or ::BAIL_OUT('install() subroutine was not exported!'); + ::ok(__PACKAGE__->can('declare'), 'declare() import is available') + or ::BAIL_OUT('proxy declare() subroutine was not exported!'); + declare target => $target; + declare args => [@args]; + declare class => $class->_test_class_method; + install target => sub { $target }; + install args => sub { [@args] }; + } + sub _test_class_method { + return shift; + } + $INC{'TestVariable.pm'} = __FILE__; +} + +use TestVariable; + +my $variant = TestVariable(3..7); + +ok defined($variant), 'new variant is a defined value'; +ok length($variant), 'new variant has length'; +is $variant->target, $variant, 'target was new variant'; +is_deeply $variant->args, [3..7], 'correct arguments received'; + +is_deeply shift(@DECLARED), [target => $variant], + 'target passed via proxy'; +is_deeply shift(@DECLARED), [args => [3..7]], + 'arguments passed via proxy'; +is_deeply shift(@DECLARED), [class => $variant], + 'class method resolution'; +is scalar(@DECLARED), 0, 'proxy sub called right amount of times'; + +done_testing;