X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F030_roles%2F019_build.t;h=1dfc9124a0abdd6cf4dc4c25c796aafe449bb8cb;hb=06d16be025b59d5bb71c237c6ab27c6053c2b615;hp=fe3873625f81722e9aba0646992d0f206d4c0ff4;hpb=39443466d42bdfefb2a1da1b622c51176d35d5a8;p=gitmo%2FMoose.git diff --git a/t/030_roles/019_build.t b/t/030_roles/019_build.t index fe38736..1dfc912 100644 --- a/t/030_roles/019_build.t +++ b/t/030_roles/019_build.t @@ -1,17 +1,17 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 7; +use Test::More; +BEGIN { + eval "use Test::Output;"; + plan skip_all => "Test::Output is required for this test" if $@; +} # this test script ensures that my idiom of: # role: sub BUILD, after BUILD # continues to work to run code after object initialization, whether the class # has a BUILD method or not -BEGIN { - use_ok('Moose::Role'); -} - my @CALLS; do { @@ -26,53 +26,55 @@ do { do { package ClassWithBUILD; use Moose; - with 'TestRole'; + + ::stderr_is { + with 'TestRole'; + } ''; sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' } }; do { - package ClassWithoutBUILD; + package ExplicitClassWithBUILD; use Moose; - with 'TestRole'; -}; -is_deeply([splice @CALLS], [], "no calls to BUILD yet"); + ::stderr_is { + with 'TestRole' => { excludes => 'BUILD' }; + } ''; -ClassWithBUILD->new; - -is_deeply([splice @CALLS], [ - 'TestRole::BUILD:before', - 'ClassWithBUILD::BUILD', - 'TestRole::BUILD:after', -]); - -ClassWithoutBUILD->new; + sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' } +}; -is_deeply([splice @CALLS], [ - 'TestRole::BUILD:before', - 'TestRole::BUILD', - 'TestRole::BUILD:after', -]); +do { + package ClassWithoutBUILD; + use Moose; + with 'TestRole'; +}; -ClassWithBUILD->meta->make_immutable; -ClassWithoutBUILD->meta->make_immutable; +{ + is_deeply([splice @CALLS], [], "no calls to BUILD yet"); -is_deeply([splice @CALLS], [], "no calls to BUILD yet"); + ClassWithBUILD->new; -ClassWithBUILD->new; + is_deeply([splice @CALLS], [ + 'TestRole::BUILD:before', + 'ClassWithBUILD::BUILD', + 'TestRole::BUILD:after', + ]); -is_deeply([splice @CALLS], [ - 'TestRole::BUILD:before', - 'ClassWithBUILD::BUILD', - 'TestRole::BUILD:after', -]); + ClassWithoutBUILD->new; -ClassWithoutBUILD->new; + is_deeply([splice @CALLS], [ + 'TestRole::BUILD:before', + 'TestRole::BUILD', + 'TestRole::BUILD:after', + ]); -is_deeply([splice @CALLS], [ - 'TestRole::BUILD:before', - 'TestRole::BUILD', - 'TestRole::BUILD:after', -]); + if (ClassWithBUILD->meta->is_mutable) { + ClassWithBUILD->meta->make_immutable; + ClassWithoutBUILD->meta->make_immutable; + redo; + } +} +done_testing;