X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FTest-Leaner.git;a=blobdiff_plain;f=t%2F07-BAIL_OUT.t;h=8fd396458c3d5b059cdb58862ef53ef598fdcc8c;hp=cde9694099197f5abc2584fc5ab47e44a3485be2;hb=653bd706f7c17c61e34d98e6fcaed75861b2f7d7;hpb=9497e7098591c7bbc659406d4ffae555a7b8acc8 diff --git a/t/07-BAIL_OUT.t b/t/07-BAIL_OUT.t index cde9694..8fd3964 100644 --- a/t/07-BAIL_OUT.t +++ b/t/07-BAIL_OUT.t @@ -5,49 +5,45 @@ use warnings; use Test::More; -plan skip_all => 'perl 5.8 required to test BAIL_OUT()' unless $] >= 5.008; +our $status; +BEGIN { + *CORE::GLOBAL::exit = *CORE::GLOBAL::exit = sub { + my $caller = caller; + if ($caller eq 'Test::Leaner') { + $status = $_[0] || 0; + } else { + CORE::exit $_[0]; + } + }; + + delete $ENV{PERL_TEST_LEANER_USES_TEST_MORE}; +} -my $buf = ''; -open my $memory_stream, '>', \$buf - or plan skip_all => 'could not create the in-memory file'; +use Test::Leaner (); -plan tests => 7; +use lib 't/lib'; +use Test::Leaner::TestHelper; -our $status; -*CORE::GLOBAL::exit = *CORE::GLOBAL::exit = sub { - my $caller = caller; - if ($caller eq 'Test::Leaner') { - $status = $_[0] || 0; - } else { - CORE::exit $_[0]; - } -}; +my $buf = ''; +capture_to_buffer $buf + or plan skip_all => 'perl 5.8 required to test BAIL_OUT()'; -require Test::Leaner; -{ - local $@; - eval { Test::Leaner::tap_stream($memory_stream) }; - is $@, '', 'tap_stream($fh) does not croak'; -} +plan tests => 6; -{ +reset_buffer { local ($@, $status); - $buf = ''; - seek $memory_stream, 0, 0; eval { Test::Leaner::BAIL_OUT() }; is $@, '', 'BAIL_OUT() does not croak'; is $buf, "Bail out!\n", 'BAIL_OUT() produces the correct TAP code'; is $status, 255, 'BAIL_OUT() exits with the correct status'; -} +}; -{ +reset_buffer { local ($@, $status); - $buf = ''; - seek $memory_stream, 0, 0; eval { Test::Leaner::BAIL_OUT('this is a comment') }; is $@, '', 'BAIL_OUT("comment") does not croak'; is $buf, "Bail out! this is a comment\n", 'BAIL_OUT("comment") produces the correct TAP code'; is $status, 255, 'BAIL_OUT("comment") exits with the correct status'; -} +};