diff options
Diffstat (limited to 't/test_moose')
-rw-r--r-- | t/test_moose/test_moose.t | 10 | ||||
-rw-r--r-- | t/test_moose/test_moose_does_ok.t | 58 | ||||
-rw-r--r-- | t/test_moose/test_moose_has_attribute_ok.t | 45 | ||||
-rw-r--r-- | t/test_moose/test_moose_meta_ok.t | 29 | ||||
-rw-r--r-- | t/test_moose/with_immutable.t | 36 |
5 files changed, 178 insertions, 0 deletions
diff --git a/t/test_moose/test_moose.t b/t/test_moose/test_moose.t new file mode 100644 index 0000000..e277cfa --- /dev/null +++ b/t/test_moose/test_moose.t @@ -0,0 +1,10 @@ +use strict; +use warnings; + +use Test::More; + +BEGIN { + use_ok('Test::Moose'); +} + +done_testing; diff --git a/t/test_moose/test_moose_does_ok.t b/t/test_moose/test_moose_does_ok.t new file mode 100644 index 0000000..9ba5b68 --- /dev/null +++ b/t/test_moose/test_moose_does_ok.t @@ -0,0 +1,58 @@ +use strict; +use warnings; + +use Test::Builder::Tester; +use Test::More; + +use Test::Moose; + +{ + package Foo; + use Moose::Role; +} + +{ + package Bar; + use Moose; + + with qw/Foo/; +} + +{ + package Baz; + use Moose; +} + +# class ok + +test_out('ok 1 - does_ok class'); + +does_ok('Bar','Foo','does_ok class'); + +# class fail + +test_out ('not ok 2 - does_ok class fail'); +test_fail (+2); + +does_ok('Baz','Foo','does_ok class fail'); + +# object ok + +my $bar = Bar->new; + +test_out ('ok 3 - does_ok object'); + +does_ok ($bar,'Foo','does_ok object'); + +# object fail + +my $baz = Baz->new; + +test_out ('not ok 4 - does_ok object fail'); +test_fail (+2); + +does_ok ($baz,'Foo','does_ok object fail'); + +test_test ('does_ok'); + +done_testing; diff --git a/t/test_moose/test_moose_has_attribute_ok.t b/t/test_moose/test_moose_has_attribute_ok.t new file mode 100644 index 0000000..9e77dd4 --- /dev/null +++ b/t/test_moose/test_moose_has_attribute_ok.t @@ -0,0 +1,45 @@ +use strict; +use warnings; + +use Test::Builder::Tester; +use Test::More; + +use Test::Moose; + +{ + package Foo; + use Moose; + + has 'foo', is => 'bare'; +} + +{ + package Bar; + use Moose; + + extends 'Foo'; + + has 'bar', is => 'bare'; +} + + +test_out('ok 1 - ... has_attribute_ok(Foo, foo) passes'); + +has_attribute_ok('Foo', 'foo', '... has_attribute_ok(Foo, foo) passes'); + +test_out ('not ok 2 - ... has_attribute_ok(Foo, bar) fails'); +test_fail (+2); + +has_attribute_ok('Foo', 'bar', '... has_attribute_ok(Foo, bar) fails'); + +test_out('ok 3 - ... has_attribute_ok(Bar, foo) passes'); + +has_attribute_ok('Bar', 'foo', '... has_attribute_ok(Bar, foo) passes'); + +test_out('ok 4 - ... has_attribute_ok(Bar, bar) passes'); + +has_attribute_ok('Bar', 'bar', '... has_attribute_ok(Bar, bar) passes'); + +test_test ('has_attribute_ok'); + +done_testing; diff --git a/t/test_moose/test_moose_meta_ok.t b/t/test_moose/test_moose_meta_ok.t new file mode 100644 index 0000000..1556379 --- /dev/null +++ b/t/test_moose/test_moose_meta_ok.t @@ -0,0 +1,29 @@ +use strict; +use warnings; + +use Test::Builder::Tester; +use Test::More; + +use Test::Moose; + +{ + package Foo; + use Moose; +} + +{ + package Bar; +} + +test_out('ok 1 - ... meta_ok(Foo) passes'); + +meta_ok('Foo', '... meta_ok(Foo) passes'); + +test_out ('not ok 2 - ... meta_ok(Bar) fails'); +test_fail (+2); + +meta_ok('Bar', '... meta_ok(Bar) fails'); + +test_test ('meta_ok'); + +done_testing; diff --git a/t/test_moose/with_immutable.t b/t/test_moose/with_immutable.t new file mode 100644 index 0000000..6536e70 --- /dev/null +++ b/t/test_moose/with_immutable.t @@ -0,0 +1,36 @@ +use strict; +use warnings; + +use Test::Builder::Tester; +use Test::More; + +use Test::Moose; + +{ + package Foo; + use Moose; +} + +{ + package Bar; + use Moose; +} + +package main; + +test_out("ok 1", "not ok 2"); +test_fail(+2); +my $ret = with_immutable { + ok(Foo->meta->is_mutable); +} qw(Foo); +test_test('with_immutable failure'); +ok(!$ret, "one of our tests failed"); + +test_out("ok 1", "ok 2"); +$ret = with_immutable { + ok(Bar->meta->find_method_by_name('new')); +} qw(Bar); +test_test('with_immutable success'); +ok($ret, "all tests succeeded"); + +done_testing; |