[libmoosex-lazyrequire-perl] 02/06: Add basic tests.

Intrigeri intrigeri at moszumanska.debian.org
Wed Aug 27 21:25:15 UTC 2014


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to annotated tag 0.01
in repository libmoosex-lazyrequire-perl.

commit f96258fce6319ec12d5ffc626226191524a82e38
Author: Florian Ragwitz <rafl at debian.org>
Date:   Thu Aug 13 01:56:55 2009 +0200

    Add basic tests.
---
 t/basic.t | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/t/basic.t b/t/basic.t
new file mode 100644
index 0000000..a29ca5d
--- /dev/null
+++ b/t/basic.t
@@ -0,0 +1,80 @@
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+{
+    package Foo;
+    use Moose;
+    use MooseX::LazyRequire;
+
+    has bar => (
+        is           => 'ro',
+        lazy_require => 1,
+    );
+
+    has baz => (
+        is      => 'ro',
+        builder => '_build_baz',
+    );
+
+    sub _build_baz { shift->bar + 1 }
+}
+
+{
+    my $foo;
+    lives_ok(sub {
+        $foo = Foo->new(bar => 42);
+    });
+    is($foo->baz, 43);
+}
+
+{
+    my $foo;
+    lives_ok(sub {
+        $foo = Foo->new(baz => 23);
+    });
+    is($foo->baz, 23);
+}
+
+throws_ok(sub {
+    Foo->new;
+}, qr/must be provided/);
+
+{
+    package Bar;
+    use Moose;
+    use MooseX::LazyRequire;
+
+    has foo => (
+        is           => 'rw',
+        lazy_require => 1,
+    );
+
+    has baz => (
+        is      => 'ro',
+        lazy    => 1,
+        builder => '_build_baz',
+    );
+
+    sub _build_baz { shift->foo + 1 }
+}
+
+{
+    my $bar = Bar->new;
+
+    throws_ok(sub {
+        $bar->baz;
+    }, qr/must be provided/);
+
+    $bar->foo(42);
+
+    my $baz;
+    lives_ok(sub {
+        $baz = $bar->baz;
+    });
+
+    is($baz, 43);
+}
+
+done_testing;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmoosex-lazyrequire-perl.git



More information about the Pkg-perl-cvs-commits mailing list