]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - t/07-BAIL_OUT.t
Factor the capturing logic into Test::Leaner::TestHelper
[perl/modules/Test-Leaner.git] / t / 07-BAIL_OUT.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 our $status;
9 BEGIN {
10  *CORE::GLOBAL::exit = *CORE::GLOBAL::exit = sub {
11   my $caller = caller;
12   if ($caller eq 'Test::Leaner') {
13    $status = $_[0] || 0;
14   } else {
15    CORE::exit $_[0];
16   }
17  };
18 }
19
20 use Test::Leaner ();
21
22 use lib 't/lib';
23 use Test::Leaner::TestHelper;
24
25 my $buf = '';
26 capture_to_buffer $buf
27                   or plan skip_all => 'perl 5.8 required to test BAIL_OUT()';
28
29
30 plan tests => 6;
31
32 reset_buffer {
33  local ($@, $status);
34  eval { Test::Leaner::BAIL_OUT() };
35  is $@,      '',            'BAIL_OUT() does not croak';
36  is $buf,    "Bail out!\n", 'BAIL_OUT() produces the correct TAP code';
37  is $status, 255,           'BAIL_OUT() exits with the correct status';
38 };
39
40 reset_buffer {
41  local ($@, $status);
42  eval { Test::Leaner::BAIL_OUT('this is a comment') };
43  is $@,      '',  'BAIL_OUT("comment") does not croak';
44  is $buf,    "Bail out!  this is a comment\n",
45                   'BAIL_OUT("comment") produces the correct TAP code';
46  is $status, 255, 'BAIL_OUT("comment") exits with the correct status';
47 };