From: Vincent Pit Date: Mon, 27 Dec 2010 22:49:16 +0000 (+0100) Subject: Test BAIL_OUT() X-Git-Tag: v0.01~13 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=9497e7098591c7bbc659406d4ffae555a7b8acc8;p=perl%2Fmodules%2FTest-Leaner.git Test BAIL_OUT() --- diff --git a/MANIFEST b/MANIFEST index c89c5a8..1d2acad 100644 --- a/MANIFEST +++ b/MANIFEST @@ -7,6 +7,7 @@ t/00-load.t t/01-import.t t/05-pass.t t/06-fail.t +t/07-BAIL_OUT.t t/10-plan-tests.t t/11-plan-no_plan.t t/12-plan-skip_all.t diff --git a/t/07-BAIL_OUT.t b/t/07-BAIL_OUT.t new file mode 100644 index 0000000..cde9694 --- /dev/null +++ b/t/07-BAIL_OUT.t @@ -0,0 +1,53 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More; + +plan skip_all => 'perl 5.8 required to test BAIL_OUT()' unless $] >= 5.008; + +my $buf = ''; +open my $memory_stream, '>', \$buf + or plan skip_all => 'could not create the in-memory file'; + +plan tests => 7; + +our $status; +*CORE::GLOBAL::exit = *CORE::GLOBAL::exit = sub { + my $caller = caller; + if ($caller eq 'Test::Leaner') { + $status = $_[0] || 0; + } else { + CORE::exit $_[0]; + } +}; + +require Test::Leaner; + +{ + local $@; + eval { Test::Leaner::tap_stream($memory_stream) }; + is $@, '', 'tap_stream($fh) does not croak'; +} + +{ + 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'; +} + +{ + 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'; +}